NGL  6.5
The NCCA Graphics Library
Mat4.cpp
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 #include "NGLassert.h"
18 #include "Mat4.h"
19 #include "Quaternion.h"
20 #include "Util.h"
21 #include "Vec3.h"
22 #include <iostream>
23 #include <cstring> // for memset
24 #include <algorithm>
25 
26 //----------------------------------------------------------------------------------------------------------------------
29 //----------------------------------------------------------------------------------------------------------------------
30 
31 
32 namespace ngl
33 {
34 
35 //----------------------------------------------------------------------------------------------------------------------
36 Mat4::Mat4() noexcept
37 {
38  memset(&m_m,0,sizeof(m_m));
39  m_00=1.0f;
40  m_11=1.0f;
41  m_22=1.0f;
42  m_33=1.0f;
43 }
44 
45 Mat4::Mat4(Real _m[4][4]) noexcept
46 {
47  for(int y=0; y<4; ++y)
48  {
49  for(int x=0; x<4; ++x)
50  {
51  m_m[y][x]=_m[y][x];
52  }
53  }
54 
55 }
56 
58  Real _00,Real _01,Real _02,Real _03,
59  Real _10,Real _11,Real _12,Real _13,
60  Real _20,Real _21,Real _22,Real _23,
61  Real _30, Real _31, Real _32, Real _33 ) noexcept
62 {
63  m_00=_00;
64  m_01=_01;
65  m_02=_02;
66  m_03=_03;
67 
68  m_10=_10;
69  m_11=_11;
70  m_12=_12;
71  m_13=_13;
72  m_20=_20;
73  m_21=_21;
74  m_22=_22;
75  m_23=_23;
76  m_30=_30;
77  m_31=_31;
78  m_32=_32;
79  m_33=_33;
80 }
81 //----------------------------------------------------------------------------------------------------------------------
82 Mat4::Mat4(const Mat4& _m ) noexcept
83 {
84  memcpy(m_m,&_m.m_m,sizeof(m_m));
85 }
86 //----------------------------------------------------------------------------------------------------------------------
87 Mat4& Mat4::operator=(const Mat4& _m ) noexcept
88 {
89  memcpy(m_m,&_m.m_m,sizeof(m_m));
90  return *this;
91 }
92 //----------------------------------------------------------------------------------------------------------------------
93 Mat4::Mat4(Real _m) noexcept
94 {
95  memset(m_m,0,sizeof(m_m));
96  m_00=_m;
97  m_11=_m;
98  m_22=_m;
99  m_33=1.0f;
100 }
101 //----------------------------------------------------------------------------------------------------------------------
103 void Mat4::setAtXY(GLint _x,GLint _y, Real _equals ) noexcept
104 {
105  m_m[_x][_y]=_equals;
106 }
107 //----------------------------------------------------------------------------------------------------------------------
108 const Mat4& Mat4::null() noexcept
109 {
110  memset(&m_m,0,sizeof(m_m));
111  return *this;
112 }
113 //----------------------------------------------------------------------------------------------------------------------
114 const Mat4& Mat4::identity() noexcept
115 {
116  memset(m_m,0,sizeof(m_m));
117  m_00=1.0f;
118  m_11=1.0f;
119  m_22=1.0f;
120  m_33=1.0f;
121  return *this;
122 }
123 
124 //----------------------------------------------------------------------------------------------------------------------
125 Mat4 Mat4::operator*(const Mat4& _m ) const noexcept
126 {
127  Mat4 temp;
128  // according to this http://www.research.scea.com/research/pdfs/GDC2003_Memory_Optimization_18Mar03.pdf
129  // we get better cache performance and less in the way of
130  // cache misses by prefectching the data using the consume / process pardigm
131  // not really tested this yet so will be interesting to do so
132 /*
133  ngl::Real m00=m_m[0][0];
134  ngl::Real m01=m_m[0][1];
135  ngl::Real m02=m_m[0][2];
136  ngl::Real m03=m_m[0][3];
137 
138  ngl::Real m10=m_m[1][0];
139  ngl::Real m11=m_m[1][1];
140  ngl::Real m12=m_m[1][2];
141  ngl::Real m13=m_m[1][3];
142 
143  ngl::Real m20=m_m[2][0];
144  ngl::Real m21=m_m[2][1];
145  ngl::Real m22=m_m[2][2];
146  ngl::Real m23=m_m[2][3];
147 
148  ngl::Real m30=m_m[3][0];
149  ngl::Real m31=m_m[3][1];
150  ngl::Real m32=m_m[3][2];
151  ngl::Real m33=m_m[3][3];
152 
153  ngl::Real b00=_m.m_m[0][0];
154  ngl::Real b01=_m.m_m[0][1];
155  ngl::Real b02=_m.m_m[0][2];
156  ngl::Real b03=_m.m_m[0][3];
157 
158  ngl::Real b10=_m.m_m[1][0];
159  ngl::Real b11=_m.m_m[1][1];
160  ngl::Real b12=_m.m_m[1][2];
161  ngl::Real b13=_m.m_m[1][3];
162 
163  ngl::Real b20=_m.m_m[2][0];
164  ngl::Real b21=_m.m_m[2][1];
165  ngl::Real b22=_m.m_m[2][2];
166  ngl::Real b23=_m.m_m[2][3];
167 
168  ngl::Real b30=_m.m_m[3][0];
169  ngl::Real b31=_m.m_m[3][1];
170  ngl::Real b32=_m.m_m[3][2];
171  ngl::Real b33=_m.m_m[3][3];
172 
173  temp.m_m[0][0] = m00 * b00 + m01 * b10 + m02 * b20 + m03 * b30;
174  temp.m_m[0][1] = m00 * b01 + m01 * b11 + m02 * b21 + m03 * b31;
175  temp.m_m[0][2] = m00 * _m.m_m[0][2] + m01 * b12 + m02 * b22 + m03 * b32;
176  temp.m_m[0][3] = m00 * b03 + m01 * b13 + m02 * b23 + m03 * b33;
177  temp.m_m[1][0] = m10 * b00 + m11 * b10 + m12 * b20 + m13 * b30;
178  temp.m_m[1][1] = m10 * b01 + m11 * b11 + m12 * b21 + m13 * b31;
179  temp.m_m[1][2] = m10 * _m.m_m[0][2] + m11 * b12 + m12 * b22 + m13 * b32;
180  temp.m_m[1][3] = m10 * b03 + m11 * b13 + m12 * b23 + m13 * b33;
181  temp.m_m[2][0] = m20 * b00 + m21 * b10 + m22 * b20 + m23 * b30;
182  temp.m_m[2][1] = m20 * b01 + m21 * b11 + m22 * b21 + m23 * b31;
183  temp.m_m[2][2] = m20 * _m.m_m[0][2] + m21 * b12 + m22 * b22 + m23 * b32;
184  temp.m_m[2][3] = m20 * b03 + m21 * b13 + m22 * b23 + m23 * b33;
185  temp.m_m[3][0] = m30 * b00 + m31 * b10 + m32 * b20 + m33 * b30;
186  temp.m_m[3][1] = m30 * b01 + m31 * b11 + m32 * b21 + m33 * b31;
187  temp.m_m[3][2] = m30 * _m.m_m[0][2] + m31 * b12 + m32 * b22 + m33 * b32;
188  temp.m_m[3][3] = m30 * b03 + m31 * b13 + m32 * b23 + m33 * b33;
189 */
190 // orignal
191 
192  temp.m_m[0][0] = m_m[0][0] * _m.m_m[0][0] + m_m[0][1] * _m.m_m[1][0] + m_m[0][2] * _m.m_m[2][0] + m_m[0][3] * _m.m_m[3][0];
193  temp.m_m[0][1] = m_m[0][0] * _m.m_m[0][1] + m_m[0][1] * _m.m_m[1][1] + m_m[0][2] * _m.m_m[2][1] + m_m[0][3] * _m.m_m[3][1];
194  temp.m_m[0][2] = m_m[0][0] * _m.m_m[0][2] + m_m[0][1] * _m.m_m[1][2] + m_m[0][2] * _m.m_m[2][2] + m_m[0][3] * _m.m_m[3][2];
195  temp.m_m[0][3] = m_m[0][0] * _m.m_m[0][3] + m_m[0][1] * _m.m_m[1][3] + m_m[0][2] * _m.m_m[2][3] + m_m[0][3] * _m.m_m[3][3];
196  temp.m_m[1][0] = m_m[1][0] * _m.m_m[0][0] + m_m[1][1] * _m.m_m[1][0] + m_m[1][2] * _m.m_m[2][0] + m_m[1][3] * _m.m_m[3][0];
197  temp.m_m[1][1] = m_m[1][0] * _m.m_m[0][1] + m_m[1][1] * _m.m_m[1][1] + m_m[1][2] * _m.m_m[2][1] + m_m[1][3] * _m.m_m[3][1];
198  temp.m_m[1][2] = m_m[1][0] * _m.m_m[0][2] + m_m[1][1] * _m.m_m[1][2] + m_m[1][2] * _m.m_m[2][2] + m_m[1][3] * _m.m_m[3][2];
199  temp.m_m[1][3] = m_m[1][0] * _m.m_m[0][3] + m_m[1][1] * _m.m_m[1][3] + m_m[1][2] * _m.m_m[2][3] + m_m[1][3] * _m.m_m[3][3];
200  temp.m_m[2][0] = m_m[2][0] * _m.m_m[0][0] + m_m[2][1] * _m.m_m[1][0] + m_m[2][2] * _m.m_m[2][0] + m_m[2][3] * _m.m_m[3][0];
201  temp.m_m[2][1] = m_m[2][0] * _m.m_m[0][1] + m_m[2][1] * _m.m_m[1][1] + m_m[2][2] * _m.m_m[2][1] + m_m[2][3] * _m.m_m[3][1];
202  temp.m_m[2][2] = m_m[2][0] * _m.m_m[0][2] + m_m[2][1] * _m.m_m[1][2] + m_m[2][2] * _m.m_m[2][2] + m_m[2][3] * _m.m_m[3][2];
203  temp.m_m[2][3] = m_m[2][0] * _m.m_m[0][3] + m_m[2][1] * _m.m_m[1][3] + m_m[2][2] * _m.m_m[2][3] + m_m[2][3] * _m.m_m[3][3];
204  temp.m_m[3][0] = m_m[3][0] * _m.m_m[0][0] + m_m[3][1] * _m.m_m[1][0] + m_m[3][2] * _m.m_m[2][0] + m_m[3][3] * _m.m_m[3][0];
205  temp.m_m[3][1] = m_m[3][0] * _m.m_m[0][1] + m_m[3][1] * _m.m_m[1][1] + m_m[3][2] * _m.m_m[2][1] + m_m[3][3] * _m.m_m[3][1];
206  temp.m_m[3][2] = m_m[3][0] * _m.m_m[0][2] + m_m[3][1] * _m.m_m[1][2] + m_m[3][2] * _m.m_m[2][2] + m_m[3][3] * _m.m_m[3][2];
207  temp.m_m[3][3] = m_m[3][0] * _m.m_m[0][3] + m_m[3][1] * _m.m_m[1][3] + m_m[3][2] * _m.m_m[2][3] + m_m[3][3] * _m.m_m[3][3];
208 
209  return temp;
210 }
211 
212 //----------------------------------------------------------------------------------------------------------------------
213 const Mat4& Mat4::operator*= ( const Mat4 &_m ) noexcept
214 {
215  Mat4 temp(*this);
216  // row 0
217  m_00 = temp.m_00 * _m.m_00;
218  m_01 = temp.m_01 * _m.m_00;
219  m_02 = temp.m_02 * _m.m_00;
220  m_03 = temp.m_03 * _m.m_00;
221 
222  m_00 += temp.m_10 * _m.m_01;
223  m_01 += temp.m_11 * _m.m_01;
224  m_02 += temp.m_12 * _m.m_01;
225  m_03 += temp.m_13 * _m.m_01;
226 
227  m_00 += temp.m_20 * _m.m_02;
228  m_01 += temp.m_21 * _m.m_02;
229  m_02 += temp.m_22 * _m.m_02;
230  m_03 += temp.m_23 * _m.m_02;
231 
232  m_00 += temp.m_30 * _m.m_03;
233  m_01 += temp.m_31 * _m.m_03;
234  m_02 += temp.m_32 * _m.m_03;
235  m_03 += temp.m_33 * _m.m_03;
236 
237 
238  // row 1
239  m_10 = temp.m_00 * _m.m_10;
240  m_11 = temp.m_01 * _m.m_10;
241  m_12 = temp.m_02 * _m.m_10;
242  m_13 = temp.m_03 * _m.m_10;
243 
244  m_10 += temp.m_10 * _m.m_11;
245  m_11 += temp.m_11 * _m.m_11;
246  m_12 += temp.m_12 * _m.m_11;
247  m_13 += temp.m_13 * _m.m_11;
248 
249  m_10 += temp.m_20 * _m.m_12;
250  m_11 += temp.m_21 * _m.m_12;
251  m_12 += temp.m_22 * _m.m_12;
252  m_13 += temp.m_23 * _m.m_12;
253 
254  m_10 += temp.m_30 * _m.m_13;
255  m_11 += temp.m_31 * _m.m_13;
256  m_12 += temp.m_32 * _m.m_13;
257  m_13 += temp.m_33 * _m.m_13;
258 
259 
260  // row 2
261  m_20 = temp.m_00 * _m.m_20;
262  m_21 = temp.m_01 * _m.m_20;
263  m_22 = temp.m_02 * _m.m_20;
264  m_23 = temp.m_03 * _m.m_20;
265 
266  m_20 += temp.m_10 * _m.m_21;
267  m_21 += temp.m_11 * _m.m_21;
268  m_22 += temp.m_12 * _m.m_21;
269  m_23 += temp.m_13 * _m.m_21;
270 
271  m_20 += temp.m_20 * _m.m_22;
272  m_21 += temp.m_21 * _m.m_22;
273  m_22 += temp.m_22 * _m.m_22;
274  m_23 += temp.m_23 * _m.m_22;
275 
276  m_20 += temp.m_30 * _m.m_23;
277  m_21 += temp.m_31 * _m.m_23;
278  m_22 += temp.m_32 * _m.m_23;
279  m_23 += temp.m_33 * _m.m_23;
280 
281 
282  // row 3
283  m_30 = temp.m_00 * _m.m_30;
284  m_31 = temp.m_01 * _m.m_30;
285  m_32 = temp.m_02 * _m.m_30;
286  m_33 = temp.m_03 * _m.m_30;
287 
288  m_30 += temp.m_10 * _m.m_31;
289  m_31 += temp.m_11 * _m.m_31;
290  m_32 += temp.m_12 * _m.m_31;
291  m_33 += temp.m_13 * _m.m_31;
292 
293  m_30 += temp.m_20 * _m.m_32;
294  m_31 += temp.m_21 * _m.m_32;
295  m_32 += temp.m_22 * _m.m_32;
296  m_33 += temp.m_23 * _m.m_32;
297 
298  m_30 += temp.m_30 * _m.m_33;
299  m_31 += temp.m_31 * _m.m_33;
300  m_32 += temp.m_32 * _m.m_33;
301  m_33 += temp.m_33 * _m.m_33;
302 
303  return *this;
304 }
305 
306 
307 //----------------------------------------------------------------------------------------------------------------------
308 Mat4 Mat4::operator+(const Mat4 &_m ) const noexcept
309 {
310  Mat4 ret;
311  const Real* iterA = &m_openGL[0];
312  const Real* iterB = &_m.m_openGL[0];
313  Real* iterR = &ret.m_openGL[0];
314  const Real* end = &m_openGL[16];
315 
316 
317  for( ; iterA != end; ++iterA, ++iterB, ++iterR)
318  {
319  *iterR = *iterA + *iterB;
320  }
321  return ret;
322 
323 /* this is one way of doing things with STL however speed is Average time: 15.457 us as
324  apposed to Average time: 6.847 us using the above version
325 Mat4 ret;
326 std::transform(std::begin(m_openGL), std::end(m_openGL),
327  std::begin(_m.m_openGL), std::begin(ret.m_openGL),
328  std::plus<Real>());
329 
330 return ret;
331 */
332 }
333 //----------------------------------------------------------------------------------------------------------------------
334 const Mat4& Mat4::operator+=(const Mat4 &_m) noexcept
335 {
336  Real* iterA =&m_openGL[0];
337  const Real* iterB = &_m.m_openGL[0];
338  const Real* end = &m_openGL[16];
339 
340  for( ; iterA != end; ++iterA, ++iterB)
341  {
342  *iterA += *iterB;
343  }
344  return *this;
345 }
346 //----------------------------------------------------------------------------------------------------------------------
347 Mat4 Mat4::operator*( const Real _i) const noexcept
348 {
349  Mat4 ret;
350  const Real* iterA = &m_openGL[0];
351  Real* iterB = &ret.m_openGL[0];
352  const Real* end = &m_openGL[16];
353 
354  for( ; iterA != end; ++iterA, ++iterB)
355  {
356  *iterB = (*iterA) * _i;
357  }
358  return ret;
359 }
360 
361 //----------------------------------------------------------------------------------------------------------------------
362 const Mat4& Mat4::operator*=(const Real _i) noexcept
363 {
364  for(int y=0; y<4; y++)
365  {
366  for(int x=0; x<4; x++)
367  {
368  m_m[y][x]*=_i;
369  }
370  }
371  return *this;
372 }
373 
374 //----------------------------------------------------------------------------------------------------------------------
375 Vec4 Mat4::operator * (const Vec4 &_v ) const noexcept
376 {
377  Vec4 temp;
378 
379  temp.m_x=_v.m_x * m_00 + _v.m_y * m_01 + _v.m_z * m_02 + _v.m_w * m_03;
380  temp.m_y=_v.m_x * m_10 + _v.m_y * m_11 + _v.m_z * m_12 + _v.m_w * m_13;
381  temp.m_z=_v.m_x * m_20 + _v.m_y * m_21 + _v.m_z * m_22 + _v.m_w * m_23;
382  temp.m_w=_v.m_x * m_30 + _v.m_y * m_31 + _v.m_z * m_32 + _v.m_w * m_33;
383 
384 return temp;
385 }
386 
387 
388 //----------------------------------------------------------------------------------------------------------------------
389 const Mat4& Mat4::transpose() noexcept
390 {
391  Mat4 tmp(*this);
392 
393  for(int row=0; row<4; row++)
394  {
395  for(int col=0; col<4; col++)
396  {
397  m_m[row][col]=tmp.m_m[col][row];
398  }
399  }
400  return *this;
401 }
402 
403 
404 
405 //----------------------------------------------------------------------------------------------------------------------
406 void Mat4::rotateX( const Real _deg) noexcept
407 {
408  Real beta=radians(_deg);
409  Real sr = sinf( beta );
410  Real cr = cosf( beta );
411  m_11 = cr;
412  m_21 = -sr;
413  m_12 = sr;
414  m_22 = cr;
415 }
416 
417 //----------------------------------------------------------------------------------------------------------------------
418 void Mat4::rotateY( const Real _deg ) noexcept
419 {
420  Real beta=radians(_deg);
421  Real sr = sinf( beta );
422  Real cr = cosf( beta );
423  m_00 = cr;
424  m_20 = sr;
425  m_02 = -sr;
426  m_22 = cr;
427 }
428 
429 //----------------------------------------------------------------------------------------------------------------------
430 void Mat4::rotateZ(const Real _deg ) noexcept
431 {
432  Real beta=radians(_deg);
433  Real sr = sinf( beta );
434  Real cr = cosf( beta );
435  m_00 = cr;
436  m_10 = -sr;
437  m_01 = sr;
438  m_11 = cr;
439 }
440 
441 //----------------------------------------------------------------------------------------------------------------------
442 void Mat4::translate( const Real _x,const Real _y, const Real _z ) noexcept
443 {
444  m_30 = _x;
445  m_31 = _y;
446  m_32 = _z;
447 }
448 
449 //----------------------------------------------------------------------------------------------------------------------
450 void Mat4::scale(const Real _x, const Real _y, const Real _z ) noexcept
451 {
452  m_00 = _x;
453  m_11 = _y;
454  m_22 = _z;
455 }
456 
457 //----------------------------------------------------------------------------------------------------------------------
458 void Mat4::subMatrix3x3(const int _i, const int _j, Real o_mat[] ) const noexcept
459 {
460  int ti, tj, idst=0, jdst=0;
461 
462  for ( ti = 0; ti != 4; ++ti )
463  {
464  if ( ti < _i )
465  {
466  idst = ti;
467  }
468  else
469  {
470  if ( ti > _i )
471  {
472  idst = ti-1;
473  }
474 
475  for ( tj = 0; tj != 4; ++tj )
476  {
477  if ( tj < _j )
478  {
479  jdst = tj;
480  }
481  else if ( tj > _j )
482  {
483  jdst = tj-1;
484  }
485  if ( ti != _i && tj != _j )
486  {
487  o_mat[idst*3 + jdst] = m_openGL[ti*4 + tj];
488  }
489  }
490  } // end else
491  }// end for
492 }
493 //----------------------------------------------------------------------------------------------------------------------
494 Real Mat4::determinant() const noexcept
495 {
496  // Our matrices are 4.4 only, so we can just write the full formula instead of a complex algorithm.
497  return (
498  m_m[0][0]*m_m[1][1]*m_m[2][2]*m_m[3][3] - m_m[0][0]*m_m[1][1]*m_m[2][3]*m_m[3][2] + m_m[0][0]*m_m[1][2]*m_m[2][3]*m_m[3][1] - m_m[0][0]*m_m[1][2]*m_m[2][1]*m_m[3][3] + m_m[0][0]*m_m[1][3]*m_m[2][1]*m_m[3][2] - m_m[0][0]*m_m[1][3]*m_m[2][2]*m_m[3][1]
499  - m_m[1][0]*m_m[2][1]*m_m[3][2]*m_m[0][3] + m_m[1][0]*m_m[2][1]*m_m[0][2]*m_m[3][3] - m_m[1][0]*m_m[3][1]*m_m[0][2]*m_m[2][3] + m_m[1][0]*m_m[3][1]*m_m[2][2]*m_m[0][3] - m_m[1][0]*m_m[0][1]*m_m[2][2]*m_m[3][3] + m_m[1][0]*m_m[0][1]*m_m[3][2]*m_m[2][3]
500  + m_m[2][0]*m_m[3][1]*m_m[0][2]*m_m[1][3] - m_m[2][0]*m_m[3][1]*m_m[1][2]*m_m[0][3] + m_m[2][0]*m_m[0][1]*m_m[1][2]*m_m[3][3] - m_m[2][0]*m_m[0][1]*m_m[3][2]*m_m[1][3] + m_m[2][0]*m_m[1][1]*m_m[3][2]*m_m[0][3] - m_m[2][0]*m_m[1][1]*m_m[0][2]*m_m[3][3]
501  - m_m[3][0]*m_m[0][1]*m_m[1][2]*m_m[2][3] + m_m[3][0]*m_m[0][1]*m_m[2][2]*m_m[1][3] - m_m[3][0]*m_m[1][1]*m_m[2][2]*m_m[0][3] + m_m[3][0]*m_m[1][1]*m_m[0][2]*m_m[2][3] - m_m[3][0]*m_m[2][1]*m_m[0][2]*m_m[1][3] + m_m[3][0]*m_m[2][1]*m_m[1][2]*m_m[0][3]
502  );
503 }
504 
505 
506 
507 
508 
509 
510 
511 //----------------------------------------------------------------------------------------------------------------------
512 void Mat4::euler(const Real _angle, const Real _x, const Real _y, const Real _z) noexcept
513 {
514  // Axis and Angle matrix rotation see
515  // http://en.wikipedia.org/wiki/Rotation_matrix for more details
516  Real beta=radians(-_angle);
517  Real cosTheta = cosf((beta));
518  Real sinTheta = sinf((beta));
519  Real OneMinusCosTheta=1.0f-cosTheta;
520  ngl::Vec3 norm(_x,_y,_z);
521  norm.normalize();
522  Real x=norm.m_x;
523  Real y=norm.m_y;
524  Real z=norm.m_z;
525 
526 
527  m_m[0][0]=OneMinusCosTheta*(x*x)+cosTheta;
528  m_m[0][1]=OneMinusCosTheta*(x*y)-(z*sinTheta);
529  m_m[0][2]=OneMinusCosTheta*(x*z)+(y*sinTheta);
530 // m_m[1][0]=xyC+zs;
531 // m_m[1][1]=_y*yC+cosTheta;
532 // m_m[1][2]= yzC-xs;
533  m_m[1][0]=OneMinusCosTheta*(x*y)+(z*sinTheta);
534  m_m[1][1]=OneMinusCosTheta*(y*y)+cosTheta;
535  m_m[1][2]=OneMinusCosTheta*(y*z)-(x*sinTheta);
536 
537 
538 // m_m[2][0]=zxC-ys;
539 // m_m[2][1]=yzC+xs;
540 // m_m[2][2]=_z*zC+cosTheta;
541 
542  m_m[2][0]=OneMinusCosTheta*(x*z)-(y*sinTheta);
543  m_m[2][1]=OneMinusCosTheta*(y*z)+(x*sinTheta);
544  m_m[2][2]=OneMinusCosTheta*(z*z)+cosTheta;
545 }
546 
547 void Mat4::as3x3Array(Real _d[9]) const noexcept
548 {
549  _d[0]=m_m[0][0];
550  _d[1]=m_m[1][0];
551  _d[2]=m_m[2][0];
552 
553  _d[3]=m_m[0][1];
554  _d[4]=m_m[1][1];
555  _d[5]=m_m[2][1];
556 
557  _d[6]=m_m[0][2];
558  _d[7]=m_m[1][2];
559  _d[8]=m_m[2][2];
560 }
561 
562 //----------------------------------------------------------------------------------------------------------------------
564 {
565  // calculate trace of the matrix
566  Real T = m_openGL[0] + m_openGL[5] + m_openGL[10] + 1;
567 
568  // if trace is greater than 0, calculate an instant calculation
569  if( T > 0 )
570  {
571  Real S = static_cast<Real>( 0.5f / sqrtf(T) );
572  return Quaternion( static_cast<Real>( ( m_openGL[6] - m_openGL[9] ) * S),
573  static_cast<Real>( ( m_openGL[8] - m_openGL[2] ) * S),
574  static_cast<Real>( ( m_openGL[1] - m_openGL[4] ) * S),
575  static_cast<Real>( 0.25f / S)
576  );
577  }
578  Real BigF = m_openGL[0];
579  unsigned char check=0;
580  if( m_openGL[5] > BigF )
581  {
582  check = 1;
583  BigF = m_openGL[5];
584  }
585  if( m_openGL[10] > BigF )
586  {
587  check = 2;
588  //BigF = m_openGL[10];
589  }
590  switch(check)
591  {
592  case 0:
593  {
594  Real S = static_cast<Real>( sqrtf( 1.0f + m_openGL[0] - m_openGL[5] - m_openGL[10] ) * 2.0f );
595 
596  return Quaternion( 0.5f / S,
597  (m_openGL[1] + m_openGL[4] ) / S,
598  (m_openGL[2] + m_openGL[8] ) / S,
599  (m_openGL[6] + m_openGL[9] ) / S );
600  }
601  case 1:
602  {
603  Real S = static_cast<Real>( sqrtf( 1.0f + m_openGL[5] - m_openGL[0] - m_openGL[10] ) * 2.0f );
604 
605  return Quaternion((m_openGL[1] + m_openGL[4] ) / S,
606  0.5f / S,
607  (m_openGL[6] + m_openGL[9] ) / S,
608  (m_openGL[2] + m_openGL[8] ) / S );
609  }
610  case 2:
611  {
612  Real S = static_cast<Real>( sqrtf( 1.0f + m_openGL[10] - m_openGL[0] - m_openGL[5] ) * 2.0f );
613 
614  return Quaternion((m_openGL[2] + m_openGL[8] ) / S,
615  (m_openGL[6] + m_openGL[9] ) / S,
616  0.5f / S,
617  (m_openGL[1] + m_openGL[4] ) / S );
618  }
619  default:
620  {
621  NGL_ASSERT(0 && "SHOULDN'T GET HERE in ngl Quaternion");
622  break;
623  }
624  }// end switch
625  return Quaternion();
626 
627 }
628 //----------------------------------------------------------------------------------------------------------------------
629 
630 Mat4 Mat4::Adjacent( const Mat4 &_mat) noexcept
631 {
632  Mat4 m;
633 
634  m.m_00 = _mat.m_m[1][1]*(_mat.m_m[2][2]*_mat.m_m[3][3]-_mat.m_m[3][2]*_mat.m_m[2][3])+_mat.m_m[1][2]*(_mat.m_m[3][1]*_mat.m_m[2][3]-_mat.m_m[2][1]*_mat.m_m[3][3])+_mat.m_m[1][3]*(_mat.m_m[2][1]*_mat.m_m[3][2]-_mat.m_m[3][1]*_mat.m_m[2][2]);
635  m.m_01 = _mat.m_m[1][0]*(_mat.m_m[3][2]*_mat.m_m[2][3]-_mat.m_m[2][2]*_mat.m_m[3][3])+_mat.m_m[1][2]*(_mat.m_m[2][0]*_mat.m_m[3][3]-_mat.m_m[3][0]*_mat.m_m[2][3])+_mat.m_m[1][3]*(_mat.m_m[3][0]*_mat.m_m[2][2]-_mat.m_m[2][0]*_mat.m_m[3][2]);
636  m.m_02 = _mat.m_m[1][0]*(_mat.m_m[2][1]*_mat.m_m[3][3]-_mat.m_m[3][1]*_mat.m_m[2][3])+_mat.m_m[1][1]*(_mat.m_m[3][0]*_mat.m_m[2][3]-_mat.m_m[2][0]*_mat.m_m[3][3])+_mat.m_m[1][3]*(_mat.m_m[2][0]*_mat.m_m[3][1]-_mat.m_m[3][0]*_mat.m_m[2][1]);
637  m.m_03 = _mat.m_m[1][0]*(_mat.m_m[3][1]*_mat.m_m[2][2]-_mat.m_m[2][1]*_mat.m_m[3][2])+_mat.m_m[1][1]*(_mat.m_m[2][0]*_mat.m_m[3][2]-_mat.m_m[3][0]*_mat.m_m[2][2])+_mat.m_m[1][2]*(_mat.m_m[3][0]*_mat.m_m[2][1]-_mat.m_m[2][0]*_mat.m_m[3][1]);
638 
639  m.m_10 = _mat.m_m[0][1]*(_mat.m_m[3][2]*_mat.m_m[2][3]-_mat.m_m[2][2]*_mat.m_m[3][3])+_mat.m_m[0][2]*(_mat.m_m[2][1]*_mat.m_m[3][3]-_mat.m_m[3][1]*_mat.m_m[2][3])+_mat.m_m[0][3]*(_mat.m_m[3][1]*_mat.m_m[2][2]-_mat.m_m[2][1]*_mat.m_m[3][2]);
640  m.m_11 = _mat.m_m[0][0]*(_mat.m_m[2][2]*_mat.m_m[3][3]-_mat.m_m[3][2]*_mat.m_m[2][3])+_mat.m_m[0][2]*(_mat.m_m[3][0]*_mat.m_m[2][3]-_mat.m_m[2][0]*_mat.m_m[3][3])+_mat.m_m[0][3]*(_mat.m_m[2][0]*_mat.m_m[3][2]-_mat.m_m[3][0]*_mat.m_m[2][2]);
641  m.m_12 = _mat.m_m[0][0]*(_mat.m_m[3][1]*_mat.m_m[2][3]-_mat.m_m[2][1]*_mat.m_m[3][3])+_mat.m_m[0][1]*(_mat.m_m[2][0]*_mat.m_m[3][3]-_mat.m_m[3][0]*_mat.m_m[2][3])+_mat.m_m[0][3]*(_mat.m_m[3][0]*_mat.m_m[2][1]-_mat.m_m[2][0]*_mat.m_m[3][1]);
642  m.m_13= _mat.m_m[0][0]*(_mat.m_m[2][1]*_mat.m_m[3][2]-_mat.m_m[3][1]*_mat.m_m[2][2])+_mat.m_m[0][1]*(_mat.m_m[3][0]*_mat.m_m[2][2]-_mat.m_m[2][0]*_mat.m_m[3][2])+_mat.m_m[0][2]*(_mat.m_m[2][0]*_mat.m_m[3][1]-_mat.m_m[3][0]*_mat.m_m[2][1]);
643 
644  m.m_20 = _mat.m_m[0][1]*(_mat.m_m[1][2]*_mat.m_m[3][3]-_mat.m_m[3][2]*_mat.m_m[1][3])+_mat.m_m[0][2]*(_mat.m_m[3][1]*_mat.m_m[1][3]-_mat.m_m[1][1]*_mat.m_m[3][3])+_mat.m_m[0][3]*(_mat.m_m[1][1]*_mat.m_m[3][2]-_mat.m_m[3][1]*_mat.m_m[1][2]);
645  m.m_21 = _mat.m_m[0][0]*(_mat.m_m[3][2]*_mat.m_m[1][3]-_mat.m_m[1][2]*_mat.m_m[3][3])+_mat.m_m[0][2]*(_mat.m_m[1][0]*_mat.m_m[3][3]-_mat.m_m[3][0]*_mat.m_m[1][3])+_mat.m_m[0][3]*(_mat.m_m[3][0]*_mat.m_m[1][2]-_mat.m_m[1][0]*_mat.m_m[3][2]);
646  m.m_22 = _mat.m_m[0][0]*(_mat.m_m[1][1]*_mat.m_m[3][3]-_mat.m_m[3][1]*_mat.m_m[1][3])+_mat.m_m[0][1]*(_mat.m_m[3][0]*_mat.m_m[1][3]-_mat.m_m[1][0]*_mat.m_m[3][3])+_mat.m_m[0][3]*(_mat.m_m[1][0]*_mat.m_m[3][1]-_mat.m_m[3][0]*_mat.m_m[1][1]);
647  m.m_23 = _mat.m_m[0][0]*(_mat.m_m[3][1]*_mat.m_m[1][2]-_mat.m_m[1][1]*_mat.m_m[3][2])+_mat.m_m[0][1]*(_mat.m_m[1][0]*_mat.m_m[3][2]-_mat.m_m[3][0]*_mat.m_m[1][2])+_mat.m_m[0][2]*(_mat.m_m[3][0]*_mat.m_m[1][1]-_mat.m_m[1][0]*_mat.m_m[3][1]);
648 
649  m.m_30 = _mat.m_m[0][1]*(_mat.m_m[2][2]*_mat.m_m[1][3]-_mat.m_m[1][2]*_mat.m_m[2][3])+_mat.m_m[0][2]*(_mat.m_m[1][1]*_mat.m_m[2][3]-_mat.m_m[2][1]*_mat.m_m[1][3])+_mat.m_m[0][3]*(_mat.m_m[2][1]*_mat.m_m[1][2]-_mat.m_m[1][1]*_mat.m_m[2][2]);
650  m.m_31 = _mat.m_m[0][0]*(_mat.m_m[1][2]*_mat.m_m[2][3]-_mat.m_m[2][2]*_mat.m_m[1][3])+_mat.m_m[0][2]*(_mat.m_m[2][0]*_mat.m_m[1][3]-_mat.m_m[1][0]*_mat.m_m[2][3])+_mat.m_m[0][3]*(_mat.m_m[1][0]*_mat.m_m[2][2]-_mat.m_m[2][0]*_mat.m_m[1][2]);
651  m.m_32 = _mat.m_m[0][0]*(_mat.m_m[2][1]*_mat.m_m[1][3]-_mat.m_m[1][1]*_mat.m_m[2][3])+_mat.m_m[0][1]*(_mat.m_m[1][0]*_mat.m_m[2][3]-_mat.m_m[2][0]*_mat.m_m[1][3])+_mat.m_m[0][3]*(_mat.m_m[2][0]*_mat.m_m[1][1]-_mat.m_m[1][0]*_mat.m_m[2][1]);
652  m.m_33 = _mat.m_m[0][0]*(_mat.m_m[1][1]*_mat.m_m[2][2]-_mat.m_m[2][1]*_mat.m_m[1][2])+_mat.m_m[0][1]*(_mat.m_m[2][0]*_mat.m_m[1][2]-_mat.m_m[1][0]*_mat.m_m[2][2])+_mat.m_m[0][2]*(_mat.m_m[1][0]*_mat.m_m[2][1]-_mat.m_m[2][0]*_mat.m_m[1][1]);
653 
654  return m;
655 }
656 
658 {
659  Mat4 m;
660 
661  m.m_00 = m_m[1][1]*(m_m[2][2]*m_m[3][3]-m_m[3][2]*m_m[2][3])+m_m[1][2]*(m_m[3][1]*m_m[2][3]-m_m[2][1]*m_m[3][3])+m_m[1][3]*(m_m[2][1]*m_m[3][2]-m_m[3][1]*m_m[2][2]);
662  m.m_01 = m_m[1][0]*(m_m[3][2]*m_m[2][3]-m_m[2][2]*m_m[3][3])+m_m[1][2]*(m_m[2][0]*m_m[3][3]-m_m[3][0]*m_m[2][3])+m_m[1][3]*(m_m[3][0]*m_m[2][2]-m_m[2][0]*m_m[3][2]);
663  m.m_02 = m_m[1][0]*(m_m[2][1]*m_m[3][3]-m_m[3][1]*m_m[2][3])+m_m[1][1]*(m_m[3][0]*m_m[2][3]-m_m[2][0]*m_m[3][3])+m_m[1][3]*(m_m[2][0]*m_m[3][1]-m_m[3][0]*m_m[2][1]);
664  m.m_03 = m_m[1][0]*(m_m[3][1]*m_m[2][2]-m_m[2][1]*m_m[3][2])+m_m[1][1]*(m_m[2][0]*m_m[3][2]-m_m[3][0]*m_m[2][2])+m_m[1][2]*(m_m[3][0]*m_m[2][1]-m_m[2][0]*m_m[3][1]);
665 
666  m.m_10 = m_m[0][1]*(m_m[3][2]*m_m[2][3]-m_m[2][2]*m_m[3][3])+m_m[0][2]*(m_m[2][1]*m_m[3][3]-m_m[3][1]*m_m[2][3])+m_m[0][3]*(m_m[3][1]*m_m[2][2]-m_m[2][1]*m_m[3][2]);
667  m.m_11 = m_m[0][0]*(m_m[2][2]*m_m[3][3]-m_m[3][2]*m_m[2][3])+m_m[0][2]*(m_m[3][0]*m_m[2][3]-m_m[2][0]*m_m[3][3])+m_m[0][3]*(m_m[2][0]*m_m[3][2]-m_m[3][0]*m_m[2][2]);
668  m.m_12 = m_m[0][0]*(m_m[3][1]*m_m[2][3]-m_m[2][1]*m_m[3][3])+m_m[0][1]*(m_m[2][0]*m_m[3][3]-m_m[3][0]*m_m[2][3])+m_m[0][3]*(m_m[3][0]*m_m[2][1]-m_m[2][0]*m_m[3][1]);
669  m.m_13= m_m[0][0]*(m_m[2][1]*m_m[3][2]-m_m[3][1]*m_m[2][2])+m_m[0][1]*(m_m[3][0]*m_m[2][2]-m_m[2][0]*m_m[3][2])+m_m[0][2]*(m_m[2][0]*m_m[3][1]-m_m[3][0]*m_m[2][1]);
670 
671  m.m_20 = m_m[0][1]*(m_m[1][2]*m_m[3][3]-m_m[3][2]*m_m[1][3])+m_m[0][2]*(m_m[3][1]*m_m[1][3]-m_m[1][1]*m_m[3][3])+m_m[0][3]*(m_m[1][1]*m_m[3][2]-m_m[3][1]*m_m[1][2]);
672  m.m_21 = m_m[0][0]*(m_m[3][2]*m_m[1][3]-m_m[1][2]*m_m[3][3])+m_m[0][2]*(m_m[1][0]*m_m[3][3]-m_m[3][0]*m_m[1][3])+m_m[0][3]*(m_m[3][0]*m_m[1][2]-m_m[1][0]*m_m[3][2]);
673  m.m_22 = m_m[0][0]*(m_m[1][1]*m_m[3][3]-m_m[3][1]*m_m[1][3])+m_m[0][1]*(m_m[3][0]*m_m[1][3]-m_m[1][0]*m_m[3][3])+m_m[0][3]*(m_m[1][0]*m_m[3][1]-m_m[3][0]*m_m[1][1]);
674  m.m_23 = m_m[0][0]*(m_m[3][1]*m_m[1][2]-m_m[1][1]*m_m[3][2])+m_m[0][1]*(m_m[1][0]*m_m[3][2]-m_m[3][0]*m_m[1][2])+m_m[0][2]*(m_m[3][0]*m_m[1][1]-m_m[1][0]*m_m[3][1]);
675 
676  m.m_30 = m_m[0][1]*(m_m[2][2]*m_m[1][3]-m_m[1][2]*m_m[2][3])+m_m[0][2]*(m_m[1][1]*m_m[2][3]-m_m[2][1]*m_m[1][3])+m_m[0][3]*(m_m[2][1]*m_m[1][2]-m_m[1][1]*m_m[2][2]);
677  m.m_31 = m_m[0][0]*(m_m[1][2]*m_m[2][3]-m_m[2][2]*m_m[1][3])+m_m[0][2]*(m_m[2][0]*m_m[1][3]-m_m[1][0]*m_m[2][3])+m_m[0][3]*(m_m[1][0]*m_m[2][2]-m_m[2][0]*m_m[1][2]);
678  m.m_32 = m_m[0][0]*(m_m[2][1]*m_m[1][3]-m_m[1][1]*m_m[2][3])+m_m[0][1]*(m_m[1][0]*m_m[2][3]-m_m[2][0]*m_m[1][3])+m_m[0][3]*(m_m[2][0]*m_m[1][1]-m_m[1][0]*m_m[2][1]);
679  m.m_33 = m_m[0][0]*(m_m[1][1]*m_m[2][2]-m_m[2][1]*m_m[1][2])+m_m[0][1]*(m_m[2][0]*m_m[1][2]-m_m[1][0]*m_m[2][2])+m_m[0][2]*(m_m[1][0]*m_m[2][1]-m_m[2][0]*m_m[1][1]);
680 
681  return m;
682 }
683 
684 Mat4 Mat4::inverse() noexcept
685 {
686 
687 
688  Mat4 t;
690  t.m_01 = m_01*m_23*m_32 + m_02*m_21*m_33 + m_03*m_22*m_31 - m_01*m_22*m_33 - m_02*m_23*m_31 - m_03*m_21*m_32;
691  t.m_02 = m_01*m_12*m_33 + m_02*m_13*m_31 + m_03*m_11*m_32 - m_01*m_13*m_32 - m_02*m_11*m_33 - m_03*m_12*m_31;
693  t.m_10 = m_10*m_23*m_32 + m_12*m_20*m_33 + m_13*m_22*m_30 - m_10*m_22*m_33 - m_12*m_23*m_30 - m_13*m_20*m_32;
694  t.m_11 = m_00*m_22*m_33 + m_02*m_23*m_30 + m_03*m_20*m_32 - m_00*m_23*m_32 - m_02*m_20*m_33 - m_03*m_22*m_30;
695  t.m_12 = m_00*m_13*m_32 + m_02*m_10*m_33 + m_03*m_12*m_30 - m_00*m_12*m_33 - m_02*m_13*m_30 - m_03*m_10*m_32;
696  t.m_13 = m_00*m_12*m_23 + m_02*m_13*m_20 + m_03*m_10*m_22 - m_00*m_13*m_22 - m_02*m_10*m_23 - m_03*m_12*m_20;
697  t.m_20 = m_10*m_21*m_33 + m_11*m_23*m_30 + m_13*m_20*m_31 - m_10*m_23*m_31 - m_11*m_20*m_33 - m_13*m_21*m_30;
698  t.m_21 = m_00*m_23*m_31 + m_01*m_20*m_33 + m_03*m_21*m_30 - m_00*m_21*m_33 - m_01*m_23*m_30 - m_03*m_20*m_31;
699  t.m_22 = m_00*m_11*m_33 + m_01*m_13*m_30 + m_03*m_10*m_31 - m_00*m_13*m_31 - m_01*m_10*m_33 - m_03*m_11*m_30;
700  t.m_23 = m_00*m_13*m_21 + m_01*m_10*m_23 + m_03*m_11*m_20 - m_00*m_11*m_23 - m_01*m_13*m_20 - m_03*m_10*m_21;
701  t.m_30 = m_10*m_22*m_31 + m_11*m_20*m_32 + m_12*m_21*m_30 - m_10*m_21*m_32 - m_11*m_22*m_30 - m_12*m_20*m_31;
702  t.m_31 = m_00*m_21*m_32 + m_01*m_22*m_30 + m_02*m_20*m_31 - m_00*m_22*m_31 - m_01*m_20*m_32 - m_02*m_21*m_30;
703  t.m_32 = m_00*m_12*m_31 + m_01*m_10*m_32 + m_02*m_11*m_30 - m_00*m_11*m_32 - m_01*m_12*m_30 - m_02*m_10*m_31;
704  t.m_33 = m_00*m_11*m_22 + m_01*m_12*m_20 + m_02*m_10*m_21 - m_00*m_12*m_21 - m_01*m_10*m_22 - m_02*m_11*m_20;
705 
706 
707  auto det = determinant();
708  det = 1.0f/det;
709  return t*det;
710 
711 
712 }
713 
714 //----------------------------------------------------------------------------------------------------------------------
715 Vec3 Mat4::getLeftVector() const noexcept
716 {
717  return Vec3(-m_openGL[0],-m_openGL[1],-m_openGL[2]);
718 }
719 //----------------------------------------------------------------------------------------------------------------------
720 Vec3 Mat4::getRightVector() const noexcept
721 {
722  return Vec3( m_openGL[0],m_openGL[1],m_openGL[2]);
723 
724 }
725 //----------------------------------------------------------------------------------------------------------------------
726 Vec3 Mat4::getUpVector() const noexcept
727 {
728  return Vec3(m_openGL[4],m_openGL[5],m_openGL[6]);
729 
730 }
731 
732 //----------------------------------------------------------------------------------------------------------------------
733 Vec3 Mat4::getDownVector() const noexcept
734 {
735  return Vec3(-m_openGL[4],-m_openGL[5],-m_openGL[6]);
736 
737 }
738 //----------------------------------------------------------------------------------------------------------------------
739 Vec3 Mat4::getForwardVector() const noexcept
740 {
741  return Vec3(-m_openGL[8],-m_openGL[9],-m_openGL[10]);
742 }
743 //----------------------------------------------------------------------------------------------------------------------
744 
745 Vec3 Mat4::getBackVector() const noexcept
746 {
747  return Vec3(m_openGL[8],m_openGL[9],m_openGL[10]);
748 
749 }
750 
751 
752 
753 } // end namespace ngl
754 
755 
756 
Mat4 Adjacent() noexcept
returns the ajacent matrix to this
Definition: Mat4.cpp:657
some useful definitions and functions
GLdouble GLdouble z
Definition: glew.h:1562
Vec3 getBackVector() const noexcept
get the back vector of the matrix ( 3nd Row)
Definition: Mat4.cpp:745
const Mat4 & operator+=(const Mat4 &_m) noexcept
+= operator
Definition: Mat4.cpp:334
Real m_11
individual matrix element maps to m_m[1][1] or m_openGL[5]
Definition: Mat4.h:316
Real m_21
individual matrix element maps to m_m[2][1] or m_openGL[9]
Definition: Mat4.h:320
void as3x3Array(Real _d[9]) const noexcept
return the data as a 3x3 matrix
Definition: Mat4.cpp:547
simple Vector class for OpenGL graphics, contains overloaded operators for most math functions...
Definition: Vec4.h:57
const Mat4 & null() noexcept
clear the matrix to all 0
Definition: Mat4.cpp:108
friend class Quaternion
Definition: Mat4.h:285
Real m_22
individual matrix element maps to m_m[2][2] or m_openGL[10]
Definition: Mat4.h:321
const Mat4 & transpose() noexcept
method to transpose the matrix
Definition: Mat4.cpp:389
Mat4 operator*(const Mat4 &_m) const noexcept
operator for matrix multiplication
Definition: Mat4.cpp:125
void euler(const Real _angle, const Real _x, const Real _y, const Real _z) noexcept
axis / angle rotation using the Euler method
Definition: Mat4.cpp:512
Real m_12
individual matrix element maps to m_m[1][2] or m_openGL[6]
Definition: Mat4.h:317
Real m_31
individual matrix element maps to m_m[3][1] or m_openGL[13]
Definition: Mat4.h:324
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1255
Real m_m[4][4]
matrix element m_m as a 4x4 array mapped by union to m_nn elements and m_openGL
Definition: Mat4.h:295
Vec3 getDownVector() const noexcept
get the down vector of the matrix ( -ve 2nd Row)
Definition: Mat4.cpp:733
GLdouble GLdouble t
Definition: glew.h:1401
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
Mat4 & operator=(const Mat4 &_m) noexcept
assignment operator
Definition: Mat4.cpp:87
Real determinant() const noexcept
get the determinant of the matrix
Definition: Mat4.cpp:494
Real m_30
individual matrix element maps to m_m[3][0] or m_openGL[12]
Definition: Mat4.h:323
void rotateZ(const Real _deg) noexcept
set this matrix to a rotation matrix in the Z axis for value _deg note the matrix should be set to id...
Definition: Mat4.cpp:430
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Definition: Types.h:127
Real m_02
individual matrix element maps to m_m[0][2] or m_openGL[2]
Definition: Mat4.h:313
Vec3 getRightVector() const noexcept
get the right vector of the matrix ( 1nd Row)
Definition: Mat4.cpp:720
void scale(const Real _x, const Real _y, const Real _z) noexcept
set the matrix scale values
Definition: Mat4.cpp:450
Real m_y
y component
Definition: Vec3.h:311
void setAtXY(GLint _x, GLint _y, Real _equals) noexcept
set the value at m_m[_x][_y] to _equals
Definition: Mat4.cpp:103
void rotateY(const Real _deg) noexcept
set this matrix to a rotation matrix in the Y axis for value _deg note the matrix should be set to id...
Definition: Mat4.cpp:418
GLuint GLuint end
Definition: glew.h:1256
void rotateX(const Real _deg) noexcept
set this matrix to a rotation matrix in the X axis for value _deg note the matrix should be set to id...
Definition: Mat4.cpp:406
a simple 3 tuple container for compatibility with glsl
Real m_z
z component
Definition: Vec4.h:323
Real m_01
individual matrix element maps to m_m[0][1] or m_openGL[1]
Definition: Mat4.h:312
Real m_00
individual matrix element maps to m_m[0][0] or m_openGL[0]
Definition: Mat4.h:311
const Mat4 & identity() noexcept
make the matrix m the identity matrix 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
Definition: Mat4.cpp:114
Real m_x
x component
Definition: Vec3.h:310
Real m_10
individual matrix element maps to m_m[1][0] or m_openGL[4]
Definition: Mat4.h:315
Mat4 inverse() noexcept
get the inverse of the matrix
Definition: Mat4.cpp:684
Defines the class Quaternion based on John Vinces lecture notes basically we have a scalar part and t...
const Mat4 & operator*=(const Mat4 &_m) noexcept
operator to mult this matrix by value _m
Definition: Mat4.cpp:213
Real m_13
individual matrix element maps to m_m[1][3] or m_openGL[7]
Definition: Mat4.h:318
Real m_23
individual matrix element maps to m_m[2][3] or m_openGL[11]
Definition: Mat4.h:322
Real m_x
x component
Definition: Vec4.h:321
Quaternion asQuaternion() const noexcept
convert this matrix to a Quaternion
Definition: Mat4.cpp:563
Mat4 operator+(const Mat4 &_m) const noexcept
operator to add two matrices together
Definition: Mat4.cpp:308
void translate(const Real _x, const Real _y, const Real _z) noexcept
set the matrix as a translation matrix
Definition: Mat4.cpp:442
GLint GLint GLint GLint GLint x
Definition: glew.h:1255
#define NGL_ASSERT(X)
re-define the standard assert to work for ngl first check to see if assert is defined and undef it th...
Definition: NGLassert.h:53
Vec3 getUpVector() const noexcept
get the up vector of the matrix (2nd Row)
Definition: Mat4.cpp:726
GLenum GLenum void * row
Definition: glew.h:4993
Real m_32
individual matrix element maps to m_m[3][2] or m_openGL[14]
Definition: Mat4.h:325
NGL_DLLEXPORT Real radians(const Real _deg)
converts Degrees to Radians
Definition: Util.cpp:89
const GLdouble * m
Definition: glew.h:9164
Matrix Class to do simple matrix operations included operator overloaded functions for maths and matr...
Definition: Mat4.h:58
Vec3 getForwardVector() const noexcept
get the forward vector of the matrix (-ve 3rd Row)
Definition: Mat4.cpp:739
int GLint
Definition: glew.h:281
std::array< Real, 16 > m_openGL
The matrix in m_openGL 16 Real array format usefull for OpenGL fv formats mapped to m_m[][] elements ...
Definition: Mat4.h:300
Real m_20
individual matrix element maps to m_m[2][0] or m_openGL[8]
Definition: Mat4.h:319
Real m_w
w component 0 for vector 1 for point
Definition: Vec4.h:324
void subMatrix3x3(const int _i, const int _j, Real o_mat[]) const noexcept
get a sub 3x3 matrix used in determinant and Inverse calculations
Definition: Mat4.cpp:458
Real m_03
individual matrix element maps to m_m[0][3] or m_openGL[3]
Definition: Mat4.h:314
Real m_y
y component
Definition: Vec4.h:322
Mat4() noexcept
ctor will always create an identity matrix
Definition: Mat4.cpp:36
void normalize() noexcept
Normalize the vector using .
Definition: Vec3.cpp:206
re impliment asserts so we don&#39;t exit on failure
Vec3 getLeftVector() const noexcept
get the left vector of the matrix (-ve 1st Row)
Definition: Mat4.cpp:715
Real m_33
individual matrix element maps to m_m[3][3] or m_openGL[15]
Definition: Mat4.h:326
Real m_z
z component
Definition: Vec3.h:312
GLclampf f
Definition: glew.h:3511