]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - matrixlib.c
optimized edgedir handling to use half as many, which reduces it from
[xonotic/darkplaces.git] / matrixlib.c
index 38c41817750e1c8a737cb94deec3fdcd3dede6b6..a7fdd38f48a0f17c9746613e307000be3bf7142d 100644 (file)
@@ -147,7 +147,6 @@ void Matrix4x4_Transpose (matrix4x4_t *out, const matrix4x4_t *in1)
 int Matrix4x4_Invert_Full (matrix4x4_t *out, const matrix4x4_t *in1)
 {
         float det;
-        int i, j;
 
         // note: orientation does not matter, as transpose(invert(transpose(m))) == invert(m), proof:
         //   transpose(invert(transpose(m))) * m
@@ -181,7 +180,7 @@ int Matrix4x4_Invert_Full (matrix4x4_t *out, const matrix4x4_t *in1)
         out->m[3][3] =  (m00*(m11*m22 - m12*m21) - m10*(m01*m22 - m02*m21) + m20*(m01*m12 - m02*m11));
 
         // calculate the determinant (as inverse == 1/det * adjoint, adjoint * m == identity * det, so this calculates the det)
-        det = in1->m[0][0]*out->m[0][0] + in1->m[1][0]*out->m[0][1] + in1->m[2][0]*out->m[0][2] + in1->m[3][0]*out->m[0][3];
+        det = m00*out->m[0][0] + m10*out->m[0][1] + m20*out->m[0][2] + m30*out->m[0][3];
         if (det == 0.0f)
                 return 0;
 
@@ -1664,3 +1663,17 @@ void Matrix4x4_Scale (matrix4x4_t *out, double rotatescale, double originscale)
        out->m[2][3] *= originscale;
 #endif
 }
+
+void Matrix4x4_Abs (matrix4x4_t *out)
+{
+    out->m[0][0] = fabs(out->m[0][0]);
+    out->m[0][1] = fabs(out->m[0][1]);
+    out->m[0][2] = fabs(out->m[0][2]);
+    out->m[1][0] = fabs(out->m[1][0]);
+    out->m[1][1] = fabs(out->m[1][1]);
+    out->m[1][2] = fabs(out->m[1][2]);
+    out->m[2][0] = fabs(out->m[2][0]);
+    out->m[2][1] = fabs(out->m[2][1]);
+    out->m[2][2] = fabs(out->m[2][2]);
+}
+