Subversion Repositories gelsvn

Rev

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

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