Subversion Repositories gelsvn

Rev

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

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