OGLplus (0.52.0) a C++ wrapper for OpenGL

matrix.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #ifndef OGLPLUS_MATRIX_1107121519_HPP
14 #define OGLPLUS_MATRIX_1107121519_HPP
15 
16 #include <oglplus/config/compiler.hpp>
17 #include <oglplus/math/vector.hpp>
18 #include <oglplus/math/angle.hpp>
20 
21 #if !OGLPLUS_NO_INITIALIZER_LISTS
22 #include <initializer_list>
23 #endif
24 
25 #include <algorithm>
26 
27 #include <cassert>
28 #include <cstddef>
29 #include <cmath>
30 
31 namespace oglplus {
32 
33 template <typename T, std::size_t Rows, std::size_t Cols>
34 class Matrix;
35 
36 #if OGLPLUS_DOCUMENTATION_ONLY || defined(GL_FLOAT)
37 
42 
44 
48 
50 
54 
56 
60 
62 
66 
68 
72 
74 
78 
80 
84 
86 
90 #endif
91 
92 #if OGLPLUS_DOCUMENTATION_ONLY || defined(GL_DOUBLE)
93 
98 
100 
104 
106 
110 
112 
116 
118 
122 
124 
128 
130 
134 
136 
140 
142 
146 #endif
147 
148 namespace aux {
149 struct Matrix_spec_ctr_tag { };
150 } // namespace aux
151 
153 template <typename T, std::size_t Rows, std::size_t Cols>
154 class Matrix
155 {
156 protected:
157  union {
158  T _data[Rows * Cols];
159  T _elem[Rows][Cols];
160  } _m;
161 
162  typedef aux::Matrix_spec_ctr_tag _spec_ctr;
163 
164  struct _op_negate
165  {
166  const Matrix& a;
167 
168  void operator()(Matrix& t) const
169  {
170  for(std::size_t i=0; i!=Rows; ++i)
171  for(std::size_t j=0; j!=Cols; ++j)
172  t._m._elem[i][j] = -a._m._elem[i][j];
173  }
174  };
175 
176  struct _op_add
177  {
178  const Matrix& a;
179  const Matrix& b;
180 
181  void operator()(Matrix& t) const
182  {
183  for(std::size_t i=0; i!=Rows; ++i)
184  for(std::size_t j=0; j!=Cols; ++j)
185  t._m._elem[i][j] =
186  a._m._elem[i][j]+
187  b._m._elem[i][j];
188  }
189  };
190 
191  struct _op_subtract
192  {
193  const Matrix& a;
194  const Matrix& b;
195 
196  void operator()(Matrix& t) const
197  {
198  for(std::size_t i=0; i!=Rows; ++i)
199  for(std::size_t j=0; j!=Cols; ++j)
200  t._m._elem[i][j] =
201  a._m._elem[i][j]-
202  b._m._elem[i][j];
203  }
204  };
205 
206  template <std::size_t N>
207  struct _op_multiply
208  {
209  const Matrix<T, Rows, N>& a;
210  const Matrix<T, N, Cols>& b;
211 
212  void operator()(Matrix& t) const
213  {
214  for(std::size_t i=0; i!=Rows; ++i)
215  for(std::size_t j=0; j!=Cols; ++j)
216  {
217  t._m._elem[i][j] = a.At(i, 0)* b.At(0, j);
218  for(std::size_t k=1; k!=N; ++k)
219  {
220  t._m._elem[i][j] +=
221  a.At(i, k)*
222  b.At(k, j);
223  }
224  }
225  }
226  };
227 
228  struct _op_mult_c
229  {
230  void operator()(
231  Matrix& t,
232  const Matrix& a,
233  const T& v
234  )
235  {
236  for(std::size_t i=0; i!=Rows; ++i)
237  for(std::size_t j=0; j!=Cols; ++j)
238  t._m._elem[i][j] = a._m._elem[i][j] * v;
239  }
240  };
241 
242  struct _op_transpose
243  {
244  const Matrix<T, Cols, Rows>& a;
245 
246  void operator()(Matrix& t) const
247  {
248  for(std::size_t i=0; i!=Rows; ++i)
249  for(std::size_t j=0; j!=Cols; ++j)
250  t._m._elem[i][j] = a._m._elem[j][i];
251  }
252  };
253 
254  template <std::size_t I, std::size_t J, std::size_t R, std::size_t C>
255  struct _op_extract
256  {
257  const Matrix& a;
258 
259  void operator()(Matrix<T, R, C>& t) const
260  {
261  static_assert(
262  I+R<= Rows,
263  "Invalid row for this matrix type"
264  );
265  static_assert(
266  J+C<= Cols ,
267  "Invalid column for this matrix type"
268  );
269  for(std::size_t i=0; i!=R; ++i)
270  for(std::size_t j=0; j!=C; ++j)
271  t.Set(i, j, a.At(I+i, J+j));
272  }
273  };
274 
275  template <typename U, std::size_t R, std::size_t C>
276  struct _op_copy
277  {
278  const Matrix<U, R, C>& a;
279 
280  void operator()(Matrix& t) const
281  {
282  static_assert(
283  Rows <= R,
284  "Invalid row for this matrix type"
285  );
286  static_assert(
287  Cols <= C ,
288  "Invalid column for this matrix type"
289  );
290  for(std::size_t i=0; i!=Rows; ++i)
291  for(std::size_t j=0; j!=Cols; ++j)
292  t._m._elem[i][j] = T(a.At(i, j));
293  }
294  };
295 
296  void _init_row(std::size_t r, const T* data, std::size_t cols)
297  {
298  assert(cols == Cols);
299  std::copy(data, data+cols, _m._elem[r]);
300  }
301 
302  void _init_row(std::size_t r, const Vector<T, Cols>& row)
303  {
304  std::copy(row.Data(), row.Data()+Cols, _m._elem[r]);
305  }
306 
307  // No initialization
308  Matrix(oglplus::Nothing)
309  { }
310 
311 public:
312  template <typename InitOp>
313  explicit Matrix(_spec_ctr, InitOp& init)
314  {
315  init(*this);
316  }
317 
319  Matrix(void)
320  {
321  std::fill(_m._data, _m._data+Rows*Cols, T(0));
322  for(std::size_t i=0, n=Rows<Cols?Rows:Cols; i!=n; ++i)
323  this->_m._elem[i][i] = T(1);
324  }
325 
327  Matrix(const T* data, std::size_t n)
328  {
329  std::copy(data, data+n, _m._data);
330  }
331 
333  explicit Matrix(const T (&data)[Rows*Cols])
334  {
335  std::copy(data, data+Rows*Cols, _m._data);
336  }
337 
338 #if !OGLPLUS_NO_DEFAULTED_FUNCTIONS
339  Matrix(const Matrix&) = default;
340  Matrix& operator = (const Matrix&) = default;
341 #endif
342 
343  template <typename U, std::size_t R, std::size_t C>
344  explicit Matrix(const Matrix<U, R, C>& other)
345  {
346  _op_copy<U, R, C> init = {other};
347  init(*this);
348  }
349 
350 #if OGLPLUS_DOCUMENTATION_ONLY
351 
357  template <typename ... P>
358  explicit Matrix(P ... p);
359 
361 
367  template <typename ... C>
368  explicit Matrix(const Vector<T, C> ... row);
369 #elif !OGLPLUS_NO_VARIADIC_TEMPLATES && !OGLPLUS_NO_UNIFIED_INITIALIZATION_SYNTAX
370 
371 #include <oglplus/math/matrix_n_ctr.ipp>
372 
373 #else
374 
375 #include <oglplus/math/matrix_2_ctr.ipp>
376 #include <oglplus/math/matrix_3_ctr.ipp>
377 #include <oglplus/math/matrix_4_ctr.ipp>
378 
379 #endif
380 
381  void Fill(T value)
382  {
383  std::fill(_m._data, _m._data+Rows*Cols, value);
384  }
385 
387  const T* Data(void) const
388  {
389  return this->_m._data;
390  }
391 
393  std::size_t Size(void) const
394  {
395  return Rows * Cols;
396  }
397 
398 #if OGLPLUS_DOCUMENTATION_ONLY
399  friend const T* Data(const Matrix& matrix);
401 
403  friend std::size_t Size(const Matrix& matrix);
404 
406  friend std::size_t Rows(const Matrix& matrix);
407 
409  friend std::size_t Cols(const Matrix& matrix);
410 #endif
411 
413 
416  T At(std::size_t i, std::size_t j) const
417  {
418  assert((i < Rows) && (j < Cols));
419  return this->_m._elem[i][j];
420  }
421 
423 
426  void Set(std::size_t i, std::size_t j, T v)
427  {
428  assert((i < Rows) && (j < Cols));
429  this->_m._elem[i][j] = v;
430  }
431 
433 
436  Vector<T, Cols> Row(std::size_t i) const
437  {
438  assert(i < Rows);
439  return Vector<T, Cols>(this->_m._elem[i], Cols);
440  }
441 
443 
446  Vector<T, Rows> Col(std::size_t j) const
447  {
448  assert(j < Cols);
449  T v[Rows];
450  for(std::size_t i=0; i!= Rows; ++i)
451  v[i] = this->_m._elem[i][j];
452  return Vector<T, Rows>(v, Rows);
453  }
454 
456  friend bool Equal(const Matrix& a, const Matrix& b)
457  {
458  for(std::size_t i=0; i!=Rows; ++i)
459  for(std::size_t j=0; j!=Cols; ++j)
460  if(a._m._elem[i][j] != b._m._elem[i][j])
461  return false;
462  return true;
463  }
464 
466  friend bool operator == (const Matrix& a, const Matrix& b)
467  {
468  return Equal(a, b);
469  }
470 
472  friend bool operator != (const Matrix& a, const Matrix& b)
473  {
474  return !Equal(a, b);
475  }
476 
478  friend Matrix Negated(const Matrix& a)
479  {
480  _op_negate init = {a};
481  return Matrix(_spec_ctr(), init);
482  }
483 
485  friend Matrix operator - (const Matrix& a)
486  {
487  return Negated(a);
488  }
489 
491  friend Matrix Added(const Matrix& a, const Matrix& b)
492  {
493  _op_add init = {a, b};
494  return Matrix(_spec_ctr(), init);
495  }
496 
498  friend Matrix operator + (const Matrix& a, const Matrix& b)
499  {
500  return Added(a, b);
501  }
502 
504  friend Matrix Subtracted(const Matrix& a, const Matrix& b)
505  {
506  _op_subtract init = {a, b};
507  return Matrix(_spec_ctr(), init);
508  }
509 
511  friend Matrix operator - (const Matrix& a, const Matrix& b)
512  {
513  return Subtracted(a, b);
514  }
515 
517  template <std::size_t N>
519  const Matrix<T, Rows, N>& a,
520  const Matrix<T, N, Cols>& b
521  )
522  {
523  _op_multiply<N> init = {a, b};
524  return Matrix(_spec_ctr(), init);
525  }
526 
528  template <std::size_t N>
530  const Matrix<T, Rows, N>& a,
531  const Matrix<T, N, Cols>& b
532  )
533  {
534  return Multiplied(a, b);
535  }
536 
538  friend Matrix Multiplied(const Matrix& a, T m)
539  {
540  _op_mult_c init = {a, m};
541  return Matrix(_spec_ctr(), init);
542  }
543 
545  friend Matrix operator * (const Matrix& a, T m)
546  {
547  return Multiplied(a, m);
548  }
549 
551  friend Matrix operator * (T m, const Matrix& a)
552  {
553  return Multiplied(a, m);
554  }
555 
558  {
559  _op_transpose init = {a};
560  return Matrix(_spec_ctr(), init);
561  }
562 
564  template <std::size_t I, std::size_t J, std::size_t R, std::size_t C>
566  {
567  _op_extract<I, J, R, C> init = {*this};
568  return Matrix<T, R, C>(_spec_ctr(), init);
569  }
570 
572  friend Matrix<T, 2, 2> Sub2x2(const Matrix& a)
573  {
574  _op_extract<0, 0, 2, 2> init = {a};
575  return Matrix<T, 2, 2>(_spec_ctr(), init);
576  }
577 
579  friend Matrix<T, 3, 3> Sub3x3(const Matrix& a)
580  {
581  _op_extract<0, 0, 3, 3> init = {a};
582  return Matrix<T, 3, 3>(_spec_ctr(), init);
583  }
584 
586  friend void RowSwap(Matrix& m, std::size_t a, std::size_t b)
587  {
588  assert(a < Rows);
589  assert(b < Rows);
590  ::std::swap_ranges(
591  m._m._elem[a],
592  m._m._elem[a]+Cols,
593  m._m._elem[b]
594  );
595  }
596 
598  friend void RowMultiply(Matrix& m, std::size_t i, T k)
599  {
600  assert(i < Rows);
601  for(std::size_t j=0; j!=Cols; ++j)
602  m._m._elem[i][j] *= k;
603  }
604 
606  friend void RowAdd(Matrix& m, std::size_t a, std::size_t b, T k)
607  {
608  assert(a < Rows);
609  assert(b < Rows);
610  for(std::size_t j=0; j!=Cols; ++j)
611  m._m._elem[a][j] += m._m._elem[b][j] * k;
612  }
613 
615  template <std::size_t C>
616  friend bool Gauss(Matrix& a, Matrix<T, Rows, C>& b)
617  {
618  const T zero(0), one(1);
619  for(std::size_t i=0; i!=Rows; ++i)
620  {
621  T d = a._m._elem[i][i];
622  if(d == zero)
623  {
624  for(std::size_t k=i+1; k!=Rows; ++k)
625  {
626  if(a._m._elem[k][i] != zero)
627  {
628  RowSwap(a, i, k);
629  RowSwap(b, i, k);
630  break;
631  }
632  }
633  d = a._m._elem[i][i];
634  }
635  if(d == zero) return false;
636 
637  RowMultiply(a, i, one / d);
638  RowMultiply(b, i, one / d);
639 
640  for(std::size_t k=i+1; k!=Rows; ++k)
641  {
642  T c = a._m._elem[k][i];
643  if(c != zero)
644  {
645  RowAdd(a, k, i, -c);
646  RowAdd(b, k, i, -c);
647  }
648  }
649  }
650  return true;
651  }
652 
654  template <std::size_t C>
656  {
657  if(!Gauss(a, b)) return false;
658  const T zero(0);
659  for(std::size_t i=Rows-1; i!=0; --i)
660  {
661  for(std::size_t k=0; k!=i; ++k)
662  {
663  T c = a._m._elem[k][i];
664  if(c != zero)
665  {
666  RowAdd(a, k, i, -c);
667  RowAdd(b, k, i, -c);
668  }
669  }
670  }
671  return true;
672  }
673 };
674 
675 template <
676  std::size_t I,
677  std::size_t J,
678  std::size_t R,
679  std::size_t C,
680  typename T,
681  std::size_t Rows,
682  std::size_t Cols
683 > inline Matrix<T, R, C> Submatrix(const Matrix<T, Rows, Cols>& a)
684 {
685  return a.template Submatrix<I, J, R, C>();
686 }
687 
688 template <typename T, std::size_t R, std::size_t C>
689 inline bool Close(
690  const Matrix<T, R, C>& a,
691  const Matrix<T, R, C>& b,
692  T eps
693 )
694 {
695  assert(eps >= T(0));
696  for(std::size_t i=0; i!=R; ++i)
697  for(std::size_t j=0; j!=C; ++j)
698  {
699  T u = a.At(i, j);
700  T v = b.At(i, j);
701  T d = std::abs(u-v);
702  bool ca = d <= std::abs(u)*eps;
703  bool cb = d <= std::abs(v)*eps;
704  if(!ca && !cb) return false;
705  }
706  return true;
707 }
708 
709 template <typename T>
710 inline void InitMatrix4x4(
711  Matrix<T, 4, 4>& matrix,
712  T v00, T v01, T v02, T v03,
713  T v10, T v11, T v12, T v13,
714  T v20, T v21, T v22, T v23,
715  T v30, T v31, T v32, T v33
716 )
717 {
718  matrix.Set(0, 0, v00);
719  matrix.Set(0, 1, v01);
720  matrix.Set(0, 2, v02);
721  matrix.Set(0, 3, v03);
722 
723  matrix.Set(1, 0, v10);
724  matrix.Set(1, 1, v11);
725  matrix.Set(1, 2, v12);
726  matrix.Set(1, 3, v13);
727 
728  matrix.Set(2, 0, v20);
729  matrix.Set(2, 1, v21);
730  matrix.Set(2, 2, v22);
731  matrix.Set(2, 3, v23);
732 
733  matrix.Set(3, 0, v30);
734  matrix.Set(3, 1, v31);
735  matrix.Set(3, 2, v32);
736  matrix.Set(3, 3, v33);
737 }
738 
739 template <typename T, std::size_t R, std::size_t C>
740 inline const T* Data(const Matrix<T, R, C>& matrix)
741 {
742  return matrix.Data();
743 }
744 
745 template <typename T, std::size_t R, std::size_t C>
746 inline std::size_t Size(const Matrix<T, R, C>&)
747 {
748  return R * C;
749 }
750 
751 template <typename T, std::size_t R, std::size_t C>
752 inline std::size_t Rows(const Matrix<T, R, C>&)
753 {
754  return R;
755 }
756 
757 template <typename T, std::size_t R, std::size_t C>
758 inline std::size_t Cols(const Matrix<T, R, C>&)
759 {
760  return C;
761 }
762 
763 template <typename T, std::size_t R, std::size_t C>
764 inline T At(const Matrix<T, R, C>& matrix, std::size_t i, std::size_t j)
765 {
766  return matrix.At(i, j);
767 }
768 
769 template <typename T, std::size_t R, std::size_t C>
770 inline Matrix<T, R, C> Inverse(Matrix<T, R, C> m)
771 {
772  Matrix<T, R, C> i;
773  if(!GaussJordan(m, i)) i.Fill(T(0));
774  return i;
775 }
776 
778 
783 template <typename T>
785  : public Matrix<T, 4, 4>
786 {
787 private:
788  typedef Matrix<T, 4, 4> Base;
789 public:
792  : Base()
793  { }
794 
795  ModelMatrix(const Base& base)
796  : Base(base)
797  { }
798 
799  struct Translation_ { };
800 
801  ModelMatrix(Translation_, T dx, T dy, T dz)
802  : Base(oglplus::Nothing())
803  {
804  InitMatrix4x4(
805  *this,
806  T(1), T(0), T(0), dx,
807  T(0), T(1), T(0), dy,
808  T(0), T(0), T(1), dz,
809  T(0), T(0), T(0), T(1)
810  );
811  }
812 
814  static inline ModelMatrix Translation(T dx, T dy, T dz)
815  {
816  return ModelMatrix(Translation_(), dx, dy, dz);
817  }
818 
820  static inline ModelMatrix TranslationX(T dx)
821  {
822  return ModelMatrix(Translation_(), dx, T(0), T(0));
823  }
824 
826  static inline ModelMatrix TranslationY(T dy)
827  {
828  return ModelMatrix(Translation_(), T(0), dy, T(0));
829  }
830 
832  static inline ModelMatrix TranslationZ(T dz)
833  {
834  return ModelMatrix(Translation_(), T(0), T(0), dz);
835  }
836 
838  static inline ModelMatrix Translation(const Vector<T, 3>& dp)
839  {
840  return ModelMatrix(Translation_(), dp.x(), dp.y(), dp.z());
841  }
842 
843  struct Scale_ { };
844 
845  ModelMatrix(Scale_, T sx, T sy, T sz)
846  : Base(oglplus::Nothing())
847  {
848  InitMatrix4x4(
849  *this,
850  sx, T(0), T(0), T(0),
851  T(0), sy, T(0), T(0),
852  T(0), T(0), sz, T(0),
853  T(0), T(0), T(0), T(1)
854  );
855  }
856 
858  static inline ModelMatrix Scale(T sx, T sy, T sz)
859  {
860  return ModelMatrix(Scale_(), sx, sy, sz);
861  }
862 
863  struct Reflection_ { };
864 
865  ModelMatrix(Reflection_, bool rx, bool ry, bool rz)
866  : Base(oglplus::Nothing())
867  {
868  const T _rx = rx ?-T(1):T(1);
869  const T _ry = ry ?-T(1):T(1);
870  const T _rz = rz ?-T(1):T(1);
871  InitMatrix4x4(
872  *this,
873  _rx, T(0), T(0), T(0),
874  T(0), _ry, T(0), T(0),
875  T(0), T(0), _rz, T(0),
876  T(0), T(0), T(0), T(1)
877  );
878  }
879 
881  static inline ModelMatrix Reflection(bool rx, bool ry, bool rz)
882  {
883  return ModelMatrix(Reflection_(), rx, ry, rz);
884  }
885 
886  struct RotationX_ { };
887 
888  ModelMatrix(RotationX_, Angle<T> angle)
889  : Base(oglplus::Nothing())
890  {
891  const T cosx = Cos(angle);
892  const T sinx = Sin(angle);
893  InitMatrix4x4(
894  *this,
895  T(1), T(0), T(0), T(0),
896  T(0), cosx, -sinx, T(0),
897  T(0), sinx, cosx, T(0),
898  T(0), T(0), T(0), T(1)
899  );
900  }
901 
903  static inline ModelMatrix RotationX(Angle<T> angle)
904  {
905  return ModelMatrix(RotationX_(), angle);
906  }
907 
908  struct RotationY_ { };
909 
910  ModelMatrix(RotationY_, Angle<T> angle)
911  : Base(oglplus::Nothing())
912  {
913  const T cosx = Cos(angle);
914  const T sinx = Sin(angle);
915  InitMatrix4x4(
916  *this,
917  cosx, T(0), sinx, T(0),
918  T(0), T(1), T(0), T(0),
919  -sinx, T(0), cosx, T(0),
920  T(0), T(0), T(0), T(1)
921  );
922  }
923 
925  static inline ModelMatrix RotationY(Angle<T> angle)
926  {
927  return ModelMatrix(RotationY_(), angle);
928  }
929 
930  struct RotationZ_ { };
931 
932  ModelMatrix(RotationZ_, Angle<T> angle)
933  : Base(oglplus::Nothing())
934  {
935  const T cosx = Cos(angle);
936  const T sinx = Sin(angle);
937  InitMatrix4x4(
938  *this,
939  cosx, -sinx, T(0), T(0),
940  sinx, cosx, T(0), T(0),
941  T(0), T(0), T(1), T(0),
942  T(0), T(0), T(0), T(1)
943  );
944  }
945 
947  static inline ModelMatrix RotationZ(Angle<T> angle)
948  {
949  return ModelMatrix(RotationZ_(), angle);
950  }
951 
952  struct RotationA_ { };
953 
954  ModelMatrix(RotationA_, const Vector<T,3>& axis, Angle<T> angle)
955  : Base(oglplus::Nothing())
956  {
957  const Vector<T, 3> a = Normalized(axis);
958  const T sf = Sin(angle);
959  const T cf = Cos(angle);
960  const T _cf = T(1) - cf;
961  const T x = a.At(0), y = a.At(1), z = a.At(2);
962  const T xx= x*x, xy= x*y, xz= x*z, yy= y*y, yz= y*z, zz= z*z;
963  InitMatrix4x4(
964  *this,
965  xx*_cf + cf, xy*_cf - z*sf, xz*_cf + y*sf, T(0),
966  xy*_cf + z*sf, yy*_cf + cf, yz*_cf - x*sf, T(0),
967  xz*_cf - y*sf, yz*_cf + x*sf, zz*_cf + cf, T(0),
968  T(0), T(0), T(0), T(1)
969  );
970  }
971 
973  static inline ModelMatrix RotationA(
974  const Vector<T,3>& axis,
975  Angle<T> angle
976  )
977  {
978  return ModelMatrix(RotationA_(), axis, angle);
979  }
980 
981  ModelMatrix(RotationA_, Quaternion<T> quat)
982  : Base(oglplus::Nothing())
983  {
984  quat.Normalize();
985  const T a = quat.At(0);
986  const T x = quat.At(1);
987  const T y = quat.At(2);
988  const T z = quat.At(3);
989  InitMatrix4x4(
990  *this,
991  1-2*y*y-2*z*z, 2*x*y-2*a*z, 2*x*z+2*a*y, T(0),
992  2*x*y+2*a*z, 1-2*x*x-2*z*z, 2*y*z-2*a*x, T(0),
993  2*x*z-2*a*y, 2*y*z+2*a*x, 1-2*x*x-2*y*y, T(0),
994  T(0), T(0), T(0), T(1)
995  );
996  }
997 
999  static inline ModelMatrix RotationQ(const Quaternion<T>& quat)
1000  {
1001  return ModelMatrix(RotationA_(), quat);
1002  }
1003 
1004 };
1005 
1006 #if OGLPLUS_DOCUMENTATION_ONLY || defined(GL_FLOAT)
1007 
1012 #endif
1013 
1014 #if OGLPLUS_DOCUMENTATION_ONLY || defined(GL_DOUBLE)
1015 
1020 #endif
1021 
1023 
1028 template <typename T>
1030  : public Matrix<T, 4, 4>
1031 {
1032 private:
1033  typedef Matrix<T, 4, 4> Base;
1034 public:
1035 
1036 #if OGLPLUS_DOCUMENTATION_ONLY
1037  CameraMatrix(void);
1039 #endif
1040 
1041 #if !OGLPLUS_NO_DEFAULTED_FUNCTIONS
1042  CameraMatrix(void) = default;
1043 #else
1044  CameraMatrix(void){ }
1045 #endif
1046 
1047  CameraMatrix(const Base& base)
1048  : Base(base)
1049  { }
1050 
1051  Vector<T, 3> Position(void) const
1052  {
1053  return Vector<T,3>(Inverse(*this).Col(3).Data(), 3);
1054  }
1055 
1056  Vector<T, 3> Direction(void) const
1057  {
1058  return -Vector<T, 3>(this->Row(2).Data(), 3);
1059  }
1060 
1061  struct Perspective_ { };
1062 
1063  CameraMatrix(
1064  Perspective_,
1065  T x_left,
1066  T x_right,
1067  T y_bottom,
1068  T y_top,
1069  T z_near,
1070  T z_far
1071  ): Base(oglplus::Nothing())
1072  {
1073  T m00 = (T(2) * z_near) / (x_right - x_left);
1074  T m11 = (T(2) * z_near) / (y_top - y_bottom);
1075  T m22 = -(z_far + z_near) / (z_far - z_near);
1076 
1077  T m20 = (x_right + x_left) / (x_right - x_left);
1078  T m21 = (y_top + y_bottom) / (y_top - y_bottom);
1079  T m23 = -T(1);
1080 
1081  T m32 = -(T(2) * z_far * z_near) / (z_far - z_near);
1082 
1083  InitMatrix4x4(
1084  *this,
1085  m00, T(0), m20, T(0),
1086  T(0), m11, m21, T(0),
1087  T(0), T(0), m22, m32,
1088  T(0), T(0), m23, T(0)
1089  );
1090  }
1091 
1093 
1096  static inline CameraMatrix Perspective(
1097  T x_left,
1098  T x_right,
1099  T y_bottom,
1100  T y_top,
1101  T z_near,
1102  T z_far
1103  )
1104  {
1105  return CameraMatrix(
1106  Perspective_(),
1107  x_left,
1108  x_right,
1109  y_bottom,
1110  y_top,
1111  z_near,
1112  z_far
1113  );
1114  }
1115 
1117 
1121  Angle<T> xfov,
1122  T aspect,
1123  T z_near,
1124  T z_far
1125  )
1126  {
1127  assert(aspect > T(0));
1128  assert(xfov > Angle<T>::Radians(T(0)));
1129 
1130  T x_right = z_near * Tan(xfov * T(0.5));
1131  T x_left = -x_right;
1132 
1133  T y_bottom = x_left / aspect;
1134  T y_top = x_right / aspect;
1135 
1136  return CameraMatrix(
1137  Perspective_(),
1138  x_left,
1139  x_right,
1140  y_bottom,
1141  y_top,
1142  z_near,
1143  z_far
1144  );
1145  }
1146 
1148 
1152  Angle<T> yfov,
1153  T aspect,
1154  T z_near,
1155  T z_far
1156  )
1157  {
1158  assert(aspect > T(0));
1159  assert(yfov > Angle<T>::Radians(T(0)));
1160 
1161  T y_top = z_near * Tan(yfov * T(0.5));
1162  T y_bottom = -y_top;
1163 
1164  T x_left = y_bottom * aspect;
1165  T x_right = y_top * aspect;
1166 
1167  return CameraMatrix(
1168  Perspective_(),
1169  x_left,
1170  x_right,
1171  y_bottom,
1172  y_top,
1173  z_near,
1174  z_far
1175  );
1176  }
1177 
1178  struct Ortho_ { };
1179 
1180  CameraMatrix(
1181  Ortho_,
1182  T x_left,
1183  T x_right,
1184  T y_bottom,
1185  T y_top,
1186  T z_near,
1187  T z_far
1188  ): Base(oglplus::Nothing())
1189  {
1190  T m00 = T(2) / (x_right - x_left);
1191  T m11 = T(2) / (y_top - y_bottom);
1192  T m22 = -T(2) / (z_far - z_near);
1193 
1194  T m30 = -(x_right + x_left) / (x_right - x_left);
1195  T m31 = -(y_top + y_bottom) / (y_top - y_bottom);
1196  T m32 = -(z_far + z_near) / (z_far - z_near);
1197 
1198  InitMatrix4x4(
1199  *this,
1200  m00, T(0), T(0), m30,
1201  T(0), m11, T(0), m31,
1202  T(0), T(0), m22, m32,
1203  T(0), T(0), T(0), T(1)
1204  );
1205  }
1206 
1208 
1211  static inline CameraMatrix Ortho(
1212  T x_left,
1213  T x_right,
1214  T y_bottom,
1215  T y_top,
1216  T z_near,
1217  T z_far
1218  )
1219  {
1220  return CameraMatrix(
1221  Ortho_(),
1222  x_left,
1223  x_right,
1224  y_bottom,
1225  y_top,
1226  z_near,
1227  z_far
1228  );
1229  }
1230 
1232 
1235  static inline CameraMatrix OrthoX(
1236  T width,
1237  T aspect,
1238  T z_near,
1239  T z_far
1240  )
1241  {
1242  assert(aspect > T(0));
1243  assert(width > T(0));
1244 
1245  T x_right = width / T(2);
1246  T x_left = -x_right;
1247 
1248  T y_bottom = x_left / aspect;
1249  T y_top = x_right / aspect;
1250 
1251  return CameraMatrix(
1252  Ortho_(),
1253  x_left,
1254  x_right,
1255  y_bottom,
1256  y_top,
1257  z_near,
1258  z_far
1259  );
1260  }
1261 
1263 
1266  static inline CameraMatrix OrthoY(
1267  T height,
1268  T aspect,
1269  T z_near,
1270  T z_far
1271  )
1272  {
1273  assert(aspect > T(0));
1274  assert(height > T(0));
1275 
1276  T y_top = height / T(2);
1277  T y_bottom = -y_top;
1278 
1279  T x_left = y_bottom * aspect;
1280  T x_right = y_top * aspect;
1281 
1282  return CameraMatrix(
1283  Ortho_(),
1284  x_left,
1285  x_right,
1286  y_bottom,
1287  y_top,
1288  z_near,
1289  z_far
1290  );
1291  }
1292 
1293  struct ScreenStretch_ { };
1294 
1295  CameraMatrix(
1296  ScreenStretch_,
1297  T x_left,
1298  T x_right,
1299  T y_bottom,
1300  T y_top
1301  ): Base(oglplus::Nothing())
1302  {
1303  assert((x_right - x_left) != T(0));
1304  assert((y_top - y_bottom) != T(0));
1305 
1306  T m00 = T(2) / (x_right - x_left);
1307  T m11 = T(2) / (y_top - y_bottom);
1308 
1309  T m30 = -(x_right + x_left) / (x_right - x_left);
1310  T m31 = -(y_top + y_bottom) / (y_top - y_bottom);
1311 
1312  InitMatrix4x4(
1313  *this,
1314  m00, T(0), T(0), m30,
1315  T(0), m11, T(0), m31,
1316  T(0), T(0), T(1), T(0),
1317  T(0), T(0), T(0), T(1)
1318  );
1319  }
1320 
1322 
1326  T x_left,
1327  T x_right,
1328  T y_bottom,
1329  T y_top
1330  )
1331  {
1332  return CameraMatrix(
1333  ScreenStretch_(),
1334  x_left,
1335  x_right,
1336  y_bottom,
1337  y_top
1338  );
1339  }
1340 
1342 
1348  static inline CameraMatrix ScreenTile(
1349  unsigned x,
1350  unsigned y,
1351  unsigned nx,
1352  unsigned ny
1353  )
1354  {
1355  assert(x < nx);
1356  assert(y < ny);
1357 
1358  return CameraMatrix(
1359  ScreenStretch_(),
1360  -T(1)+T(2*(x+0))/T(nx),
1361  -T(1)+T(2*(x+1))/T(nx),
1362  -T(1)+T(2*(y+0))/T(ny),
1363  -T(1)+T(2*(y+1))/T(ny)
1364  );
1365  }
1366 
1367  struct LookingAt_ { };
1368 
1369  CameraMatrix(
1370  LookingAt_,
1371  const Vector<T, 3>& eye,
1372  const Vector<T, 3>& target
1373  ): Base(oglplus::Nothing())
1374  {
1375  assert(eye != target);
1376  Vector<T, 3> z = Normalized(eye - target);
1377  T zx = z[0];
1378  T zz = z[2];
1379  Vector<T, 3> t(zz, T(0), -zx);
1380  Vector<T, 3> y = Normalized(Cross(z, t));
1381  Vector<T, 3> x = Cross(y, z);
1382 
1383  InitMatrix4x4(
1384  *this,
1385  x[0], x[1], x[2],
1386  -Dot(eye, x),
1387 
1388  y[0], y[1], y[2],
1389  -Dot(eye, y),
1390 
1391  z[0], z[1], z[2],
1392  -Dot(eye, z),
1393 
1394  T(0), T(0), T(0), T(1)
1395  );
1396  }
1397 
1399  static inline CameraMatrix LookingAt(
1400  const Vector<T, 3>& eye,
1401  const Vector<T, 3>& target
1402  )
1403  {
1404  return CameraMatrix(LookingAt_(), eye, target);
1405  }
1406 
1407  CameraMatrix(
1408  LookingAt_,
1409  const Vector<T, 3>& eye,
1410  const Vector<T, 3>& target,
1411  const Vector<T, 3>& up
1412  ): Base(oglplus::Nothing())
1413  {
1414  assert(eye != target);
1415  Vector<T, 3> z = Normalized(eye - target);
1416  T dupz = Dot(up, z);
1417  assert(dupz < 0.9 && dupz >-0.9);
1418  Vector<T, 3> y = Normalized(
1419  dupz != 0.0?
1420  up-z*dupz:
1421  up
1422  );
1423  Vector<T, 3> x = Cross(y, z);
1424 
1425  InitMatrix4x4(
1426  *this,
1427  x[0], x[1], x[2],
1428  -Dot(eye, x),
1429 
1430  y[0], y[1], y[2],
1431  -Dot(eye, y),
1432 
1433  z[0], z[1], z[2],
1434  -Dot(eye, z),
1435 
1436  T(0), T(0), T(0), T(1)
1437  );
1438  }
1439 
1441  static inline CameraMatrix LookingAt(
1442  const Vector<T, 3>& eye,
1443  const Vector<T, 3>& target,
1444  const Vector<T, 3>& up
1445  )
1446  {
1447  return CameraMatrix(LookingAt_(), eye, target, up);
1448  }
1449 
1450  struct Orbiting_ { };
1451 
1452  CameraMatrix(
1453  Orbiting_,
1454  const Vector<T, 3>& target,
1455  T radius,
1456  Angle<T> azimuth,
1457  Angle<T> elevation
1458  )
1459  {
1460  Vector<T, 3> z(
1461  Cos(elevation) * Cos(azimuth),
1462  Sin(elevation),
1463  Cos(elevation) *-Sin(azimuth)
1464  );
1465  Vector<T, 3> x(
1466  -Sin(azimuth),
1467  T(0),
1468  -Cos(azimuth)
1469  );
1470  Vector<T, 3> y = Cross(z, x);
1471 
1472  InitMatrix4x4(
1473  *this,
1474  x[0], x[1], x[2],
1475  Dot(x, z) * -radius - Dot(x, target),
1476 
1477  y[0], y[1], y[2],
1478  Dot(y, z) * -radius - Dot(y, target),
1479 
1480  z[0], z[1], z[2],
1481  Dot(z, z) * -radius - Dot(z, target),
1482 
1483  T(0), T(0), T(0), T(1)
1484  );
1485 
1486  }
1487 
1489  static inline CameraMatrix Orbiting(
1490  const Vector<T, 3>& target,
1491  T radius,
1492  Angle<T> azimuth,
1493  Angle<T> elevation
1494  )
1495  {
1496  return CameraMatrix(
1497  Orbiting_(),
1498  target,
1499  radius,
1500  azimuth,
1501  elevation
1502  );
1503  }
1504 
1505  struct Pitch_ { };
1506 
1507  CameraMatrix(Pitch_, Angle<T> angle)
1508  : Base(oglplus::Nothing())
1509  {
1510  const T cosx = Cos(-angle);
1511  const T sinx = Sin(-angle);
1512  InitMatrix4x4(
1513  *this,
1514  T(1), T(0), T(0), T(0),
1515  T(0), cosx, -sinx, T(0),
1516  T(0), sinx, cosx, T(0),
1517  T(0), T(0), T(0), T(1)
1518  );
1519  }
1520 
1522 
1527  static inline CameraMatrix Pitch(Angle<T> angle)
1528  {
1529  return CameraMatrix(Pitch_(), angle);
1530  }
1531 
1532  struct Yaw_ { };
1533 
1534  CameraMatrix(Yaw_, Angle<T> angle)
1535  : Base(oglplus::Nothing())
1536  {
1537  const T cosx = Cos(-angle);
1538  const T sinx = Sin(-angle);
1539  InitMatrix4x4(
1540  *this,
1541  cosx, T(0), sinx, T(0),
1542  T(0), T(1), T(0), T(0),
1543  -sinx, T(0), cosx, T(0),
1544  T(0), T(0), T(0), T(1)
1545  );
1546  }
1547 
1549 
1554  static inline CameraMatrix Yaw(Angle<T> angle)
1555  {
1556  return CameraMatrix(Yaw_(), angle);
1557  }
1558 
1559  struct Roll_ { };
1560 
1561  CameraMatrix(Roll_, Angle<T> angle)
1562  : Base(oglplus::Nothing())
1563  {
1564  const T cosx = Cos(-angle);
1565  const T sinx = Sin(-angle);
1566  InitMatrix4x4(
1567  *this,
1568  cosx, -sinx, T(0), T(0),
1569  sinx, cosx, T(0), T(0),
1570  T(0), T(0), T(1), T(0),
1571  T(0), T(0), T(0), T(1)
1572  );
1573  }
1574 
1576 
1581  static inline CameraMatrix Roll(Angle<T> angle)
1582  {
1583  return CameraMatrix(Roll_(), angle);
1584  }
1585 };
1586 
1587 #if OGLPLUS_DOCUMENTATION_ONLY || defined(GL_FLOAT)
1588 
1593 #endif
1594 
1595 #if OGLPLUS_DOCUMENTATION_ONLY || defined(GL_DOUBLE)
1596 
1601 #endif
1602 
1603 } // namespace oglplus
1604 
1605 #endif // include guard
static ModelMatrix Translation(T dx, T dy, T dz)
Constructs a translation matrix.
Definition: matrix.hpp:814
static CameraMatrix Roll(Angle< T > angle)
Constructs a Z-axis rotation (Bank/Roll) matrix.
Definition: matrix.hpp:1581
Matrix< GLdouble, 4, 4 > Mat4d
4x4 double-precision matrix
Definition: matrix.hpp:145
Class implementing model transformation matrix named constructors.
Definition: matrix.hpp:784
friend Matrix Multiplied(const Matrix &a, T m)
Multiplication by scalar value.
Definition: matrix.hpp:538
static CameraMatrix PerspectiveX(Angle< T > xfov, T aspect, T z_near, T z_far)
Constructs a perspective projection matrix.
Definition: matrix.hpp:1120
static ModelMatrix RotationA(const Vector< T, 3 > &axis, Angle< T > angle)
Constructs a rotation matrix from a vector and angle.
Definition: matrix.hpp:973
static CameraMatrix LookingAt(const Vector< T, 3 > &eye, const Vector< T, 3 > &target)
Constructs a 'look-at' matrix from eye and target positions.
Definition: matrix.hpp:1399
Template class for quaternions.
Definition: fwd.hpp:59
static CameraMatrix ScreenTile(unsigned x, unsigned y, unsigned nx, unsigned ny)
Constructs a matrix for stretching NDCs after projection.
Definition: matrix.hpp:1348
Matrix< GLfloat, 2, 3 > Mat2x3f
2x3 float matrix
Definition: matrix.hpp:47
Matrix< GLdouble, 4, 3 > Mat4x3d
4x3 double-precision matrix
Definition: matrix.hpp:139
static ModelMatrix RotationX(Angle< T > angle)
Constructs a X-axis rotation matrix.
Definition: matrix.hpp:903
friend void RowAdd(Matrix &m, std::size_t a, std::size_t b, T k)
Adds row b multipled by coeficient k to row a.
Definition: matrix.hpp:606
Vector< T, Rows > Col(std::size_t j) const
Return the j-th column of this matrix.
Definition: matrix.hpp:446
Class implementing planar angle-related functionality.
Definition: fwd.hpp:24
Definition: vector.hpp:14
friend std::size_t Rows(const Matrix &matrix)
Returns the number of rows of the matrix.
friend bool GaussJordan(Matrix &a, Matrix< T, Rows, C > &b)
The Gauss-Jordan matrix elimination.
Definition: matrix.hpp:655
static CameraMatrix Yaw(Angle< T > angle)
Constructs a Y-axis rotation (Heading/Yaw) matrix.
Definition: matrix.hpp:1554
friend Matrix Negated(const Matrix &a)
Element negation function.
Definition: matrix.hpp:478
friend Matrix Added(const Matrix &a, const Matrix &b)
Matrix addition.
Definition: matrix.hpp:491
static ModelMatrix TranslationY(T dy)
Constructs a translation matrix.
Definition: matrix.hpp:826
friend bool Equal(const Matrix &a, const Matrix &b)
Equality comparison function.
Definition: matrix.hpp:456
static ModelMatrix RotationZ(Angle< T > angle)
Constructs a Z-axis rotation matrix.
Definition: matrix.hpp:947
friend Matrix Subtracted(const Matrix &a, const Matrix &b)
Matrix subtraction.
Definition: matrix.hpp:504
friend Matrix operator*(const Matrix< T, Rows, N > &a, const Matrix< T, N, Cols > &b)
Matrix multiplication operator.
Definition: matrix.hpp:529
static CameraMatrix ScreenStretch(T x_left, T x_right, T y_bottom, T y_top)
Constructs a matrix for stretching NDCs after projection.
Definition: matrix.hpp:1325
Matrix< GLfloat, 4, 3 > Mat4x3f
4x3 float matrix
Definition: matrix.hpp:83
static CameraMatrix LookingAt(const Vector< T, 3 > &eye, const Vector< T, 3 > &target, const Vector< T, 3 > &up)
Constructs 'look-at' matrix from eye and target positions and up vector.
Definition: matrix.hpp:1441
friend Matrix operator+(const Matrix &a, const Matrix &b)
Matrix addition operator.
Definition: matrix.hpp:498
Matrix< GLfloat, 3, 2 > Mat3x2f
3x2 float matrix
Definition: matrix.hpp:59
Matrix< GLdouble, 3, 3 > Mat3d
3x3 double-precision matrix
Definition: matrix.hpp:121
friend Matrix operator-(const Matrix &a)
Element negation operator.
Definition: matrix.hpp:485
static CameraMatrix OrthoY(T height, T aspect, T z_near, T z_far)
Constructs an orthographic projection matrix.
Definition: matrix.hpp:1266
ModelMatrix< GLfloat > ModelMatrixf
Model transformation float matrix.
Definition: matrix.hpp:1011
static CameraMatrix Ortho(T x_left, T x_right, T y_bottom, T y_top, T z_near, T z_far)
Constructs an orthographic projection matrix.
Definition: matrix.hpp:1211
friend Matrix Transposed(const Matrix< T, Cols, Rows > &a)
Matrix transposition.
Definition: matrix.hpp:557
static CameraMatrix PerspectiveY(Angle< T > yfov, T aspect, T z_near, T z_far)
Constructs a perspective projection matrix.
Definition: matrix.hpp:1151
static CameraMatrix OrthoX(T width, T aspect, T z_near, T z_far)
Constructs an orthographic projection matrix.
Definition: matrix.hpp:1235
Quaternion & Normalize(void)
Normalizes this quaternion.
Definition: quaternion.hpp:152
friend Matrix Multiplied(const Matrix< T, Rows, N > &a, const Matrix< T, N, Cols > &b)
Matrix multiplication.
Definition: matrix.hpp:518
Matrix< GLdouble, 3, 2 > Mat3x2d
3x2 double-precision matrix
Definition: matrix.hpp:115
static ModelMatrix Translation(const Vector< T, 3 > &dp)
Constructs a translation matrix.
Definition: matrix.hpp:838
friend bool Gauss(Matrix &a, Matrix< T, Rows, C > &b)
The gaussian matrix elimination.
Definition: matrix.hpp:616
static CameraMatrix Perspective(T x_left, T x_right, T y_bottom, T y_top, T z_near, T z_far)
Constructs a perspective projection matrix.
Definition: matrix.hpp:1096
static CameraMatrix Orbiting(const Vector< T, 3 > &target, T radius, Angle< T > azimuth, Angle< T > elevation)
Constructs a matrix from target, radius, azimuth and elevation.
Definition: matrix.hpp:1489
void Set(std::size_t i, std::size_t j, T v)
Sets the value of the element at position i, j.
Definition: matrix.hpp:426
Matrix(const T(&data)[Rows *Cols])
Constructuion from static array.
Definition: matrix.hpp:333
static ModelMatrix TranslationZ(T dz)
Constructs a translation matrix.
Definition: matrix.hpp:832
friend bool operator!=(const Matrix &a, const Matrix &b)
Unequality comparison operator.
Definition: matrix.hpp:472
Matrix< GLfloat, 3, 4 > Mat3x4f
3x4 float matrix
Definition: matrix.hpp:71
Matrix< GLdouble, 2, 4 > Mat2x4d
2x4 double-precision matrix
Definition: matrix.hpp:109
Matrix< GLdouble, 2, 2 > Mat2d
2x2 double-precision matrix
Definition: matrix.hpp:97
Matrix< GLfloat, 4, 2 > Mat4x2f
4x2 float matrix
Definition: matrix.hpp:77
CameraMatrix< GLdouble > CamMatrixd
Camera matrix using double precition numbers.
Definition: matrix.hpp:1600
T At(std::size_t i, std::size_t j) const
Returns the value of the element at position i, j.
Definition: matrix.hpp:416
Matrix(const T *data, std::size_t n)
Constructuion from raw data.
Definition: matrix.hpp:327
friend void RowMultiply(Matrix &m, std::size_t i, T k)
Multiplies row i with coeficient k.
Definition: matrix.hpp:598
Matrix< GLfloat, 3, 3 > Mat3f
3x3 float matrix
Definition: matrix.hpp:65
Matrix< GLdouble, 3, 4 > Mat3x4d
3x4 double-precision matrix
Definition: matrix.hpp:127
static ModelMatrix RotationQ(const Quaternion< T > &quat)
Constructs a rotation matrix from a quaternion.
Definition: matrix.hpp:999
friend void RowSwap(Matrix &m, std::size_t a, std::size_t b)
Swaps two rows of the Matrix.
Definition: matrix.hpp:586
Matrix< GLfloat, 2, 2 > Mat2f
2x2 float matrix
Definition: matrix.hpp:34
ModelMatrix< GLdouble > ModelMatrixd
Model transformation double precision matrix.
Definition: matrix.hpp:1019
Class implementing camera matrix named constructors.
Definition: matrix.hpp:1029
Base template for Matrix.
Definition: fwd.hpp:63
friend bool operator==(const Matrix &a, const Matrix &b)
Equality comparison operator.
Definition: matrix.hpp:466
static ModelMatrix Reflection(bool rx, bool ry, bool rz)
Constructs a reflection matrix.
Definition: matrix.hpp:881
Angle utility class.
const T * Data(void) const
Returns a pointer to the matrix elements in row major order.
Definition: matrix.hpp:387
std::size_t Size(void) const
Returns the number of elements of the matrix.
Definition: matrix.hpp:393
Matrix< T, R, C > Submatrix(void) const
Submatrix extraction.
Definition: matrix.hpp:565
friend Matrix< T, 3, 3 > Sub3x3(const Matrix &a)
3x3 submatrix extraction
Definition: matrix.hpp:579
Matrix< GLfloat, 2, 4 > Mat2x4f
2x4 float matrix
Definition: matrix.hpp:53
CameraMatrix< GLfloat > CamMatrixf
Camera matrix using float numbers.
Definition: matrix.hpp:1592
static ModelMatrix RotationY(Angle< T > angle)
Constructs a Y-axis rotation matrix.
Definition: matrix.hpp:925
ModelMatrix(void)
Constructs an identity matrix.
Definition: matrix.hpp:791
Vector< T, Cols > Row(std::size_t i) const
Returns the i-th row of this matrix.
Definition: matrix.hpp:436
Matrix(void)
Default construction (identity matrix)
Definition: matrix.hpp:319
A quaternion class.
Matrix< GLdouble, 2, 3 > Mat2x3d
2x3 double-precision matrix
Definition: matrix.hpp:103
Basic template for vector types.
Definition: fwd.hpp:43
friend std::size_t Cols(const Matrix &matrix)
Returns the number of columns of the matrix.
Matrix< GLdouble, 4, 2 > Mat4x2d
4x2 double-precision matrix
Definition: matrix.hpp:133
friend Matrix< T, 2, 2 > Sub2x2(const Matrix &a)
2x2 submatrix extraction
Definition: matrix.hpp:572
A vector class.
CameraMatrix(void)
Constructs an identity matrix.
Matrix< GLfloat, 4, 4 > Mat4f
4x4 float matrix
Definition: matrix.hpp:89
static CameraMatrix Pitch(Angle< T > angle)
Constructs a X-axis rotation (Pitch/Elevation) matrix.
Definition: matrix.hpp:1527
static ModelMatrix TranslationX(T dx)
Constructs a translation matrix.
Definition: matrix.hpp:820
static ModelMatrix Scale(T sx, T sy, T sz)
Constructs a scale matrix.
Definition: matrix.hpp:858

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).