Subversion Repositories gelsvn

Rev

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

Rev 595 Rev 624
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 Mat4x4f.h
7
/** @file Mat4x4f.h
8
 * @brief 4x4 float matrix class
8
 * @brief 4x4 float matrix class
9
 */
9
 */
10
 
10
 
11
#ifndef __CGLA_MAT4X4_H__
11
#ifndef __CGLA_MAT4X4_H__
12
#define __CGLA_MAT4X4_H__
12
#define __CGLA_MAT4X4_H__
13
 
13
 
14
#include "ExceptionStandard.h"
14
#include "ExceptionStandard.h"
15
#include "CGLA.h"
15
#include "CGLA.h"
16
#include "Vec3f.h"
16
#include "Vec3f.h"
17
#include "Vec3Hf.h"
17
#include "Vec3Hf.h"
18
#include "Vec4f.h"
18
#include "Vec4f.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 float matrix.
25
  /** \brief 4x4 float matrix.
26
      This class is useful for transformations such as perspective projections 
26
      This class is useful for transformations such as perspective projections 
27
      or translation where 3x3 matrices do not suffice. */
27
      or translation where 3x3 matrices do not suffice. */
28
  class Mat4x4f: public ArithSqMat4x4Float<Vec4f, Mat4x4f>
28
  class Mat4x4f: public ArithSqMat4x4Float<Vec4f, Mat4x4f>
29
    {
29
    {
30
    public:
30
    public:
31
  
31
  
32
      /// Construct a Mat4x4f from four Vec4f vectors
32
      /// Construct a Mat4x4f from four Vec4f vectors
33
      Mat4x4f(Vec4f _a, Vec4f _b, Vec4f _c, Vec4f _d): 
33
      Mat4x4f(Vec4f _a, Vec4f _b, Vec4f _c, Vec4f _d): 
34
	ArithSqMat4x4Float<Vec4f, Mat4x4f> (_a,_b,_c,_d) {}
34
	ArithSqMat4x4Float<Vec4f, Mat4x4f> (_a,_b,_c,_d) {}
35
  
35
  
36
      /// Construct the NaN matrix
36
      /// Construct the NaN matrix
37
      Mat4x4f() {}
37
      Mat4x4f() {}
38
 
38
 
39
      /// Construct a matrix with identical elements.
39
      /// Construct a matrix with identical elements.
40
      explicit Mat4x4f(float a) : ArithSqMat4x4Float<Vec4f, Mat4x4f> (a) {}
40
      explicit Mat4x4f(float a) : ArithSqMat4x4Float<Vec4f, Mat4x4f> (a) {}
41
    };
41
    };
42
 
42
 
43
  /// Create a rotation _matrix. Rotates about one of the major axes.
43
  /// Create a rotation _matrix. Rotates about one of the major axes.
44
  Mat4x4f rotation_Mat4x4f(CGLA::Axis axis, float angle);
44
  Mat4x4f rotation_Mat4x4f(CGLA::Axis axis, float angle);
45
 
45
 
46
  /// Create a translation matrix
46
  /// Create a translation matrix
47
  Mat4x4f translation_Mat4x4f(const Vec3f&);
47
  Mat4x4f translation_Mat4x4f(const Vec3f&);
48
 
48
 
49
  /// Create a scaling matrix.
49
  /// Create a scaling matrix.
50
  Mat4x4f scaling_Mat4x4f(const Vec3f&);
50
  Mat4x4f scaling_Mat4x4f(const Vec3f&);
-
 
51
    
-
 
52
    /// Creates a perspective projection similar to gluPerspective
-
 
53
    /// Description from gluPerspective: perspective_Mat4x4f specifies a viewing frustum into
-
 
54
    /// the world coordinate system. In general, the aspect ratio in perspective_Mat4x4f
-
 
55
    /// should match the aspect ratio of the associated viewport. For example, aspect = 2.0
-
 
56
    /// means the viewer's angle of view is twice as wide in x as it is in y. If the viewport
-
 
57
    /// is twice as wide as it is tall, it displays the image without distortion.
-
 
58
    Mat4x4f perspective_Mat4x4f(float fovy, float aspect, float zNear, float zFar);
-
 
59
    
-
 
60
    /// Creates a perspective matrix similar to glFrustum
-
 
61
    Mat4x4f frustum_Mat4x4f(float  	left,
-
 
62
                            float  	right,
-
 
63
                            float  	bottom,
-
 
64
                            float  	top,
-
 
65
                            float  	nearVal,
-
 
66
                            float  	farVal);
-
 
67
    
-
 
68
    /// Creates an orthographic projection matrix (similar to glOrtho)
-
 
69
    Mat4x4f ortho_Mat4x4f(float left,
-
 
70
                          float right,
-
 
71
                          float bottom,
-
 
72
                          float top,
-
 
73
                          float nearVal,
-
 
74
                          float farVal);
-
 
75
    
-
 
76
    /// Creates a 2D orthographic projection matrix (similar to gluOrtho2D)
-
 
77
    Mat4x4f ortho2D_Mat4x4f(float left, float right, float bottom, float top);
-
 
78
    
-
 
79
    /// Creates a view matrix similar to gluLookAt
-
 
80
    Mat4x4f lookAt_Mat4x4f(const Vec3f& eye, const Vec3f& at, const Vec3f& up);
51
 
81
 
52
  /// Create an identity matrix.
82
  /// Create an identity matrix.
53
  inline Mat4x4f identity_Mat4x4f()
83
  inline Mat4x4f identity_Mat4x4f()
54
    {
84
    {
55
      return Mat4x4f(Vec4f(1.0f,0.0f,0.0f,0.0f), 
85
      return Mat4x4f(Vec4f(1.0f,0.0f,0.0f,0.0f), 
56
		     Vec4f(0.0f,1.0f,0.0f,0.0f), 
86
		     Vec4f(0.0f,1.0f,0.0f,0.0f), 
57
		     Vec4f(0.0f,0.0f,1.0f,0.0f), 
87
		     Vec4f(0.0f,0.0f,1.0f,0.0f), 
58
		     Vec4f(0.0f,0.0f,0.0f,1.0f));
88
		     Vec4f(0.0f,0.0f,0.0f,1.0f));
59
    }
89
    }
60
 
90
 
61
  /** Compute inverse assuming that the upper-left 3x3 sub-matrix is
91
  /** Compute inverse assuming that the upper-left 3x3 sub-matrix is
62
      orthonormal (which is the case if the transformation is only
92
      orthonormal (which is the case if the transformation is only
63
      a concatenation of rotations and translations).
93
      a concatenation of rotations and translations).
64
  */
94
  */
65
  inline Mat4x4f invert_ortho(const Mat4x4f& m)
95
  inline Mat4x4f invert_ortho(const Mat4x4f& m)
66
  {
96
  {
67
    Vec3f rx(m[0][0], m[1][0], m[2][0]);
97
    Vec3f rx(m[0][0], m[1][0], m[2][0]);
68
    Vec3f ry(m[0][1], m[1][1], m[2][1]);
98
    Vec3f ry(m[0][1], m[1][1], m[2][1]);
69
    Vec3f rz(m[0][2], m[1][2], m[2][2]);
99
    Vec3f rz(m[0][2], m[1][2], m[2][2]);
70
    Vec3f t(m[0][3], m[1][3], m[2][3]);
100
    Vec3f t(m[0][3], m[1][3], m[2][3]);
71
 
101
 
72
    return Mat4x4f(Vec4f(rx, -dot(t, rx)),
102
    return Mat4x4f(Vec4f(rx, -dot(t, rx)),
73
		   Vec4f(ry, -dot(t, ry)),
103
		   Vec4f(ry, -dot(t, ry)),
74
		   Vec4f(rz, -dot(t, rz)),
104
		   Vec4f(rz, -dot(t, rz)),
75
		   Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
105
		   Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
76
  }   
106
  }
77
}
107
}
78
#endif
108
#endif
79
 
109
 
80
 
110
 
81
 
111
 
82
 
112
 
83
 
113
 
84
 
114
 
85
 
115
 
86
 
116