]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
added Matrix4x4_Normalize
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 13 Nov 2005 12:05:24 +0000 (12:05 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 13 Nov 2005 12:05:24 +0000 (12:05 +0000)
now normalizes dlight matrix so that attached dlight entities won't be smaller/bigger than normal

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5807 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
matrixlib.c
matrixlib.h

index fa5356618b2e699b0c5aa9a01633ac2033109a6e..13c04f1ea15a1e1d6b732db6237daea4ee0a495a 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -519,7 +519,7 @@ void CL_AllocDlight(entity_render_t *ent, matrix4x4_t *matrix, float radius, flo
 dlightsetup:
        //Con_Printf("dlight %i : %f %f %f : %f %f %f\n", i, org[0], org[1], org[2], red * radius, green * radius, blue * radius);
        memset (dl, 0, sizeof(*dl));
 dlightsetup:
        //Con_Printf("dlight %i : %f %f %f : %f %f %f\n", i, org[0], org[1], org[2], red * radius, green * radius, blue * radius);
        memset (dl, 0, sizeof(*dl));
-       dl->matrix = *matrix;
+       Matrix4x4_Normalize(&dl->matrix, matrix);
        dl->ent = ent;
        dl->origin[0] = dl->matrix.m[0][3];
        dl->origin[1] = dl->matrix.m[1][3];
        dl->ent = ent;
        dl->origin[0] = dl->matrix.m[0][3];
        dl->origin[1] = dl->matrix.m[1][3];
index 550a511837d6981c196204e21f8d6618334bcea8..5433aaccbb032661c0c3cb7eddc0c5bf5a760c82 100644 (file)
@@ -158,6 +158,29 @@ void Matrix4x4_Invert_Simple (matrix4x4_t *out, const matrix4x4_t *in1)
        out->m[3][3] = 1;
 }
 
        out->m[3][3] = 1;
 }
 
+void Matrix4x4_Normalize (matrix4x4_t *out, matrix4x4_t *in1)
+{
+       // scale rotation matrix vectors to a length of 1
+       // note: this is only designed to undo uniform scaling
+       double scale = 1.0 / sqrt(in1->m[0][0] * in1->m[0][0] + in1->m[0][1] * in1->m[0][1] + in1->m[0][2] * in1->m[0][2]);
+       out->m[0][0] = (float)(in1->m[0][0] * scale);
+       out->m[0][1] = (float)(in1->m[1][0] * scale);
+       out->m[0][2] = (float)(in1->m[2][0] * scale);
+       out->m[0][3] = (float)(in1->m[0][3]);
+       out->m[1][0] = (float)(in1->m[0][1] * scale);
+       out->m[1][1] = (float)(in1->m[1][1] * scale);
+       out->m[1][2] = (float)(in1->m[2][1] * scale);
+       out->m[1][3] = (float)(in1->m[1][3]);
+       out->m[2][0] = (float)(in1->m[0][2] * scale);
+       out->m[2][1] = (float)(in1->m[1][2] * scale);
+       out->m[2][2] = (float)(in1->m[2][2] * scale);
+       out->m[2][3] = (float)(in1->m[2][3]);
+       out->m[3][0] = 0;
+       out->m[3][1] = 0;
+       out->m[3][2] = 0;
+       out->m[3][3] = 1;
+}
+
 void Matrix4x4_CreateIdentity (matrix4x4_t *out)
 {
        out->m[0][0]=1.0f;
 void Matrix4x4_CreateIdentity (matrix4x4_t *out)
 {
        out->m[0][0]=1.0f;
index 06890e294b9171ff6d18bfa3f7e4ca4677ec69b0..d3d29ed1303316a2ce9e2873d459ecf485e7adfe 100644 (file)
@@ -34,6 +34,9 @@ void Matrix4x4_Transpose3x3 (matrix4x4_t *out, const matrix4x4_t *in1);
 // creates a matrix that does the opposite of the matrix provided
 // only supports translate, rotate, scale (not scale3) matrices
 void Matrix4x4_Invert_Simple (matrix4x4_t *out, const matrix4x4_t *in1);
 // creates a matrix that does the opposite of the matrix provided
 // only supports translate, rotate, scale (not scale3) matrices
 void Matrix4x4_Invert_Simple (matrix4x4_t *out, const matrix4x4_t *in1);
+// creates a matrix that does the same rotation and translation as the matrix
+// provided, but no uniform scaling, does not support scale3 matrices
+void Matrix4x4_Normalize (matrix4x4_t *out, matrix4x4_t *in1);
 
 // creates an identity matrix
 // (a matrix which does nothing)
 
 // creates an identity matrix
 // (a matrix which does nothing)