Subversion Repositories gelsvn

Rev

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

Rev 50 Rev 89
1
#ifndef __CGLA_MAT4X4_H__
1
#ifndef __CGLA_MAT4X4_H__
2
#define __CGLA_MAT4X4_H__
2
#define __CGLA_MAT4X4_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 "ArithSqMat4x4Float.h"
9
#include "ArithSqMat4x4Float.h"
10
 
10
 
11
 
11
 
12
namespace CGLA 
12
namespace CGLA 
13
{
13
{
14
 
14
 
15
 
-
 
16
  /** Four by four float matrix.
15
  /** \brief 4x4 float matrix.
17
      This class is useful for transformations such as perspective projections 
16
      This class is useful for transformations such as perspective projections 
18
      or translation where 3x3 matrices do not suffice. */
17
      or translation where 3x3 matrices do not suffice. */
19
  class Mat4x4f: public ArithSqMat4x4Float<Vec4f, Mat4x4f>
18
  class Mat4x4f: public ArithSqMat4x4Float<Vec4f, Mat4x4f>
20
    {
19
    {
21
    public:
20
    public:
22
  
21
  
23
      /// Construct a Mat4x4f from four Vec4f vectors
22
      /// Construct a Mat4x4f from four Vec4f vectors
24
      Mat4x4f(Vec4f _a, Vec4f _b, Vec4f _c, Vec4f _d): 
23
      Mat4x4f(Vec4f _a, Vec4f _b, Vec4f _c, Vec4f _d): 
25
	ArithSqMat4x4Float<Vec4f, Mat4x4f> (_a,_b,_c,_d) {}
24
	ArithSqMat4x4Float<Vec4f, Mat4x4f> (_a,_b,_c,_d) {}
26
  
25
  
27
      /// Construct the NaN matrix
26
      /// Construct the NaN matrix
28
      Mat4x4f() {}
27
      Mat4x4f() {}
29
 
28
 
30
      /// Construct a matrix with identical elements.
29
      /// Construct a matrix with identical elements.
31
      explicit Mat4x4f(float a) : ArithSqMat4x4Float<Vec4f, Mat4x4f> (a) {}
30
      explicit Mat4x4f(float a) : ArithSqMat4x4Float<Vec4f, Mat4x4f> (a) {}
32
    };
31
    };
33
 
32
 
34
  /// Create a rotation _matrix. Rotates about one of the major axes.
33
  /// Create a rotation _matrix. Rotates about one of the major axes.
35
  Mat4x4f rotation_Mat4x4f(CGLA::Axis axis, float angle);
34
  Mat4x4f rotation_Mat4x4f(CGLA::Axis axis, float angle);
36
 
35
 
37
  /// Create a translation matrix
36
  /// Create a translation matrix
38
  Mat4x4f translation_Mat4x4f(const Vec3f&);
37
  Mat4x4f translation_Mat4x4f(const Vec3f&);
39
 
38
 
40
  /// Create a scaling matrix.
39
  /// Create a scaling matrix.
41
  Mat4x4f scaling_Mat4x4f(const Vec3f&);
40
  Mat4x4f scaling_Mat4x4f(const Vec3f&);
42
 
41
 
43
  /// Create an identity matrix.
42
  /// Create an identity matrix.
44
  inline Mat4x4f identity_Mat4x4f()
43
  inline Mat4x4f identity_Mat4x4f()
45
    {
44
    {
46
      return Mat4x4f(Vec4f(1,0,0,0), 
45
      return Mat4x4f(Vec4f(1,0,0,0), 
47
		     Vec4f(0,1,0,0), 
46
		     Vec4f(0,1,0,0), 
48
		     Vec4f(0,0,1,0), 
47
		     Vec4f(0,0,1,0), 
49
		     Vec4f(0,0,0,1));
48
		     Vec4f(0,0,0,1));
50
    }
49
    }
51
 
50
 
52
  /** Compute inverse assuming that the upper-left 3x3 sub-matrix is
51
  /** Compute inverse assuming that the upper-left 3x3 sub-matrix is
53
      orthonormal (which is the case if the transformation is only
52
      orthonormal (which is the case if the transformation is only
54
      a concatenation of rotations and translations).
53
      a concatenation of rotations and translations).
55
  */
54
  */
56
  inline Mat4x4f invert_ortho(const Mat4x4f& m)
55
  inline Mat4x4f invert_ortho(const Mat4x4f& m)
57
  {
56
  {
58
    Vec3f rx(m[0][0], m[1][0], m[2][0]);
57
    Vec3f rx(m[0][0], m[1][0], m[2][0]);
59
    Vec3f ry(m[0][1], m[1][1], m[2][1]);
58
    Vec3f ry(m[0][1], m[1][1], m[2][1]);
60
    Vec3f rz(m[0][2], m[1][2], m[2][2]);
59
    Vec3f rz(m[0][2], m[1][2], m[2][2]);
61
    Vec3f t(m[0][3], m[1][3], m[2][3]);
60
    Vec3f t(m[0][3], m[1][3], m[2][3]);
62
 
61
 
63
    return Mat4x4f(Vec4f(rx, -dot(t, rx)),
62
    return Mat4x4f(Vec4f(rx, -dot(t, rx)),
64
		   Vec4f(ry, -dot(t, ry)),
63
		   Vec4f(ry, -dot(t, ry)),
65
		   Vec4f(rz, -dot(t, rz)),
64
		   Vec4f(rz, -dot(t, rz)),
66
		   Vec4f(0.0, 0.0, 0.0, 1.0));
65
		   Vec4f(0.0, 0.0, 0.0, 1.0));
67
  }   
66
  }   
68
}
67
}
69
#endif
68
#endif
70
 
69
 
71
 
70
 
72
 
71
 
73
 
72
 
74
 
73
 
75
 
74
 
76
 
75
 
77
 
76