Gamedev Framework (gf)  0.12.0
A C++14 framework for 2D games
Matrix.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2019 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 
651 
659 
667 
668 // MSVC does not like extern template
669 #ifndef _MSC_VER
670  extern template struct GF_API Matrix<float, 2, 2>;
671  extern template struct GF_API Matrix<float, 3, 3>;
672  extern template struct GF_API Matrix<float, 4, 4>;
673 
674  extern template struct GF_API Matrix<double, 2, 2>;
675  extern template struct GF_API Matrix<double, 3, 3>;
676  extern template struct GF_API Matrix<double, 4, 4>;
677 #endif
678 
679  /*
680  * equality operations
681  */
682 
687  template<typename T, std::size_t ROWS, std::size_t COLS>
688  constexpr
690  for (std::size_t i = 0; i < ROWS; ++i) {
691  for (std::size_t j = 0; j < COLS; ++j) {
692  if (lhs(i,j) != rhs(i,j)) {
693  return false;
694  }
695  }
696  }
697 
698  return true;
699  }
700 
705  template<typename T, std::size_t ROWS, std::size_t COLS>
706  constexpr
708  return !(lhs == rhs);
709  }
710 
711  /*
712  * unary operators
713  */
714 
719  template<typename T, std::size_t ROWS, std::size_t COLS>
720  constexpr
723 
724  for (std::size_t i = 0; i < ROWS; ++i) {
725  for (std::size_t j = 0; j < COLS; ++j) {
726  out(i,j) = - val(i,j);
727  }
728  }
729 
730  return out;
731  }
732 
733  /*
734  * arithmetic component-wise operations
735  */
736 
741  template<typename T, std::size_t ROWS, std::size_t COLS>
742  constexpr
745 
746  for (std::size_t i = 0; i < ROWS; ++i) {
747  for (std::size_t j = 0; j < COLS; ++j) {
748  out(i,j) = lhs(i,j) + rhs(i,j);
749  }
750  }
751 
752  return out;
753  }
754 
759  template<typename T, std::size_t ROWS, std::size_t COLS>
760  constexpr
762  for (std::size_t i = 0; i < ROWS; ++i) {
763  for (std::size_t j = 0; j < COLS; ++j) {
764  lhs(i,j) += rhs(i,j);
765  }
766  }
767 
768  return lhs;
769  }
770 
771 
776  template<typename T, std::size_t ROWS, std::size_t COLS>
777  constexpr
780 
781  for (std::size_t i = 0; i < ROWS; ++i) {
782  for (std::size_t j = 0; j < COLS; ++j) {
783  out(i,j) = lhs(i,j) - rhs(i,j);
784  }
785  }
786 
787  return out;
788  }
789 
794  template<typename T, std::size_t ROWS, std::size_t COLS>
795  constexpr
797  for (std::size_t i = 0; i < ROWS; ++i) {
798  for (std::size_t j = 0; j < COLS; ++j) {
799  lhs(i,j) -= rhs(i,j);
800  }
801  }
802 
803  return lhs;
804  }
805 
806  /*
807  * multiplication and division
808  */
809 
814  template<typename T, std::size_t ROWS, std::size_t COLS>
815  constexpr
818 
819  for (std::size_t i = 0; i < ROWS; ++i) {
820  for (std::size_t j = 0; j < COLS; ++j) {
821  out(i,j) = lhs(i,j) * rhs;
822  }
823  }
824 
825  return out;
826  }
827 
832  template<typename T, std::size_t ROWS, std::size_t COLS>
833  constexpr
835  for (std::size_t i = 0; i < ROWS; ++i) {
836  for (std::size_t j = 0; j < COLS; ++j) {
837  lhs(i,j) *= rhs;
838  }
839  }
840 
841  return lhs;
842  }
843 
848  template<typename T, std::size_t ROWS, std::size_t COLS>
849  constexpr
852 
853  for (std::size_t i = 0; i < ROWS; ++i) {
854  for (std::size_t j = 0; j < COLS; ++j) {
855  out(i,j) = lhs * rhs(i,j);
856  }
857  }
858 
859  return out;
860  }
861 
866  template<typename T, std::size_t ROWS, std::size_t COLS>
867  constexpr
870 
871  for (std::size_t i = 0; i < ROWS; ++i) {
872  for (std::size_t j = 0; j < COLS; ++j) {
873  out(i,j) = lhs(i,j) / rhs;
874  }
875  }
876 
877  return out;
878  }
879 
884  template<typename T, std::size_t ROWS, std::size_t COLS>
885  constexpr
887  for (std::size_t i = 0; i < ROWS; ++i) {
888  for (std::size_t j = 0; j < COLS; ++j) {
889  lhs(i,j) /= rhs;
890  }
891  }
892 
893  return lhs;
894  }
895 
900  template<typename T, std::size_t S1, std::size_t S2>
901  constexpr
903  Vector<T, S1> out = gf::Zero;
904 
905  for (std::size_t i = 0; i < S1; ++i) {
906  T val{0};
907 
908  for (std::size_t j = 0; j < S2; ++j) {
909  val += lhs(i,j) * rhs[j];
910  }
911 
912  out[i] = val;
913  }
914 
915  return out;
916  }
917 
922  template<typename T, std::size_t S1, std::size_t S2>
923  constexpr
925  Vector<T, S2> out = gf::Zero;
926 
927  for (std::size_t j = 0; j < S2; ++j) {
928  T val{0};
929 
930  for (std::size_t i = 0; i < S1; ++i) {
931  val += lhs[i] * rhs(i,j);
932  }
933 
934  out[j] = val;
935  }
936 
937  return out;
938  }
939 
940 
945  template<typename T, std::size_t S1, std::size_t S2, std::size_t S3>
946  constexpr
949 
950  for (std::size_t i = 0; i < S1; ++i) {
951  for (std::size_t j = 0; j < S3; ++j) {
952  T val{0};
953 
954  for (std::size_t k = 0; k < S2; ++k) {
955  val += lhs(i,k) * rhs(k,j);
956  }
957 
958  out(i,j) = val;
959  }
960  }
961 
962  return out;
963  }
964 
971  template<typename T, std::size_t N>
972  constexpr
974  lhs = lhs * rhs;
975  return lhs;
976  }
977 
978  /*
979  * usual operations
980  */
981 
988  template<typename MatrixType>
989  constexpr
990  MatrixType identity() {
991  static_assert(MatrixType::Rows == MatrixType::Cols, "identity() is only defined for square matrices.");
992 
993  MatrixType out = gf::Zero;
994 
995  typedef typename MatrixType::value_type value_type;
996 
997  for (std::size_t i = 0; i < MatrixType::Rows; ++i) {
998  for (std::size_t j = 0; j < MatrixType::Cols; ++j) {
999  out(i,j) = (i == j) ? value_type{1} : value_type{0};
1000  }
1001  }
1002 
1003  return out;
1004  }
1005 
1010  template<typename T, std::size_t S1, std::size_t S2>
1011  constexpr
1014 
1015  for (std::size_t i = 0; i < S1; ++i) {
1016  for (std::size_t j = 0; j < S2; ++j) {
1017  out(j,i) = mat(i,j);
1018  }
1019  }
1020 
1021  return out;
1022  }
1023 
1024  // https://en.wikipedia.org/wiki/Invertible_matrix
1025 
1030  template<typename T>
1031  constexpr
1033  Matrix<T, 2, 2> out = gf::Zero;
1034 
1035  out.xx = mat.yy;
1036  out.xy = - mat.xy;
1037  out.yx = - mat.yx;
1038  out.yy = mat.xx;
1039 
1040  T det = mat.xx * mat.yy - mat.yx * mat.xy;
1041  out /= det;
1042  return out;
1043  }
1044 
1049  template<typename T>
1050  constexpr
1052  Matrix<T, 3, 3> out = gf::Zero;
1053 
1054  out.xx = mat.yy * mat.zz - mat.zy * mat.yz;
1055  out.xy = - (mat.xy * mat.zz - mat.zy * mat.xz);
1056  out.xz = mat.xy * mat.yz - mat.yy * mat.xz;
1057  out.yx = - (mat.yx * mat.zz - mat.zx * mat.yz);
1058  out.yy = mat.xx * mat.zz - mat.zx * mat.xz;
1059  out.yz = - (mat.xx * mat.yz - mat.yx * mat.xz);
1060  out.zx = mat.yx * mat.zy - mat.zx * mat.yy;
1061  out.zy = - (mat.xx * mat.zy - mat.zx * mat.xy);
1062  out.zz = mat.xx * mat.yy - mat.yx * mat.xy;
1063 
1064  T det = mat.xx * out.xx + mat.xy * out.yx + mat.xz * out.zx;
1065  out /= det;
1066  return out;
1067  }
1068 
1069 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1070 }
1071 #endif
1072 }
1073 
1074 #endif // GAME_MATRIX_H
constexpr Matrix< T, ROWS, COLS > operator-(const Matrix< T, ROWS, COLS > &val)
Component-wise unary minus.
Definition: Matrix.h:721
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:868
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:850
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:1012
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:924
constexpr Matrix< T, 2, 2 > invert(const Matrix< T, 2, 2 > &mat)
Inversion of a 2x2 matrix.
Definition: Matrix.h:1032
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:778
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:816
T m31
Definition: Matrix.h:399
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:169
constexpr MatrixType identity()
Identity matrix.
Definition: Matrix.h:990
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:902
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:743
constexpr Matrix< T, ROWS, COLS > & operator*=(Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar multiplication and assignment.
Definition: Matrix.h:834
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:707
The namespace for gf classes.
Definition: Action.h:35
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:886
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:689
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:761
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:973
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:796
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:947
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:1051
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