Subversion Repositories gelsvn

Rev

Rev 2 | Rev 12 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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