Subversion Repositories gelsvn

Rev

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