Subversion Repositories gelsvn

Rev

Rev 2 | Rev 12 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 10
1
#ifndef __CGLA_ARITHSQMAT4X4FLOAT_H
1
#ifndef __CGLA_ARITHSQMAT4X4FLOAT_H
2
#define __CGLA_ARITHSQMAT4X4FLOAT_H
2
#define __CGLA_ARITHSQMAT4X4FLOAT_H
3
 
3
 
4
#include "ExceptionStandard.h"
4
#include "ExceptionStandard.h"
5
#include "CGLA.h"
5
#include "CGLA.h"
6
#include "Vec3f.h"
6
#include "Vec3f.h"
7
#include "Vec3Hf.h"
7
#include "Vec3Hf.h"
8
#include "Vec4f.h"
8
#include "Vec4f.h"
9
#include "ArithSqMatFloat.h"
9
#include "ArithSqMatFloat.h"
10
 
10
 
11
 
11
 
12
namespace CGLA {
12
namespace CGLA {
13
 
13
 
14
	CGLA_DERIVEEXCEPTION(Mat4x4fException)
14
	CGLA_DERIVEEXCEPTION(Mat4x4fException)
15
	CGLA_DERIVEEXCEPTION(Mat4x4fNotAffine)
15
	CGLA_DERIVEEXCEPTION(Mat4x4fNotAffine)
16
	CGLA_DERIVEEXCEPTION(Mat4x4fSingular)
16
	CGLA_DERIVEEXCEPTION(Mat4x4fSingular)
17
 
17
 
18
	/** Four by four float matrix.
18
	/** Four by four float matrix.
19
			This class is useful for transformations such as perspective projections 
19
			This class is useful for transformations such as perspective projections 
20
			or translation where 3x3 matrices do not suffice. */
20
			or translation where 3x3 matrices do not suffice. */
21
	template<class V, class M>
21
	template<class V, class M>
22
	class ArithSqMat4x4Float: public ArithSqMatFloat<V, M, 4>
22
	class ArithSqMat4x4Float: public ArithSqMatFloat<V, M, 4>
23
	{
23
	{
24
	public:
24
	public:
25
  
25
  
26
		/// Construct a Mat4x4f from four V vectors
26
		/// Construct a Mat4x4f from four V vectors
27
		ArithSqMat4x4Float(V a, V b, V c, V d): 
27
		ArithSqMat4x4Float(V a, V b, V c, V d): 
28
			ArithSqMatFloat<V, M, 4> (a,b,c,d) {}
28
			ArithSqMatFloat<V, M, 4> (a,b,c,d) {}
29
  
29
  
30
		/// Construct the 0 matrix
30
		/// Construct the NAN matrix
31
		ArithSqMat4x4Float() {}
31
		ArithSqMat4x4Float() {}
32
 
32
 
-
 
33
		/// Construct matrix where all values are equal to constructor argument.
-
 
34
 
-
 
35
  	/**** SHOULD NOT USE DOUBLE BELOW. USE WHATEVER TYPE SAYS ****/		
-
 
36
		explicit ArithSqMat4x4Float(double  _a):
-
 
37
    		ArithSqMatFloat<V,M,4>(_a) {}
-
 
38
 
33
		/// Construct from a pointed to array of 16 floats.
39
		/// Construct from a pointed to array of 16 floats.
34
		ArithSqMat4x4Float(const float* sa): ArithSqMatFloat<V, M, 4> (sa) {}
40
		ArithSqMat4x4Float(const float* sa): ArithSqMatFloat<V, M, 4> (sa) {}
35
 
41
 
36
		/** Multiply vector onto matrix. Here the fourth coordinate 
42
		/** Multiply vector onto matrix. Here the fourth coordinate 
37
				is se to 0. This removes any translation from the matrix.
43
				is se to 0. This removes any translation from the matrix.
38
				Useful if one wants to transform a vector which does not
44
				Useful if one wants to transform a vector which does not
39
				represent a point but a direction. Note that this is not
45
				represent a point but a direction. Note that this is not
40
				correct for transforming normal vectors if the matric 
46
				correct for transforming normal vectors if the matric 
41
				contains anisotropic scaling. */
47
				contains anisotropic scaling. */
42
		template<class T, class VecT>
48
		template<class T, class VecT>
43
		const VecT mul_3D_vector(const ArithVec3Float<T,VecT>& v_in) const
49
		const VecT mul_3D_vector(const ArithVec3Float<T,VecT>& v_in) const
44
		{
50
		{
45
			V v_out  = (*this) * V(v_in[0],v_in[1],v_in[2],0);
51
			V v_out  = (*this) * V(v_in[0],v_in[1],v_in[2],0);
46
			return VecT(v_out[0],v_out[1],v_out[2]);
52
			return VecT(v_out[0],v_out[1],v_out[2]);
47
		}
53
		}
48
 
54
 
49
		/** Multiply 3D point onto matrix. Here the fourth coordinate 
55
		/** Multiply 3D point onto matrix. Here the fourth coordinate 
50
				becomes 1 to ensure that the point is translated. Note that
56
				becomes 1 to ensure that the point is translated. Note that
51
				the vector is converted back into a Vec3f without any 
57
				the vector is converted back into a Vec3f without any 
52
				division by w. This is deliberate: Typically, w=1 except
58
				division by w. This is deliberate: Typically, w=1 except
53
				for projections. If we are doing projection, we can use
59
				for projections. If we are doing projection, we can use
54
				project_3D_point instead */
60
				project_3D_point instead */
55
		template<class T, class VecT>
61
		template<class T, class VecT>
56
		const VecT mul_3D_point(const ArithVec3Float<T,VecT> & v_in) const
62
		const VecT mul_3D_point(const ArithVec3Float<T,VecT> & v_in) const
57
		{
63
		{
58
			V v_out  = (*this) * V(v_in[0],v_in[1],v_in[2],1);
64
			V v_out  = (*this) * V(v_in[0],v_in[1],v_in[2],1);
59
			return VecT(v_out[0],v_out[1],v_out[2]);
65
			return VecT(v_out[0],v_out[1],v_out[2]);
60
		}
66
		}
61
 
67
 
62
		/** Multiply 3D point onto matrix. We set w=1 before 
68
		/** Multiply 3D point onto matrix. We set w=1 before 
63
				multiplication and divide by w after multiplication. */
69
				multiplication and divide by w after multiplication. */
64
		template<class T, class VecT>
70
		template<class T, class VecT>
65
		const VecT project_3D_point(const ArithVec3Float<T,VecT>& v_in) const
71
		const VecT project_3D_point(const ArithVec3Float<T,VecT>& v_in) const
66
		{
72
		{
67
			V v_out = (*this) * V(v_in[0],v_in[1],v_in[2],1);
73
			V v_out = (*this) * V(v_in[0],v_in[1],v_in[2],1);
68
			v_out.de_homogenize();
74
			v_out.de_homogenize();
69
			return VecT(v_out[0],v_out[1],v_out[2]);
75
			return VecT(v_out[0],v_out[1],v_out[2]);
70
		}
76
		}
71
 
77
 
72
	};
78
	};
73
 
79
 
74
	/** Compute the adjoint of a matrix. This is the matrix where each
80
	/** Compute the adjoint of a matrix. This is the matrix where each
75
			entry is the subdeterminant of 'in' where the row and column of 
81
			entry is the subdeterminant of 'in' where the row and column of 
76
			the element is removed. Use mostly to compute the inverse */
82
			the element is removed. Use mostly to compute the inverse */
77
	template<class V, class M>
83
	template<class V, class M>
78
	M adjoint(const ArithSqMat4x4Float<V,M>&);
84
	M adjoint(const ArithSqMat4x4Float<V,M>&);
79
		
85
		
80
	/** Compute the determinant of a 4x4f matrix. */ 
86
	/** Compute the determinant of a 4x4f matrix. */ 
81
	template<class V, class M>
87
	template<class V, class M>
82
	double 
88
	double 
83
	determinant(const ArithSqMat4x4Float<V,M>&);
89
	determinant(const ArithSqMat4x4Float<V,M>&);
84
 
90
 
85
	/// Compute the inverse matrix of a Mat4x4f.
91
	/// Compute the inverse matrix of a Mat4x4f.
86
	template<class V, class M>
92
	template<class V, class M>
87
	M invert(const ArithSqMat4x4Float<V,M>&);
93
	M invert(const ArithSqMat4x4Float<V,M>&);
88
 
94
 
89
	/// Compute the inverse matrix of a Mat4x4f that is affine
95
	/// Compute the inverse matrix of a Mat4x4f that is affine
90
	template<class V, class M>
96
	template<class V, class M>
91
	M invert_affine(const ArithSqMat4x4Float<V,M>&);
97
	M invert_affine(const ArithSqMat4x4Float<V,M>&);
92
 
98
 
93
}
99
}
94
#endif
100
#endif
95
 
101
 
96
 
102
 
97
 
103
 
98
 
104
 
99
 
105
 
100
 
106
 
101
 
107
 
102
 
108