vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gm_mat3.h
Go to the documentation of this file.
1 // gmMatrix3.h - 3x3 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_MATRIX3_H
12 #define GM_MATRIX3_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 gmVector2;
22 class gmVector3;
23 
24 class gmMatrix3 {
25 
26 protected:
27  double m_[3][3];
28 
29 public:
30  gmMatrix3();
31  gmMatrix3(const gmMatrix3&);
32  gmMatrix3(double, double, double,
33  double, double, double,
34  double, double, double);
35 
36  // array access
37 
38  double* operator [](int);
39  const double* operator [](int) const;
40 
41  // assignment
42 
43  gmMatrix3& assign(double, double, double,
44  double, double, double,
45  double, double, double);
46  gmMatrix3& operator =(const gmMatrix3&);
47 
48  // operators
49 
50  gmMatrix3& operator +=(const gmMatrix3&);
51  gmMatrix3& operator -=(const gmMatrix3&);
52  gmMatrix3& operator *=(const gmMatrix3&);
53  gmMatrix3& operator *=(double);
54  gmMatrix3& operator /=(double);
55 
56  gmMatrix3 operator +(const gmMatrix3&) const;
57  gmMatrix3 operator -(const gmMatrix3&) const;
58  gmMatrix3 operator -() const;
59  gmMatrix3 operator *(const gmMatrix3&) const;
60  gmMatrix3 operator *(double) const;
61  gmMatrix3 operator /(double) const;
62 
63 friend gmMatrix3 operator *(double, const gmMatrix3&);
64 
65  bool operator ==(const gmMatrix3&) const;
66  bool operator !=(const gmMatrix3&) const;
67 
68  gmVector3 operator *(const gmVector3&) const;
69 
70 friend gmVector3 operator *(const gmVector3&, const gmMatrix3&);
71 
72  // output
73 
74 friend ostream & operator << ( ostream &, const gmMatrix3&);
75 
76  // operations
77 
78  gmMatrix3 inverse() const;
79  gmMatrix3 transpose() const;
80  gmMatrix3 adjoint() const;
81 
82  double determinant() const;
83  bool isSingular() const;
84 
85  gmVector2 transform(const gmVector2&) const;
86 
87  void copyTo(float [3][3]) const;
88  void copyTo(double [3][3]) const;
89 
90  // transformation matrices
91 
92  static gmMatrix3 identity();
93  static gmMatrix3 scale(double, double);
94  static gmMatrix3 translate(double, double);
95  static gmMatrix3 rotate(double);
96  static gmMatrix3 arb_rotate(gmVector3&, double); // arbitrary axis rotation matrix
97 };
98 
99 // ARRAY ACCESS
100 
101 inline double* gmMatrix3::operator [](int i)
102 {
103  assert(i == 0 || i == 1 || i == 2 || i == 3);
104  return &m_[i][0];
105 }
106 
107 inline const double* gmMatrix3::operator [](int i) const
108 {
109  assert(i == 0 || i == 1 || i == 2 || i == 3);
110  return &m_[i][0];
111 }
112 
113 inline void gmMatrix3::copyTo(float f[3][3]) const
114 {
115  f[0][0] = m_[0][0]; f[0][1] = m_[0][1]; f[0][2] = m_[0][2];
116  f[1][0] = m_[1][0]; f[1][1] = m_[1][1]; f[1][2] = m_[1][2];
117  f[2][0] = m_[2][0]; f[2][1] = m_[2][1]; f[2][2] = m_[2][2];
118 }
119 
120 inline void gmMatrix3::copyTo(double f[3][3]) const
121 {
122  f[0][0] = m_[0][0]; f[0][1] = m_[0][1]; f[0][2] = m_[0][2];
123  f[1][0] = m_[1][0]; f[1][1] = m_[1][1]; f[1][2] = m_[1][2];
124  f[2][0] = m_[2][0]; f[2][1] = m_[2][1]; f[2][2] = m_[2][2];
125 }
126 
127 #endif
128 
129