]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
more cleaning of matrix4x4_t struct access
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 6 Nov 2006 07:31:00 +0000 (07:31 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 6 Nov 2006 07:31:00 +0000 (07:31 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6613 d7cf8633-e32d-0410-b094-e92efae38249

gl_backend.c
matrixlib.c
matrixlib.h
model_alias.c
r_shadow.c
r_sprites.c

index e6790294e0f0d5c8f32188f407496d5456745007..96c341cb79f3c19c38e6088d806807c4d125cdbf 100644 (file)
@@ -73,7 +73,6 @@ void SCR_ScreenShot_f (void);
 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;
@@ -1034,11 +1033,12 @@ void R_Mesh_Matrix(const matrix4x4_t *matrix)
 {
        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
        }
 }
 
@@ -1511,14 +1511,14 @@ void R_Mesh_TexMatrix(unsigned int unitnum, const matrix4x4_t *matrix)
                // 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
                }
        }
index 6ba666765af8569d5a446b4e238fb587647c6f24..2800ac0d8f3d4a7fb91c4efa7c6c628b02e9b0a7 100644 (file)
@@ -430,6 +430,26 @@ void Matrix4x4_FromVectors(matrix4x4_t *out, const float vx[3], const float vy[3
        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];
@@ -450,6 +470,26 @@ void Matrix4x4_FromArrayDoubleGL (matrix4x4_t *out, const double in[16])
        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];
@@ -682,3 +722,18 @@ void Matrix4x4_AdjustOrigin (matrix4x4_t *out, double x, double y, double z)
        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;
+}
index af2555dd1fbe9b67a4f65c503b57807b3de26fc4..90e816270a4b7cc5346058673f9feadba872c1a8 100644 (file)
@@ -64,9 +64,13 @@ void Matrix4x4_ToVectors(const matrix4x4_t *in, float vx[3], float vy[3], float
 // 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
@@ -118,5 +122,7 @@ double Matrix4x4_ScaleFromMatrix (const matrix4x4_t *in);
 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
index c90dd72030fecba1296ff2b63ad428c347052ce6..09d5a70b3b9e6bf77f5d82424be65fe3648b69fd 100644 (file)
@@ -1238,14 +1238,14 @@ void Mod_IDP3_Load(model_t *mod, void *buffer, void *bufferend)
        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);
        }
 
index d1023740e5cb7a00501fad600975c08b5340bf99..a3376ad2dd718b8045bcc0b05693184bed17de29 100644 (file)
@@ -2053,8 +2053,7 @@ void R_Shadow_RenderSurfacesLighting(int numsurfaces, msurface_t **surfacelist)
 
 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));
@@ -2085,12 +2084,11 @@ void R_RTLight_Update(dlight_t *light, int isstatic)
        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
index 46a54ded5e03e141d78eba8a37af16a32f9c3e93..87c06b74ebce192b1bb36f8f9896db629d372920 100644 (file)
@@ -6,12 +6,12 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const r
 {
        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)
        {
@@ -43,33 +43,25 @@ void R_Model_Sprite_Draw_TransparentCallback(const entity_render_t *ent, const r
        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;
        }