Subversion Repositories gelsvn

Rev

Rev 89 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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