Line 85... |
Line 85... |
85 |
entry is the subdeterminant of 'in' where the row and column of
|
85 |
entry is the subdeterminant of 'in' where the row and column of
|
86 |
the element is removed. Use mostly to compute the inverse */
|
86 |
the element is removed. Use mostly to compute the inverse */
|
87 |
template<class VT, class M>
|
87 |
template<class VT, class M>
|
88 |
M adjoint(const ArithSqMat4x4Float<VT,M>&);
|
88 |
M adjoint(const ArithSqMat4x4Float<VT,M>&);
|
89 |
|
89 |
|
90 |
/** Compute the determinant of a 4x4f matrix. */
|
90 |
/** Compute the determinant of a 4x4 matrix. The code below is what
|
- |
|
91 |
I found to be most robust. The original implementation used direct
|
- |
|
92 |
computation of the 3x3 sub-determinants and I also tried a direct
|
- |
|
93 |
computation based on enumerating all permutations. The code below
|
- |
|
94 |
is better. */
|
91 |
template<class VT, class M>
|
95 |
template<class V, class M>
|
92 |
double determinant(const ArithSqMat4x4Float<VT,M>&);
|
96 |
inline double determinant(const ArithSqMat4x4Float<V,M>& m)
|
- |
|
97 |
{
|
- |
|
98 |
/* return m[0][0] * (m[1][1]*(m[2][2]*m[3][3]-m[3][2]*m[2][3])- */
|
- |
|
99 |
/* m[2][1]*(m[1][2]*m[3][3]-m[3][2]*m[1][3])+ */
|
- |
|
100 |
/* m[3][1]*(m[1][2]*m[2][3]-m[2][2]*m[1][3])) */
|
- |
|
101 |
/* - m[1][0] * (m[0][1]*(m[2][2]*m[3][3]-m[3][2]*m[2][3])- */
|
- |
|
102 |
/* m[2][1]*(m[0][2]*m[3][3]-m[3][2]*m[0][3])+ */
|
- |
|
103 |
/* m[3][1]*(m[0][2]*m[2][3]-m[2][2]*m[0][3])) */
|
- |
|
104 |
/* + m[2][0] * (m[0][1]*(m[1][2]*m[3][3]-m[3][2]*m[1][3])- */
|
- |
|
105 |
/* m[1][1]*(m[0][2]*m[3][3]-m[3][2]*m[0][3])+ */
|
- |
|
106 |
/* m[3][1]*(m[0][2]*m[1][3]-m[1][2]*m[0][3])) */
|
- |
|
107 |
/* - m[3][0] * (m[0][1]*(m[1][2]*m[2][3]-m[2][2]*m[1][3])- */
|
- |
|
108 |
/* m[1][1]*(m[0][2]*m[2][3]-m[2][2]*m[0][3])+ */
|
- |
|
109 |
/* m[2][1]*(m[0][2]*m[1][3]-m[1][2]*m[0][3])); */
|
- |
|
110 |
typedef typename M::ScalarType ScalarType;
|
- |
|
111 |
ScalarType a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4;
|
- |
|
112 |
|
- |
|
113 |
/* assign to individual variable names to aid selecting */
|
- |
|
114 |
/* correct elements */
|
- |
|
115 |
|
- |
|
116 |
a1 = m[0][0]; b1 = m[1][0]; c1 = m[2][0]; d1 = m[3][0];
|
- |
|
117 |
a2 = m[0][1]; b2 = m[1][1]; c2 = m[2][1]; d2 = m[3][1];
|
- |
|
118 |
a3 = m[0][2]; b3 = m[1][2]; c3 = m[2][2]; d3 = m[3][2];
|
- |
|
119 |
a4 = m[0][3]; b4 = m[1][3]; c4 = m[2][3]; d4 = m[3][3];
|
- |
|
120 |
|
- |
|
121 |
return
|
- |
|
122 |
a1 * (b2*(c3*d4-d3*c4)-c2*(b3*d4-d3*b4)+d2*(b3*c4-c3*b4))
|
- |
|
123 |
- b1 * (a2*(c3*d4-d3*c4)-c2*(a3*d4-d3*a4)+d2*(a3*c4-c3*a4))
|
- |
|
124 |
+ c1 * (a2*(b3*d4-d3*b4)-b2*(a3*d4-d3*a4)+d2*(a3*b4-b3*a4))
|
- |
|
125 |
- d1 * (a2*(b3*c4-c3*b4)-b2*(a3*c4-c3*a4)+c2*(a3*b4-b3*a4));
|
- |
|
126 |
|
- |
|
127 |
}
|
93 |
|
128 |
|
94 |
/// Compute the inverse matrix of a Mat4x4f.
|
129 |
/// Compute the inverse matrix of a Mat4x4f.
|
95 |
template<class VT, class M>
|
130 |
template<class VT, class M>
|
96 |
M invert(const ArithSqMat4x4Float<VT,M>&);
|
131 |
M invert(const ArithSqMat4x4Float<VT,M>&);
|
97 |
|
132 |
|