Subversion Repositories gelsvn

Rev

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

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