Subversion Repositories gelsvn

Rev

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

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