Subversion Repositories gelsvn

Rev

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

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