NGL  6.5
The NCCA Graphics Library
Mat3.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Jon Macey
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef MAT3_H_
18 #define MAT3_H_
19 //----------------------------------------------------------------------------------------------------------------------
22 //----------------------------------------------------------------------------------------------------------------------
23 // must include types.h first for Real and GLEW if required
24 #include "Types.h"
25 #include <array>
26 #include <ostream>
27 
28 namespace ngl
29 {
30 class Quaternion;
31 class Mat4;
32 class Vec3;
33 
34 //----------------------------------------------------------------------------------------------------------------------
40 //----------------------------------------------------------------------------------------------------------------------
41 
42 
44 {
45  // added after clang++ build
46 public:
47 
48  //----------------------------------------------------------------------------------------------------------------------
50  //----------------------------------------------------------------------------------------------------------------------
51  Mat3() noexcept;
52  //----------------------------------------------------------------------------------------------------------------------
54  //----------------------------------------------------------------------------------------------------------------------
55  Mat3(Real _00,Real _01,Real _02,Real _10,Real _11,Real _12,Real _20,Real _21,Real _22) noexcept;
56  //----------------------------------------------------------------------------------------------------------------------
58  //----------------------------------------------------------------------------------------------------------------------
59  Mat3( const Mat4 &_m ) noexcept;
60 
61  //----------------------------------------------------------------------------------------------------------------------
63  //----------------------------------------------------------------------------------------------------------------------
64  Mat3( const Mat3& _m ) noexcept;
65  //----------------------------------------------------------------------------------------------------------------------
67  //----------------------------------------------------------------------------------------------------------------------
68  Mat3( const Real _m ) noexcept;
69 
70  //----------------------------------------------------------------------------------------------------------------------
75  //----------------------------------------------------------------------------------------------------------------------
76  void setAtXY( GLint _x,GLint _y,Real _equals ) noexcept;
77 
78  //----------------------------------------------------------------------------------------------------------------------
80  //----------------------------------------------------------------------------------------------------------------------
81  const Mat3& null() noexcept;
82 
83  //----------------------------------------------------------------------------------------------------------------------
89  //----------------------------------------------------------------------------------------------------------------------
90  const Mat3& identity() noexcept;
91  //----------------------------------------------------------------------------------------------------------------------
95  //----------------------------------------------------------------------------------------------------------------------
96  Mat3 operator*( const Mat3 &_m ) const noexcept;
97  //----------------------------------------------------------------------------------------------------------------------
101  //----------------------------------------------------------------------------------------------------------------------
102  const Mat3& operator*=( const Mat3 &_m ) noexcept;
103  //----------------------------------------------------------------------------------------------------------------------
107  //----------------------------------------------------------------------------------------------------------------------
108  Mat3 operator+( const Mat3 &_m ) const noexcept;
109  //----------------------------------------------------------------------------------------------------------------------
113  //----------------------------------------------------------------------------------------------------------------------
114  const Mat3& operator+=( const Mat3 &_m ) noexcept;
115  //----------------------------------------------------------------------------------------------------------------------
119  //----------------------------------------------------------------------------------------------------------------------
120  Mat3 operator*( Real _i ) const noexcept;
121  //----------------------------------------------------------------------------------------------------------------------
125  //----------------------------------------------------------------------------------------------------------------------
126  const Mat3& operator*=( Real _i ) noexcept;
127  //----------------------------------------------------------------------------------------------------------------------
131  //----------------------------------------------------------------------------------------------------------------------
132  Vec3 operator * ( const Vec3 &_v ) const noexcept;
133  //----------------------------------------------------------------------------------------------------------------------
135  //----------------------------------------------------------------------------------------------------------------------
136  const Mat3& transpose() noexcept;
137 
138  //----------------------------------------------------------------------------------------------------------------------
142  //----------------------------------------------------------------------------------------------------------------------
143  void rotateX( Real _deg) noexcept;
144  //----------------------------------------------------------------------------------------------------------------------
148  //----------------------------------------------------------------------------------------------------------------------
149  void rotateY(Real _deg) noexcept;
150 
151  //----------------------------------------------------------------------------------------------------------------------
155  //----------------------------------------------------------------------------------------------------------------------
156  void rotateZ( Real _deg ) noexcept;
157  //----------------------------------------------------------------------------------------------------------------------
162  //----------------------------------------------------------------------------------------------------------------------
163  void scale( Real _x, Real _y, Real _z ) noexcept;
164 
165  //----------------------------------------------------------------------------------------------------------------------
168  //----------------------------------------------------------------------------------------------------------------------
169  Real determinant() const noexcept;
170 
171  //----------------------------------------------------------------------------------------------------------------------
173  //----------------------------------------------------------------------------------------------------------------------
174  Mat3 inverse() noexcept;
175 
176  //----------------------------------------------------------------------------------------------------------------------
182  //----------------------------------------------------------------------------------------------------------------------
183  void euler( Real _angle, Real _x, Real _y, Real _z) noexcept;
184  //----------------------------------------------------------------------------------------------------------------------
187  //----------------------------------------------------------------------------------------------------------------------
188  Real * openGL() noexcept{return &m_openGL[0];}
189  //----------------------------------------------------------------------------------------------------------------------
192  //----------------------------------------------------------------------------------------------------------------------
193  Vec3 getLeftVector() const noexcept;
194  //----------------------------------------------------------------------------------------------------------------------
197  //----------------------------------------------------------------------------------------------------------------------
198  Vec3 getRightVector() const noexcept;
199  //----------------------------------------------------------------------------------------------------------------------
202  //----------------------------------------------------------------------------------------------------------------------
203  Vec3 getUpVector() const noexcept;
204  //----------------------------------------------------------------------------------------------------------------------
207  //----------------------------------------------------------------------------------------------------------------------
208  Vec3 getDownVector() const noexcept;
209  //----------------------------------------------------------------------------------------------------------------------
212  //----------------------------------------------------------------------------------------------------------------------
213  Vec3 getForwardVector() const noexcept;
214  //----------------------------------------------------------------------------------------------------------------------
217  //----------------------------------------------------------------------------------------------------------------------
218  Vec3 getBackVector() const noexcept;
219 
220 public :
221  //----------------------------------------------------------------------------------------------------------------------
222  // allow access to some of the other classes
223  friend class Transformation;
224  friend class Quaternion;
225  friend class Camera;
226  //----------------------------------------------------------------------------------------------------------------------
227 
228 #ifndef BUILDING_DOCS
229 #pragma pack(push,1)
230 
231  union
232  {
233 #endif
234  //----------------------------------------------------------------------------------------------------------------------
236  //----------------------------------------------------------------------------------------------------------------------
237  Real m_m[3][3];
238  //----------------------------------------------------------------------------------------------------------------------
241  //----------------------------------------------------------------------------------------------------------------------
242  //Real m_openGL[9];
243  std::array<Real,9> m_openGL={{
244  1.0f,0.0f,0.0f,
245  0.0f,1.0f,0.0f,
246  0.0f,0.0f,1.0f
247  }};
248 #ifndef BUILDING_DOCS
249 
250  struct
251  {
252 #endif
253  //----------------------------------------------------------------------------------------------------------------------
255  //----------------------------------------------------------------------------------------------------------------------
257  //----------------------------------------------------------------------------------------------------------------------
259  //----------------------------------------------------------------------------------------------------------------------
261  //----------------------------------------------------------------------------------------------------------------------
263  //----------------------------------------------------------------------------------------------------------------------
265  //----------------------------------------------------------------------------------------------------------------------
267  //----------------------------------------------------------------------------------------------------------------------
269  //----------------------------------------------------------------------------------------------------------------------
271  //----------------------------------------------------------------------------------------------------------------------
273  //----------------------------------------------------------------------------------------------------------------------
275  //----------------------------------------------------------------------------------------------------------------------
277  //----------------------------------------------------------------------------------------------------------------------
279  //----------------------------------------------------------------------------------------------------------------------
281  //----------------------------------------------------------------------------------------------------------------------
283  //----------------------------------------------------------------------------------------------------------------------
285  //----------------------------------------------------------------------------------------------------------------------
287  //----------------------------------------------------------------------------------------------------------------------
289  #ifndef BUILDING_DOCS
290  };
291 #pragma pack(pop)
292 
293  };
294 #endif
295  }; // end of class
296 // free function for matrix comparison use in unit tests etc
297 inline bool operator==(const ngl::Mat3 &_m1 , const ngl::Mat3 &_m2)
298 {
299  for(size_t i=0; i<_m1.m_openGL.size(); ++i)
300  {
301  if(!( FCompare(_m1.m_openGL[i] , _m2.m_openGL[i] )))
302  {
303  return false;
304  }
305  }
306  return true;
307 }
308 }// end of namespace
309 
310 #endif
311 //----------------------------------------------------------------------------------------------------------------------
312 
bool operator==(const ngl::Mat3 &_m1, const ngl::Mat3 &_m2)
Definition: Mat3.h:297
Mat3 basic 3x3 matrix for certain glsl ops.
Definition: Mat3.h:43
GLsizei GLboolean transpose
Definition: glew.h:1867
Real m_00
individual matrix element maps to m_m[0][0] or m_openGL[0]
Definition: Mat3.h:256
GLenum GLenum GLenum GLenum GLenum scale
Definition: glew.h:14161
main definition of types and namespace
Real m_12
individual matrix element maps to m_m[1][2] or m_openGL[6]
Definition: Mat3.h:276
#define NGL_DLLEXPORT
Definition: Types.h:65
std::array< Real, 9 > m_openGL
The matrix in m_openGL 16 Real array format usefull for OpenGL fv formats mapped to m_m[][] elements ...
Definition: Mat3.h:243
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
Definition: Vec3.h:51
implementation files for RibExport class
Definition: AABB.cpp:22
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
#define FCompare(a, b)
FCompare macro used for floating point comparision functions.
Definition: Types.h:136
simple camera class to allow movement in an opengl scene. a lot of this stuff is from the HILL book C...
Definition: Camera.h:54
Real m_11
individual matrix element maps to m_m[1][1] or m_openGL[5]
Definition: Mat3.h:272
Real * openGL() noexcept
accesor to the openGL matrix
Definition: Mat3.h:188
Real m_10
individual matrix element maps to m_m[1][0] or m_openGL[4]
Definition: Mat3.h:268
Vec2 operator*(Real _k, const Vec2 &_v) noexcept
scalar * vector operator
Definition: Vec2.h:286
Real m_20
individual matrix element maps to m_m[2][0] or m_openGL[8]
Definition: Mat3.h:280
Transformation describes a transformation (translate, scale, rotation) modifed by j macey and include...
Real m_21
individual matrix element maps to m_m[2][1] or m_openGL[9]
Definition: Mat3.h:284
Matrix Class to do simple matrix operations included operator overloaded functions for maths and matr...
Definition: Mat4.h:58
int GLint
Definition: glew.h:281
Real m_02
individual matrix element maps to m_m[0][2] or m_openGL[2]
Definition: Mat3.h:264
Real m_01
individual matrix element maps to m_m[0][1] or m_openGL[1]
Definition: Mat3.h:260
Real m_22
individual matrix element maps to m_m[2][2] or m_openGL[10]
Definition: Mat3.h:288