From: havoc Date: Sun, 13 Nov 2005 12:05:24 +0000 (+0000) Subject: added Matrix4x4_Normalize X-Git-Tag: xonotic-v0.1.0preview~4477 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2ca3c4f06325e060856e75634d584a0f19f1df12;p=xonotic%2Fdarkplaces.git added Matrix4x4_Normalize 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 --- diff --git a/cl_main.c b/cl_main.c index fa535661..13c04f1e 100644 --- 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)); - 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]; diff --git a/matrixlib.c b/matrixlib.c index 550a5118..5433aacc 100644 --- a/matrixlib.c +++ b/matrixlib.c @@ -158,6 +158,29 @@ void Matrix4x4_Invert_Simple (matrix4x4_t *out, const matrix4x4_t *in1) 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; diff --git a/matrixlib.h b/matrixlib.h index 06890e29..d3d29ed1 100644 --- a/matrixlib.h +++ b/matrixlib.h @@ -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 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)