vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gm_mat4.h
Go to the documentation of this file.
1 // gmMatrix4.h - 4x4 element matrix class
2 //
3 // libgm++: Graphics Math Library
4 // Ferdi Scheepers and Stephen F May
5 // 15 June 1994
6 // ----------------------------------
7 // modified: October 2002
8 // Pavel Kolcarek, kolcarek@fi.muni.cz
9 //
10 
11 #ifndef GM_MATRIX4_H
12 #define GM_MATRIX4_H
13 
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <assert.h>
17 #include <gm_utils.h>
18 
19 using namespace std;
20 
21 class gmVector3;
22 class gmVector4;
23 
24 class gmMatrix4 {
25 
26 protected:
27  double m_[4][4];
28 
29 public:
30  gmMatrix4();
31  gmMatrix4(const gmMatrix4&);
32  gmMatrix4(double, double, double, double,
33  double, double, double, double,
34  double, double, double, double,
35  double, double, double, double);
36 
37  // array access
38 
39  double* operator [](int);
40  const double* operator [](int) const;
41 
42  // assignment
43 
44  gmMatrix4& assign(double, double, double, double,
45  double, double, double, double,
46  double, double, double, double,
47  double, double, double, double);
48  gmMatrix4& operator =(const gmMatrix4&);
49 
50  // operators
51 
52  gmMatrix4& operator +=(const gmMatrix4&);
53  gmMatrix4& operator -=(const gmMatrix4&);
54  gmMatrix4& operator *=(const gmMatrix4&);
55  gmMatrix4& operator *=(double);
56  gmMatrix4& operator /=(double);
57 
58  gmMatrix4 operator +(const gmMatrix4&) const;
59  gmMatrix4 operator -(const gmMatrix4&) const;
60  gmMatrix4 operator -() const;
61  gmMatrix4 operator *(const gmMatrix4&) const;
62  gmMatrix4 operator *(double) const;
63  gmMatrix4 operator /(double) const;
64 
65 friend gmMatrix4 operator *(double, const gmMatrix4&);
66 
67  bool operator ==(const gmMatrix4&) const;
68  bool operator !=(const gmMatrix4&) const;
69 
70  gmVector4 operator *(const gmVector4&) const;
71 
72 friend gmVector4 operator *(const gmVector4&, const gmMatrix4&);
73 
74  // mixed multiplying: vector3 = matrix4x4 * vector3 (double is for missing
75  // fourth vector element).
76  gmVector3 mixed_mult(gmVector3&, const double&);
77 
78  // output
79 
80 friend ostream & operator << (ostream &, const gmMatrix4&);
81 
82  // operations
83 
84  gmMatrix4 inverse() const;
85  gmMatrix4 transpose() const;
86  gmMatrix4 adjoint() const;
87 
88  double determinant() const;
89  bool isSingular() const;
90 
91  gmVector3 transform(const gmVector3&) const;
92 
93  void copyTo(float [4][4]) const;
94  void copyTo(double [4][4]) const;
95 
96  // transformation matrices
97 
98  static gmMatrix4 identity();
99  static gmMatrix4 rotate(double, const gmVector3& axis);
100  static gmMatrix4 scale(double, double, double);
101  static gmMatrix4 translate(double, double, double);
102  static gmMatrix4 arb_rotate(gmVector3&, double); // arbitrary axis rotation matrix
103 
104  // cubic basis matrices
105 
106  static gmMatrix4 bezierBasis();
107  static gmMatrix4 bsplineBasis();
108  static gmMatrix4 catmullromBasis();
109  static gmMatrix4 hermiteBasis();
110 
111  static gmMatrix4 tensedBSplineBasis(double);
112  static gmMatrix4 cardinalBasis(double);
113  static gmMatrix4 tauBasis(double, double);
114  static gmMatrix4 betaSplineBasis(double, double);
115 
116 };
117 
118 // ARRAY ACCESS
119 
120 inline double* gmMatrix4::operator [](int i)
121 {
122  assert(i == 0 || i == 1 || i == 2 || i == 3);
123  return &m_[i][0];
124 }
125 
126 inline const double* gmMatrix4::operator [](int i) const
127 {
128  assert(i == 0 || i == 1 || i == 2 || i == 3);
129  return &m_[i][0];
130 }
131 
132 inline void gmMatrix4::copyTo(float f[4][4]) const
133 {
134  f[0][0] = m_[0][0]; f[0][1] = m_[0][1];
135  f[0][2] = m_[0][2]; f[0][3] = m_[0][3];
136  f[1][0] = m_[1][0]; f[1][1] = m_[1][1];
137  f[1][2] = m_[1][2]; f[1][3] = m_[1][3];
138  f[2][0] = m_[2][0]; f[2][1] = m_[2][1];
139  f[2][2] = m_[2][2]; f[2][3] = m_[2][3];
140  f[3][0] = m_[3][0]; f[3][1] = m_[3][1];
141  f[3][2] = m_[3][2]; f[3][3] = m_[3][3];
142 }
143 
144 inline void gmMatrix4::copyTo(double f[4][4]) const
145 {
146  f[0][0] = m_[0][0]; f[0][1] = m_[0][1];
147  f[0][2] = m_[0][2]; f[0][3] = m_[0][3];
148  f[1][0] = m_[1][0]; f[1][1] = m_[1][1];
149  f[1][2] = m_[1][2]; f[1][3] = m_[1][3];
150  f[2][0] = m_[2][0]; f[2][1] = m_[2][1];
151  f[2][2] = m_[2][2]; f[2][3] = m_[2][3];
152  f[3][0] = m_[3][0]; f[3][1] = m_[3][1];
153  f[3][2] = m_[3][2]; f[3][3] = m_[3][3];
154 }
155 
156 #endif // GMMATRIX4_H
157 
158