Subversion Repositories gelsvn

Rev

Rev 324 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 324 Rev 327
Line 20... Line 20...
20
			a0*b2*c1 -
20
			a0*b2*c1 -
21
			a1*b0*c2 ;
21
			a1*b0*c2 ;
22
	}
22
	}
23
}
23
}
24
 
24
 
25
		/** Compute the determinant of a 4x4 matrix. The code below is what
-
 
26
				I found to be most robust. The original implementation used direct
-
 
27
				computation of the 3x3 sub-determinants and I also tried a direct
-
 
28
				computation based on enumerating all permutations. The code below
-
 
29
				is better. */
-
 
30
	template<class V, class M>
-
 
31
	double 
-
 
32
	determinant(const ArithSqMat4x4Float<V,M>& m)
-
 
33
	{
-
 
34
		typedef typename M::ScalarType ScalarType;
-
 
35
    ScalarType ans;
-
 
36
    ScalarType a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4;
-
 
37
    
-
 
38
    /* assign to individual variable names to aid selecting */
-
 
39
		/*  correct elements */
-
 
40
		
-
 
41
		a1 = m[0][0]; b1 = m[1][0]; c1 = m[2][0]; d1 = m[3][0];
-
 
42
		a2 = m[0][1]; b2 = m[1][1]; c2 = m[2][1]; d2 = m[3][1];
-
 
43
		a3 = m[0][2]; b3 = m[1][2]; c3 = m[2][2]; d3 = m[3][2];
-
 
44
		a4 = m[0][3]; b4 = m[1][3]; c4 = m[2][3]; d4 = m[3][3];
-
 
45
 
-
 
46
		ans = 
-
 
47
				a1 * (b2*(c3*d4-d3*c4)-c2*(b3*d4-d3*b4)+d2*(b3*c4-c3*b4))
-
 
48
				- b1 * (a2*(c3*d4-d3*c4)-c2*(a3*d4-d3*a4)+d2*(a3*c4-c3*a4))
-
 
49
				+ c1 * (a2*(b3*d4-d3*b4)-b2*(a3*d4-d3*a4)+d2*(a3*b4-b3*a4))
-
 
50
				- d1 * (a2*(b3*c4-c3*b4)-b2*(a3*c4-c3*a4)+c2*(a3*b4-b3*a4));
-
 
51
		return ans;
-
 
52
	}
-
 
53
 
25
 
54
 
26
 
55
	template<class V, class M>
27
	template<class V, class M>
56
	M invert_affine(const ArithSqMat4x4Float<V,M>& this_mat)
28
	M invert_affine(const ArithSqMat4x4Float<V,M>& this_mat)
57
	{
29
	{
58
		//   The following code has been copied from a gem in Graphics Gems II by
30
		//   The following com[3]e has been copied from a gem in Graphics Gems II by
59
		//   Kevin Wu.                      
31
		//   Kevin Wu.                      
60
		//   The function is very fast, but it can only invert affine matrices. An
32
		//   The function is very fast, but it can only invert affine matrices. An
61
		//   exception NotAffine is thrown if the matrix is not affine, and another
33
		//   exception NotAffine is thrown if the matrix is not affine, and another
62
		//   exception Singular is thrown if the matrix is singular.
34
		//   exception Singular is thrown if the matrix is singular.
63
		
35
		
Line 219... Line 191...
219
	}
191
	}
220
 
192
 
221
 
193
 
222
	template class ArithSqMat4x4Float<Vec4f, Mat4x4f>;
194
	template class ArithSqMat4x4Float<Vec4f, Mat4x4f>;
223
	template Mat4x4f adjoint(const ArithSqMat4x4Float<Vec4f,Mat4x4f>&);
195
	template Mat4x4f adjoint(const ArithSqMat4x4Float<Vec4f,Mat4x4f>&);
224
	template double determinant(const ArithSqMat4x4Float<Vec4f,Mat4x4f>&);
-
 
225
	template Mat4x4f invert(const ArithSqMat4x4Float<Vec4f,Mat4x4f>&);
196
	template Mat4x4f invert(const ArithSqMat4x4Float<Vec4f,Mat4x4f>&);
226
	template Mat4x4f invert_affine(const ArithSqMat4x4Float<Vec4f,Mat4x4f>&);
197
	template Mat4x4f invert_affine(const ArithSqMat4x4Float<Vec4f,Mat4x4f>&);
227
 
198
 
228
	template class ArithSqMat4x4Float<Vec4d, Mat4x4d>;
199
	template class ArithSqMat4x4Float<Vec4d, Mat4x4d>;
229
	template Mat4x4d adjoint(const ArithSqMat4x4Float<Vec4d,Mat4x4d>&);
200
	template Mat4x4d adjoint(const ArithSqMat4x4Float<Vec4d,Mat4x4d>&);
230
	template double determinant(const ArithSqMat4x4Float<Vec4d,Mat4x4d>&);
-
 
231
	template Mat4x4d invert(const ArithSqMat4x4Float<Vec4d,Mat4x4d>&);
201
	template Mat4x4d invert(const ArithSqMat4x4Float<Vec4d,Mat4x4d>&);
232
	template Mat4x4d invert_affine(const ArithSqMat4x4Float<Vec4d,Mat4x4d>&);
202
	template Mat4x4d invert_affine(const ArithSqMat4x4Float<Vec4d,Mat4x4d>&);
233
 
203
 
234
 
204
 
235
}
205
}