]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - matrixlib.c
added -developer3 for crazy debugging sessions (gl_printcheckerror spew)
[xonotic/darkplaces.git] / matrixlib.c
index 266ec14173b6d094fec45efc47bf66b8ae24a678..f84e922d506dce80ac34ed6e69f081b59d1b56eb 100644 (file)
@@ -1569,26 +1569,20 @@ void Matrix4x4_ToBonePose6s(const matrix4x4_t *m, float origininvscale, short *p
 {
        float origin[3];
        float quat[4];
-       float s;
+       float quatscale;
        Matrix4x4_ToOrigin3Quat4Float(m, origin, quat);
        // normalize quaternion so that it is unit length
-       s = quat[0]*quat[0]+quat[1]*quat[1]+quat[2]*quat[2]+quat[3]*quat[3];
-       if (s)
-       {
-               s = 1.0f / sqrt(s);
-               quat[0] *= s;
-               quat[1] *= s;
-               quat[2] *= s;
-               quat[3] *= s;
-       }
+       quatscale = quat[0]*quat[0]+quat[1]*quat[1]+quat[2]*quat[2]+quat[3]*quat[3];
+       if (quatscale)
+               quatscale = (quat[3] >= 0 ? -32767.0f : 32767.0f) / sqrt(quatscale);
        // use a negative scale on the quat because the above function produces a
        // positive quat[3] and canonical quaternions have negative quat[3]
        pose6s[0] = origin[0] * origininvscale;
        pose6s[1] = origin[1] * origininvscale;
        pose6s[2] = origin[2] * origininvscale;
-       pose6s[3] = quat[0] * -32767.0f;
-       pose6s[4] = quat[1] * -32767.0f;
-       pose6s[5] = quat[2] * -32767.0f;
+       pose6s[3] = quat[0] * quatscale;
+       pose6s[4] = quat[1] * quatscale;
+       pose6s[5] = quat[2] * quatscale;
 }
 
 void Matrix4x4_Blend (matrix4x4_t *out, const matrix4x4_t *in1, const matrix4x4_t *in2, double blend)
@@ -1654,6 +1648,7 @@ void Matrix4x4_Transform3x3 (const matrix4x4_t *in, const float v[3], float out[
 #endif
 }
 
+// transforms a positive distance plane (A*x+B*y+C*z-D=0) through a rotation or translation matrix
 void Matrix4x4_TransformPositivePlane(const matrix4x4_t *in, float x, float y, float z, float d, float *o)
 {
        float scale = sqrt(in->m[0][0] * in->m[0][0] + in->m[0][1] * in->m[0][1] + in->m[0][2] * in->m[0][2]);
@@ -1671,6 +1666,7 @@ void Matrix4x4_TransformPositivePlane(const matrix4x4_t *in, float x, float y, f
 #endif
 }
 
+// transforms a standard plane (A*x+B*y+C*z+D=0) through a rotation or translation matrix
 void Matrix4x4_TransformStandardPlane(const matrix4x4_t *in, float x, float y, float z, float d, float *o)
 {
        float scale = sqrt(in->m[0][0] * in->m[0][0] + in->m[0][1] * in->m[0][1] + in->m[0][2] * in->m[0][2]);