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];
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;
// 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)