re-optimize mat4 determinant

* note: for square matrices det(a) = det(transpose(a)), we can go with
row-major calc here
This commit is contained in:
Recep Aslantas
2016-09-20 23:27:00 +03:00
parent 8a6fe6948a
commit b2b50076d2
2 changed files with 53 additions and 34 deletions

View File

@@ -153,16 +153,17 @@ glm_mat4_det(mat4 mat) {
#if defined( __SSE__ ) || defined( __SSE2__ )
return glm_mat4_det_sse2(mat);
#else
/* [square] det(A) = det(At) */
float t[6];
float a, b, c, d,
e, f, g, h,
i, j, k, l,
m, n, o, p;
a = mat[0][0], b = mat[1][0], c = mat[2][0], d = mat[3][0],
e = mat[0][1], f = mat[1][1], g = mat[2][1], h = mat[3][1],
i = mat[0][2], j = mat[1][2], k = mat[2][2], l = mat[3][2],
m = mat[0][3], n = mat[1][3], o = mat[2][3], p = mat[3][3];
a = mat[0][0], b = mat[0][1], c = mat[0][2], d = mat[0][3],
e = mat[1][0], f = mat[1][1], g = mat[1][2], h = mat[1][3],
i = mat[2][0], j = mat[2][1], k = mat[2][2], l = mat[2][3],
m = mat[3][0], n = mat[3][1], o = mat[3][2], p = mat[3][3];
t[0] = k * p - o * l;
t[1] = j * p - n * l;
@@ -171,10 +172,10 @@ glm_mat4_det(mat4 mat) {
t[4] = i * o - m * k;
t[5] = i * n - m * j;
return a * (f * t[0] - g * t[1] + h * t[2])
- b * (e * t[0] - g * t[3] + h * t[4])
+ c * (e * t[1] - f * t[3] + h * t[5])
- d * (e * t[2] - f * t[4] + g * t[5]);
return a * (f * t[0] - g * t[1] + h * t[2])
- b * (e * t[0] - g * t[3] + h * t[4])
+ c * (e * t[1] - f * t[3] + h * t[5])
- d * (e * t[2] - f * t[4] + g * t[5]);
#endif
}