Gamedev Framework (gf)  0.10.0
A C++14 framework for 2D games
Matrix.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2018 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_MATRIX_H
22 #define GF_MATRIX_H
23 
24 #include <cstddef>
25 #include <algorithm>
26 
27 #include "Portability.h"
28 #include "Vector.h"
29 #include "Types.h"
30 
31 namespace gf {
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 inline namespace v1 {
34 #endif
35 
59  template<typename T, std::size_t ROWS, std::size_t COLS>
60  struct Matrix {
61  #ifndef DOXYGEN_SHOULD_SKIP_THIS
62  static_assert(ROWS > 0, "ROWS must be strictly positive");
63  static_assert(COLS > 0, "COLS must be strictly positive");
64  #endif
65 
69  using value_type = T;
70 
74  static constexpr std::size_t Rows = ROWS;
75 
79  static constexpr std::size_t Cols = COLS;
80 
84  Matrix() = default;
85 
86  constexpr Matrix(ZeroType) noexcept
87  {
88  zero();
89  }
90 
94  explicit Matrix(T val) noexcept
95  {
96  std::fill_n(data, ROWS * COLS, val);
97  }
98 
99  explicit Matrix(const T *array)
100  {
101  std::copy_n(array, ROWS * COLS, data);
102  }
103 
104  T operator()(std::size_t row, std::size_t col) const {
105  return grid[row][col];
106  }
107 
108  T& operator()(std::size_t row, std::size_t col) {
109  return grid[row][col];
110  }
111 
115  constexpr void zero() noexcept {
116  for (std::size_t i = 0; i < ROWS * COLS; ++i) {
117  data[i] = T{};
118  }
119  }
120 
124  union {
125  T grid[ROWS][COLS];
126  T data[ROWS * COLS];
127  };
128  };
129 
147  template<typename T>
148  struct Matrix<T, 2, 2> {
152  using value_type = T;
153 
157  static constexpr std::size_t Rows = 2;
158 
162  static constexpr std::size_t Cols = 2;
163 
167  Matrix() = default;
168 
169  constexpr Matrix(ZeroType) noexcept
170  {
171  zero();
172  }
173 
174  explicit constexpr Matrix(T val) noexcept
175  : m11(val), m12(val)
176  , m21(val), m22(val)
177  {
178 
179  }
180 
181  explicit constexpr Matrix(const T *array)
182  : m11(array[0]), m12(array[1])
183  , m21(array[2]), m22(array[3])
184  {
185 
186  }
187 
196  constexpr Matrix(T e11, T e12, T e21, T e22) noexcept
197  : m11(e11), m12(e12)
198  , m21(e21), m22(e22)
199  {
200 
201  }
202 
203  const T *getData() const noexcept {
204  return &m11;
205  }
206 
207  T *getData() noexcept {
208  return &m11;
209  }
210 
211  T operator()(std::size_t row, std::size_t col) const {
212  const T *grid[Rows][Cols] = {
213  { &m11, &m12 },
214  { &m21, &m22 }
215  };
216  return *grid[row][col];
217  }
218 
219  T& operator()(std::size_t row, std::size_t col) {
220  T *grid[Rows][Cols] = {
221  { &m11, &m12 },
222  { &m21, &m22 }
223  };
224  return *grid[row][col];
225  }
226 
227  constexpr void zero() noexcept {
228  m11 = m12 = T{};
229  m21 = m22 = T{};
230  }
231 
232  union {
233  T xx;
235  };
236 
237  union {
238  T xy;
240  };
241 
242  union {
243  T yx;
245  };
246 
247  union {
248  T yy;
250  };
251 
252  };
253 
271  template<typename T>
272  struct Matrix<T, 3, 3> {
276  using value_type = T;
277 
281  static constexpr std::size_t Rows = 3;
282 
286  static constexpr std::size_t Cols = 3;
287 
291  Matrix() = default;
292 
293  constexpr Matrix(ZeroType) noexcept
294  {
295  zero();
296  }
297 
298  explicit constexpr Matrix(T val) noexcept
299  : m11(val), m12(val), m13(val)
300  , m21(val), m22(val), m23(val)
301  , m31(val), m32(val), m33(val)
302  {
303 
304  }
305 
306  explicit constexpr Matrix(const T *array)
307  : m11(array[0]), m12(array[1]), m13(array[2])
308  , m21(array[3]), m22(array[4]), m23(array[5])
309  , m31(array[6]), m32(array[7]), m33(array[8])
310  {
311 
312  }
313 
327  constexpr Matrix(T e11, T e12, T e13, T e21, T e22, T e23, T e31, T e32, T e33) noexcept
328  : m11(e11), m12(e12), m13(e13)
329  , m21(e21), m22(e22), m23(e23)
330  , m31(e31), m32(e32), m33(e33)
331  {
332 
333  }
334 
335  const T *getData() const noexcept {
336  return &m11;
337  }
338 
339  T *getData() noexcept {
340  return &m11;
341  }
342 
343  T operator()(std::size_t row, std::size_t col) const {
344  const T *grid[Rows][Cols] = {
345  { &m11, &m12, &m13 },
346  { &m21, &m22, &m23 },
347  { &m31, &m32, &m33 }
348  };
349  return *grid[row][col];
350  }
351 
352  T& operator()(std::size_t row, std::size_t col) {
353  T *grid[Rows][Cols] = {
354  { &m11, &m12, &m13 },
355  { &m21, &m22, &m23 },
356  { &m31, &m32, &m33 }
357  };
358  return *grid[row][col];
359  }
360 
361  constexpr void zero() noexcept {
362  m11 = m12 = m13 = T{};
363  m21 = m22 = m23 = T{};
364  m31 = m32 = m33 = T{};
365  }
366 
367  union {
368  T xx;
370  };
371 
372  union {
373  T xy;
375  };
376 
377  union {
378  T xz;
380  };
381 
382  union {
383  T yx;
385  };
386 
387  union {
388  T yy;
390  };
391 
392  union {
393  T yz;
395  };
396 
397  union {
398  T zx;
400  };
401 
402  union {
403  T zy;
405  };
406 
407  union {
408  T zz;
410  };
411 
412  };
413 
429  template<typename T>
430  struct Matrix<T, 4, 4> {
434  using value_type = T;
435 
439  static constexpr std::size_t Rows = 4;
440 
444  static constexpr std::size_t Cols = 4;
445 
449  Matrix() = default;
450 
451  constexpr Matrix(ZeroType) noexcept
452  {
453  zero();
454  }
455 
456  explicit constexpr Matrix(T val) noexcept
457  : m11(val), m12(val), m13(val), m14(val)
458  , m21(val), m22(val), m23(val), m24(val)
459  , m31(val), m32(val), m33(val), m34(val)
460  , m41(val), m42(val), m43(val), m44(val)
461  {
462 
463  }
464 
465  explicit constexpr Matrix(const T *array)
466  : m11(array[ 0]), m12(array[ 1]), m13(array[ 2]), m14(array[ 3])
467  , m21(array[ 4]), m22(array[ 5]), m23(array[ 6]), m24(array[ 7])
468  , m31(array[ 8]), m32(array[ 9]), m33(array[10]), m34(array[11])
469  , m41(array[12]), m42(array[13]), m43(array[14]), m44(array[15])
470  {
471 
472  }
473 
494  constexpr Matrix(T e11, T e12, T e13, T e14, T e21, T e22, T e23, T e24, T e31, T e32, T e33, T e34, T e41, T e42, T e43, T e44) noexcept
495  : m11(e11), m12(e12), m13(e13), m14(e14)
496  , m21(e21), m22(e22), m23(e23), m24(e24)
497  , m31(e31), m32(e32), m33(e33), m34(e34)
498  , m41(e41), m42(e42), m43(e43), m44(e44)
499  {
500 
501  }
502 
503  const T *getData() const noexcept {
504  return &m11;
505  }
506 
507  T *getData() noexcept {
508  return &m11;
509  }
510 
511  T operator()(std::size_t row, std::size_t col) const {
512  const T *grid[Rows][Cols] = {
513  { &m11, &m12, &m13, &m14 },
514  { &m21, &m22, &m23, &m24 },
515  { &m31, &m32, &m33, &m34 },
516  { &m41, &m42, &m43, &m44 }
517  };
518  return *grid[row][col];
519  }
520 
521  T& operator()(std::size_t row, std::size_t col) {
522  T *grid[Rows][Cols] = {
523  { &m11, &m12, &m13, &m14 },
524  { &m21, &m22, &m23, &m24 },
525  { &m31, &m32, &m33, &m34 },
526  { &m41, &m42, &m43, &m44 }
527  };
528  return *grid[row][col];
529  }
530 
531  constexpr void zero() noexcept {
532  m11 = m12 = m13 = m14 = T{};
533  m21 = m22 = m23 = m24 = T{};
534  m31 = m32 = m33 = m34 = T{};
535  m41 = m42 = m43 = m44 = T{};
536  }
537 
538  union {
539  T xx;
541  };
542 
543  union {
544  T xy;
546  };
547 
548  union {
549  T xz;
551  };
552 
553  union {
554  T xw;
556  };
557 
558  union {
559  T yx;
561  };
562 
563  union {
564  T yy;
566  };
567 
568  union {
569  T yz;
571  };
572 
573  union {
574  T yw;
576  };
577 
578  union {
579  T zx;
581  };
582 
583  union {
584  T zy;
586  };
587 
588  union {
589  T zz;
591  };
592 
593  union {
594  T zw;
596  };
597 
598  union {
599  T wx;
601  };
602 
603  union {
604  T wy;
606  };
607 
608  union {
609  T wz;
611  };
612 
613  union {
614  T ww;
616  };
617 
618  };
619 
627 
635 
643 
644 // MSVC does not like extern template
645 #ifndef _MSC_VER
646  extern template struct Matrix<float, 2, 2>;
647  extern template struct Matrix<float, 3, 3>;
648  extern template struct Matrix<float, 4, 4>;
649 #endif
650 
651  /*
652  * equality operations
653  */
654 
659  template<typename T, std::size_t ROWS, std::size_t COLS>
660  constexpr
662  for (std::size_t i = 0; i < ROWS; ++i) {
663  for (std::size_t j = 0; j < COLS; ++j) {
664  if (lhs(i,j) != rhs(i,j)) {
665  return false;
666  }
667  }
668  }
669 
670  return true;
671  }
672 
677  template<typename T, std::size_t ROWS, std::size_t COLS>
678  constexpr
680  return !(lhs == rhs);
681  }
682 
683  /*
684  * unary operators
685  */
686 
691  template<typename T, std::size_t ROWS, std::size_t COLS>
692  constexpr
695 
696  for (std::size_t i = 0; i < ROWS; ++i) {
697  for (std::size_t j = 0; j < COLS; ++j) {
698  out(i,j) = - val(i,j);
699  }
700  }
701 
702  return out;
703  }
704 
705  /*
706  * arithmetic component-wise operations
707  */
708 
713  template<typename T, std::size_t ROWS, std::size_t COLS>
714  constexpr
717 
718  for (std::size_t i = 0; i < ROWS; ++i) {
719  for (std::size_t j = 0; j < COLS; ++j) {
720  out(i,j) = lhs(i,j) + rhs(i,j);
721  }
722  }
723 
724  return out;
725  }
726 
731  template<typename T, std::size_t ROWS, std::size_t COLS>
732  constexpr
734  for (std::size_t i = 0; i < ROWS; ++i) {
735  for (std::size_t j = 0; j < COLS; ++j) {
736  lhs(i,j) += rhs(i,j);
737  }
738  }
739 
740  return lhs;
741  }
742 
743 
748  template<typename T, std::size_t ROWS, std::size_t COLS>
749  constexpr
752 
753  for (std::size_t i = 0; i < ROWS; ++i) {
754  for (std::size_t j = 0; j < COLS; ++j) {
755  out(i,j) = lhs(i,j) - rhs(i,j);
756  }
757  }
758 
759  return out;
760  }
761 
766  template<typename T, std::size_t ROWS, std::size_t COLS>
767  constexpr
769  for (std::size_t i = 0; i < ROWS; ++i) {
770  for (std::size_t j = 0; j < COLS; ++j) {
771  lhs(i,j) -= rhs(i,j);
772  }
773  }
774 
775  return lhs;
776  }
777 
778  /*
779  * multiplication and division
780  */
781 
786  template<typename T, std::size_t ROWS, std::size_t COLS>
787  constexpr
790 
791  for (std::size_t i = 0; i < ROWS; ++i) {
792  for (std::size_t j = 0; j < COLS; ++j) {
793  out(i,j) = lhs(i,j) * rhs;
794  }
795  }
796 
797  return out;
798  }
799 
804  template<typename T, std::size_t ROWS, std::size_t COLS>
805  constexpr
807  for (std::size_t i = 0; i < ROWS; ++i) {
808  for (std::size_t j = 0; j < COLS; ++j) {
809  lhs(i,j) *= rhs;
810  }
811  }
812 
813  return lhs;
814  }
815 
820  template<typename T, std::size_t ROWS, std::size_t COLS>
821  constexpr
824 
825  for (std::size_t i = 0; i < ROWS; ++i) {
826  for (std::size_t j = 0; j < COLS; ++j) {
827  out(i,j) = lhs * rhs(i,j);
828  }
829  }
830 
831  return out;
832  }
833 
838  template<typename T, std::size_t ROWS, std::size_t COLS>
839  constexpr
842 
843  for (std::size_t i = 0; i < ROWS; ++i) {
844  for (std::size_t j = 0; j < COLS; ++j) {
845  out(i,j) = lhs(i,j) / rhs;
846  }
847  }
848 
849  return out;
850  }
851 
856  template<typename T, std::size_t ROWS, std::size_t COLS>
857  constexpr
859  for (std::size_t i = 0; i < ROWS; ++i) {
860  for (std::size_t j = 0; j < COLS; ++j) {
861  lhs(i,j) /= rhs;
862  }
863  }
864 
865  return lhs;
866  }
867 
872  template<typename T, std::size_t S1, std::size_t S2>
873  constexpr
875  Vector<T, S1> out = gf::Zero;
876 
877  for (std::size_t i = 0; i < S1; ++i) {
878  T val{0};
879 
880  for (std::size_t j = 0; j < S2; ++j) {
881  val += lhs(i,j) * rhs[j];
882  }
883 
884  out[i] = val;
885  }
886 
887  return out;
888  }
889 
894  template<typename T, std::size_t S1, std::size_t S2>
895  constexpr
897  Vector<T, S2> out = gf::Zero;
898 
899  for (std::size_t j = 0; j < S2; ++j) {
900  T val{0};
901 
902  for (std::size_t i = 0; i < S1; ++i) {
903  val += lhs[i] * rhs(i,j);
904  }
905 
906  out[j] = val;
907  }
908 
909  return out;
910  }
911 
912 
917  template<typename T, std::size_t S1, std::size_t S2, std::size_t S3>
918  constexpr
921 
922  for (std::size_t i = 0; i < S1; ++i) {
923  for (std::size_t j = 0; j < S3; ++j) {
924  T val{0};
925 
926  for (std::size_t k = 0; k < S2; ++k) {
927  val += lhs(i,k) * rhs(k,j);
928  }
929 
930  out(i,j) = val;
931  }
932  }
933 
934  return out;
935  }
936 
943  template<typename T, std::size_t N>
944  constexpr
946  lhs = lhs * rhs;
947  return lhs;
948  }
949 
950  /*
951  * usual operations
952  */
953 
960  template<typename MatrixType>
961  constexpr
962  MatrixType identity() {
963  static_assert(MatrixType::Rows == MatrixType::Cols, "identity() is only defined for square matrices.");
964 
965  MatrixType out = gf::Zero;
966 
967  typedef typename MatrixType::value_type value_type;
968 
969  for (std::size_t i = 0; i < MatrixType::Rows; ++i) {
970  for (std::size_t j = 0; j < MatrixType::Cols; ++j) {
971  out(i,j) = (i == j) ? value_type{1} : value_type{0};
972  }
973  }
974 
975  return out;
976  }
977 
982  template<typename T, std::size_t S1, std::size_t S2>
983  constexpr
986 
987  for (std::size_t i = 0; i < S1; ++i) {
988  for (std::size_t j = 0; j < S2; ++j) {
989  out(j,i) = mat(i,j);
990  }
991  }
992 
993  return out;
994  }
995 
996  // https://en.wikipedia.org/wiki/Invertible_matrix
997 
1002  template<typename T>
1003  constexpr
1005  Matrix<T, 2, 2> out = gf::Zero;
1006 
1007  out.xx = mat.yy;
1008  out.xy = - mat.xy;
1009  out.yx = - mat.yx;
1010  out.yy = mat.xx;
1011 
1012  T det = mat.xx * mat.yy - mat.yx * mat.xy;
1013  out /= det;
1014  return out;
1015  }
1016 
1021  template<typename T>
1022  constexpr
1024  Matrix<T, 3, 3> out = gf::Zero;
1025 
1026  out.xx = mat.yy * mat.zz - mat.zy * mat.yz;
1027  out.xy = - (mat.xy * mat.zz - mat.zy * mat.xz);
1028  out.xz = mat.xy * mat.yz - mat.yy * mat.xz;
1029  out.yx = - (mat.yx * mat.zz - mat.zx * mat.yz);
1030  out.yy = mat.xx * mat.zz - mat.zx * mat.xz;
1031  out.yz = - (mat.xx * mat.yz - mat.yx * mat.xz);
1032  out.zx = mat.yx * mat.zy - mat.zx * mat.yy;
1033  out.zy = - (mat.xx * mat.zy - mat.zx * mat.xy);
1034  out.zz = mat.xx * mat.yy - mat.yx * mat.xy;
1035 
1036  T det = mat.xx * out.xx + mat.xy * out.yx + mat.xz * out.zx;
1037  out /= det;
1038  return out;
1039  }
1040 
1041 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1042 }
1043 #endif
1044 }
1045 
1046 #endif // GAME_MATRIX_H
constexpr Matrix< T, ROWS, COLS > operator-(const Matrix< T, ROWS, COLS > &val)
Component-wise unary minus.
Definition: Matrix.h:693
const T * getData() const noexcept
Definition: Matrix.h:503
T m43
Definition: Matrix.h:610
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:521
T m13
Definition: Matrix.h:550
T m34
Definition: Matrix.h:595
T m44
Definition: Matrix.h:615
T m41
Definition: Matrix.h:600
T yx
Definition: Matrix.h:243
T m21
Definition: Matrix.h:244
T * getData() noexcept
Definition: Matrix.h:339
T m24
Definition: Matrix.h:575
T m42
Definition: Matrix.h:605
constexpr void zero() noexcept
Definition: Matrix.h:227
constexpr Matrix< T, ROWS, COLS > operator/(const Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar division.
Definition: Matrix.h:840
T xy
Definition: Matrix.h:544
T zz
Definition: Matrix.h:408
constexpr Matrix< T, ROWS, COLS > operator*(T lhs, const Matrix< T, ROWS, COLS > &rhs)
Left scalar multiplication.
Definition: Matrix.h:822
T yy
Definition: Matrix.h:388
T wz
Definition: Matrix.h:609
T xx
Definition: Matrix.h:368
constexpr void zero() noexcept
Zero out the matrix.
Definition: Matrix.h:115
constexpr Matrix< T, S2, S1 > transpose(const Matrix< T, S1, S2 > &mat)
Transposition of a matrix.
Definition: Matrix.h:984
T m13
Definition: Matrix.h:379
constexpr Vector< T, S2 > operator*(const Vector< T, S1 > &lhs, const Matrix< T, S1, S2 > &rhs)
Vector-matrix multiplication.
Definition: Matrix.h:896
constexpr Matrix< T, 2, 2 > invert(const Matrix< T, 2, 2 > &mat)
Inversion of a 2x2 matrix.
Definition: Matrix.h:1004
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:104
T m11
Definition: Matrix.h:540
T xy
Definition: Matrix.h:373
T zy
Definition: Matrix.h:584
constexpr Matrix(T e11, T e12, T e21, T e22) noexcept
Constructor that takes all the elements.
Definition: Matrix.h:196
constexpr Matrix(const T *array)
Definition: Matrix.h:306
constexpr Matrix< T, ROWS, COLS > operator-(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise substraction.
Definition: Matrix.h:750
T yx
Definition: Matrix.h:559
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:211
T * getData() noexcept
Definition: Matrix.h:507
T m23
Definition: Matrix.h:570
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:293
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:219
T zx
Definition: Matrix.h:579
constexpr Matrix< T, ROWS, COLS > operator*(const Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar multiplication.
Definition: Matrix.h:788
T m31
Definition: Matrix.h:399
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:169
constexpr MatrixType identity()
Identity matrix.
Definition: Matrix.h:962
T m32
Definition: Matrix.h:585
T wx
Definition: Matrix.h:599
constexpr Vector< T, S1 > operator*(const Matrix< T, S1, S2 > &lhs, const Vector< T, S2 > &rhs)
Matrix-vector multiplication.
Definition: Matrix.h:874
T xy
Definition: Matrix.h:238
T m21
Definition: Matrix.h:384
T m32
Definition: Matrix.h:404
T m14
Definition: Matrix.h:555
T yy
Definition: Matrix.h:248
T m22
Definition: Matrix.h:565
T yy
Definition: Matrix.h:564
General purpose math matrix.
Definition: Matrix.h:60
constexpr Matrix< T, ROWS, COLS > operator+(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise addition.
Definition: Matrix.h:715
constexpr Matrix< T, ROWS, COLS > & operator*=(Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar multiplication and assignment.
Definition: Matrix.h:806
T m12
Definition: Matrix.h:545
Matrix(T val) noexcept
Constructor that fills the matrix with a value.
Definition: Matrix.h:94
T zy
Definition: Matrix.h:403
float value_type
The value type of the elements of the matrix.
Definition: Matrix.h:69
T zw
Definition: Matrix.h:594
constexpr bool operator!=(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Inequality operator between two matrices.
Definition: Matrix.h:679
The namespace for gf classes.
Definition: Action.h:34
T yz
Definition: Matrix.h:569
constexpr Matrix(T e11, T e12, T e13, T e21, T e22, T e23, T e31, T e32, T e33) noexcept
Constructor that takes all the elements.
Definition: Matrix.h:327
T xz
Definition: Matrix.h:549
const T * getData() const noexcept
Definition: Matrix.h:335
T value_type
The value type of the elements of the matrix.
Definition: Matrix.h:434
T xz
Definition: Matrix.h:378
T m23
Definition: Matrix.h:394
constexpr void zero() noexcept
Definition: Matrix.h:361
T m31
Definition: Matrix.h:580
constexpr Matrix< T, ROWS, COLS > & operator/=(Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar division and assignment.
Definition: Matrix.h:858
T yw
Definition: Matrix.h:574
T xx
Definition: Matrix.h:233
T xx
Definition: Matrix.h:539
T m33
Definition: Matrix.h:590
T wy
Definition: Matrix.h:604
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:511
constexpr bool operator==(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Equality operator between two matrices.
Definition: Matrix.h:661
constexpr Matrix(T val) noexcept
Definition: Matrix.h:298
T value_type
The value type of the elements of the matrix.
Definition: Matrix.h:152
T zx
Definition: Matrix.h:398
constexpr Matrix< T, ROWS, COLS > & operator+=(Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise addition and assignment.
Definition: Matrix.h:733
constexpr Matrix(T e11, T e12, T e13, T e14, T e21, T e22, T e23, T e24, T e31, T e32, T e33, T e34, T e41, T e42, T e43, T e44) noexcept
Constructor that takes all the elements.
Definition: Matrix.h:494
T m12
Definition: Matrix.h:374
T m22
Definition: Matrix.h:389
T yz
Definition: Matrix.h:393
constexpr Matrix< T, N, N > & operator*=(Matrix< T, N, N > &lhs, const Matrix< T, N, N > &rhs)
Matrix-matrix multiplication and assignment.
Definition: Matrix.h:945
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:86
T zz
Definition: Matrix.h:589
T m22
Definition: Matrix.h:249
Matrix(const T *array)
Definition: Matrix.h:99
T m21
Definition: Matrix.h:560
T value_type
The value type of the elements of the matrix.
Definition: Matrix.h:276
constexpr Matrix< T, ROWS, COLS > & operator-=(Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise substraction and assignment.
Definition: Matrix.h:768
T m11
Definition: Matrix.h:234
T m12
Definition: Matrix.h:239
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:451
constexpr Matrix< T, S1, S3 > operator*(const Matrix< T, S1, S2 > &lhs, const Matrix< T, S2, S3 > &rhs)
Matrix-matrix multiplication.
Definition: Matrix.h:919
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:108
T m33
Definition: Matrix.h:409
General purpose math vector.
Definition: Vector.h:61
T m11
Definition: Matrix.h:369
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:343
T ww
Definition: Matrix.h:614
constexpr Matrix(const T *array)
Definition: Matrix.h:465
T * getData() noexcept
Definition: Matrix.h:207
T xw
Definition: Matrix.h:554
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:352
A 3x3 matrix.
Definition: Matrix.h:272
A 2x2 matrix.
Definition: Matrix.h:148
constexpr void zero() noexcept
Definition: Matrix.h:531
constexpr Matrix< T, 3, 3 > invert(const Matrix< T, 3, 3 > &mat)
Inversion of a 3x3 matrix.
Definition: Matrix.h:1023
T yx
Definition: Matrix.h:383
constexpr Matrix(const T *array)
Definition: Matrix.h:181
constexpr Matrix(T val) noexcept
Definition: Matrix.h:456
const T * getData() const noexcept
Definition: Matrix.h:203
constexpr Matrix(T val) noexcept
Definition: Matrix.h:174
Semantic type to represent "zero".
Definition: Types.h:69