static matrix4x4_t backend_viewmatrix;
static matrix4x4_t backend_modelmatrix;
static matrix4x4_t backend_modelviewmatrix;
-static matrix4x4_t backend_glmodelviewmatrix;
static matrix4x4_t backend_projectmatrix;
static unsigned int backendunits, backendimageunits, backendarrayunits, backendactive;
{
if (memcmp(matrix, &backend_modelmatrix, sizeof(matrix4x4_t)))
{
+ double glmatrix[16];
backend_modelmatrix = *matrix;
Matrix4x4_Concat(&backend_modelviewmatrix, &backend_viewmatrix, matrix);
- Matrix4x4_Transpose(&backend_glmodelviewmatrix, &backend_modelviewmatrix);
+ Matrix4x4_ToArrayDoubleGL(&backend_modelviewmatrix, glmatrix);
CHECKGLERROR
- qglLoadMatrixf(&backend_glmodelviewmatrix.m[0][0]);CHECKGLERROR
+ qglLoadMatrixd(glmatrix);CHECKGLERROR
}
}
// texmatrix specified, check if it is different
if (!unit->texmatrixenabled || memcmp(&unit->matrix, matrix, sizeof(matrix4x4_t)))
{
- matrix4x4_t tempmatrix;
+ double glmatrix[16];
unit->texmatrixenabled = true;
unit->matrix = *matrix;
CHECKGLERROR
- Matrix4x4_Transpose(&tempmatrix, &unit->matrix);
+ Matrix4x4_ToArrayDoubleGL(&unit->matrix, glmatrix);
qglMatrixMode(GL_TEXTURE);CHECKGLERROR
GL_ActiveTexture(unitnum);
- qglLoadMatrixf(&tempmatrix.m[0][0]);CHECKGLERROR
+ qglLoadMatrixd(glmatrix);CHECKGLERROR
qglMatrixMode(GL_MODELVIEW);CHECKGLERROR
}
}
out->m[3][3] = 1.0f;
}
+void Matrix4x4_ToArrayDoubleGL(const matrix4x4_t *in, double out[16])
+{
+ out[ 0] = in->m[0][0];
+ out[ 1] = in->m[1][0];
+ out[ 2] = in->m[2][0];
+ out[ 3] = in->m[3][0];
+ out[ 4] = in->m[0][1];
+ out[ 5] = in->m[1][1];
+ out[ 6] = in->m[2][1];
+ out[ 7] = in->m[3][1];
+ out[ 8] = in->m[0][2];
+ out[ 9] = in->m[1][2];
+ out[10] = in->m[2][2];
+ out[11] = in->m[3][2];
+ out[12] = in->m[0][3];
+ out[13] = in->m[1][3];
+ out[14] = in->m[2][3];
+ out[15] = in->m[3][3];
+}
+
void Matrix4x4_FromArrayDoubleGL (matrix4x4_t *out, const double in[16])
{
out->m[0][0] = in[0];
out->m[3][3] = in[15];
}
+void Matrix4x4_ToArrayDoubleD3D(const matrix4x4_t *in, double out[16])
+{
+ out[ 0] = in->m[0][0];
+ out[ 1] = in->m[0][1];
+ out[ 2] = in->m[0][2];
+ out[ 3] = in->m[0][3];
+ out[ 4] = in->m[1][0];
+ out[ 5] = in->m[1][1];
+ out[ 6] = in->m[1][2];
+ out[ 7] = in->m[1][3];
+ out[ 8] = in->m[2][0];
+ out[ 9] = in->m[2][1];
+ out[10] = in->m[2][2];
+ out[11] = in->m[2][3];
+ out[12] = in->m[3][0];
+ out[13] = in->m[3][1];
+ out[14] = in->m[3][2];
+ out[15] = in->m[3][3];
+}
+
void Matrix4x4_FromArrayDoubleD3D (matrix4x4_t *out, const double in[16])
{
out->m[0][0] = in[0];
out->m[2][3] += z;
}
+void Matrix4x4_Scale (matrix4x4_t *out, double rotatescale, double originscale)
+{
+ out->m[0][0] *= rotatescale;
+ out->m[0][1] *= rotatescale;
+ out->m[0][2] *= rotatescale;
+ out->m[0][3] *= originscale;
+ out->m[1][0] *= rotatescale;
+ out->m[1][1] *= rotatescale;
+ out->m[1][2] *= rotatescale;
+ out->m[1][3] *= originscale;
+ out->m[2][0] *= rotatescale;
+ out->m[2][1] *= rotatescale;
+ out->m[2][2] *= rotatescale;
+ out->m[2][3] *= originscale;
+}
// creates a matrix4x4 from a set of 3D vectors for axial directions, and translate
void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3], const float vz[3], const float t[3]);
-// creates a matrix4x4 from a float[16] array in the OpenGL orientation
+// converts a matrix4x4 to a double[16] array in the OpenGL orientation
+void Matrix4x4_ToArrayDoubleGL(const matrix4x4_t *in, double out[16]);
+// creates a matrix4x4 from a double[16] array in the OpenGL orientation
void Matrix4x4_FromArrayDoubleGL(matrix4x4_t *out, const double in[16]);
-// creates a matrix4x4 from a float[16] array in the Direct3D orientation
+// converts a matrix4x4 to a double[16] array in the Direct3D orientation
+void Matrix4x4_ToArrayDoubleD3D(const matrix4x4_t *in, double out[16]);
+// creates a matrix4x4 from a double[16] array in the Direct3D orientation
void Matrix4x4_FromArrayDoubleD3D(matrix4x4_t *out, const double in[16]);
// converts a matrix4x4 to a float[12] array in the OpenGL orientation
void Matrix4x4_SetOrigin (matrix4x4_t *out, double x, double y, double z);
// moves origin vector (translate) in matrix by a simple translate
void Matrix4x4_AdjustOrigin (matrix4x4_t *out, double x, double y, double z);
+// scales vectors of a matrix in place and allows you to scale origin as well
+void Matrix4x4_Scale (matrix4x4_t *out, double rotatescale, double originscale);
#endif
loadmodel->data_tags = (aliastag_t *)Mem_Alloc(loadmodel->mempool, loadmodel->num_tagframes * loadmodel->num_tags * sizeof(aliastag_t));
for (i = 0, pintag = (md3tag_t *)((unsigned char *)pinmodel + LittleLong(pinmodel->lump_tags));i < loadmodel->num_tagframes * loadmodel->num_tags;i++, pintag++)
{
+ float m[12];
strlcpy(loadmodel->data_tags[i].name, pintag->name, sizeof(loadmodel->data_tags[i].name));
loadmodel->data_tags[i].matrix = identitymatrix;
+ for (j = 0;j < 9;j++)
+ m[j] = LittleFloat(pintag->rotationmatrix[j]);
for (j = 0;j < 3;j++)
- {
- for (k = 0;k < 3;k++)
- loadmodel->data_tags[i].matrix.m[j][k] = LittleFloat(pintag->rotationmatrix[k * 3 + j]);
- loadmodel->data_tags[i].matrix.m[j][3] = LittleFloat(pintag->origin[j]);
- }
+ m[9+j] = LittleFloat(pintag->origin[j]);
+ Matrix4x4_FromArray12FloatGL(&loadmodel->data_tags[i].matrix, m);
//Con_Printf("model \"%s\" frame #%i tag #%i \"%s\"\n", loadmodel->name, i / loadmodel->num_tags, i % loadmodel->num_tags, loadmodel->data_tags[i].name);
}
void R_RTLight_Update(dlight_t *light, int isstatic)
{
- int j, k;
- float scale;
+ double scale;
rtlight_t *rtlight = &light->rtlight;
R_RTLight_Uncompile(rtlight);
memset(rtlight, 0, sizeof(*rtlight));
rtlight->specularscale = light->specularscale;
rtlight->flags = light->flags;
Matrix4x4_Invert_Simple(&rtlight->matrix_worldtolight, &light->matrix);
- // ConcatScale won't work here because this needs to scale rotate and
- // translate, not just rotate
- scale = 1.0f / rtlight->radius;
- for (k = 0;k < 3;k++)
- for (j = 0;j < 4;j++)
- rtlight->matrix_worldtolight.m[k][j] *= scale;
+ // this has to scale both rotate and translate because this is an already
+ // inverted matrix (it transforms from world to light space, not the other
+ // way around)
+ scale = 1.0 / rtlight->radius;
+ Matrix4x4_Scale(&rtlight->matrix_worldtolight, scale, scale);
}
// compiles rtlight geometry
{
int i;
model_t *model = ent->model;
- vec3_t left, up, org, color, diffusecolor, diffusenormal;
+ vec3_t left, up, org, color, diffusecolor, diffusenormal, mforward, mleft, mup;
mspriteframe_t *frame;
float scale;
// nudge it toward the view to make sure it isn't in a wall
- Matrix4x4_OriginFromMatrix(&ent->matrix, org);
+ Matrix4x4_ToVectors(&ent->matrix, mforward, mleft, mup, org);
VectorSubtract(org, r_view.forward, org);
switch(model->sprite.sprnum_type)
{
case SPR_VP_PARALLEL:
// normal sprite
// faces view plane
- left[0] = r_view.left[0] * ent->scale;
- left[1] = r_view.left[1] * ent->scale;
- left[2] = r_view.left[2] * ent->scale;
- up[0] = r_view.up[0] * ent->scale;
- up[1] = r_view.up[1] * ent->scale;
- up[2] = r_view.up[2] * ent->scale;
+ VectorScale(r_view.left, ent->scale, left);
+ VectorScale(r_view.up, ent->scale, up);
break;
case SPR_ORIENTED:
// bullet marks on walls
// ignores viewer entirely
- left[0] = ent->matrix.m[0][1];
- left[1] = ent->matrix.m[1][1];
- left[2] = ent->matrix.m[2][1];
- up[0] = ent->matrix.m[0][2];
- up[1] = ent->matrix.m[1][2];
- up[2] = ent->matrix.m[2][2];
+ VectorCopy(mleft, left);
+ VectorCopy(mup, up);
break;
case SPR_VP_PARALLEL_ORIENTED:
// I have no idea what people would use this for...
// oriented relative to view space
// FIXME: test this and make sure it mimicks software
- left[0] = ent->matrix.m[0][1] * r_view.forward[0] + ent->matrix.m[1][1] * r_view.left[0] + ent->matrix.m[2][1] * r_view.up[0];
- left[1] = ent->matrix.m[0][1] * r_view.forward[1] + ent->matrix.m[1][1] * r_view.left[1] + ent->matrix.m[2][1] * r_view.up[1];
- left[2] = ent->matrix.m[0][1] * r_view.forward[2] + ent->matrix.m[1][1] * r_view.left[2] + ent->matrix.m[2][1] * r_view.up[2];
- up[0] = ent->matrix.m[0][2] * r_view.forward[0] + ent->matrix.m[1][2] * r_view.left[0] + ent->matrix.m[2][2] * r_view.up[0];
- up[1] = ent->matrix.m[0][2] * r_view.forward[1] + ent->matrix.m[1][2] * r_view.left[1] + ent->matrix.m[2][2] * r_view.up[1];
- up[2] = ent->matrix.m[0][2] * r_view.forward[2] + ent->matrix.m[1][2] * r_view.left[2] + ent->matrix.m[2][2] * r_view.up[2];
+ left[0] = mleft[0] * r_view.forward[0] + mleft[1] * r_view.left[0] + mleft[2] * r_view.up[0];
+ left[1] = mleft[0] * r_view.forward[1] + mleft[1] * r_view.left[1] + mleft[2] * r_view.up[1];
+ left[2] = mleft[0] * r_view.forward[2] + mleft[1] * r_view.left[2] + mleft[2] * r_view.up[2];
+ up[0] = mup[0] * r_view.forward[0] + mup[1] * r_view.left[0] + mup[2] * r_view.up[0];
+ up[1] = mup[0] * r_view.forward[1] + mup[1] * r_view.left[1] + mup[2] * r_view.up[1];
+ up[2] = mup[0] * r_view.forward[2] + mup[1] * r_view.left[2] + mup[2] * r_view.up[2];
break;
}