Gamedev Framework (gf)  0.17.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  explicit constexpr Matrix(const T *array)
181  : m11(array[0]), m12(array[1])
182  , m21(array[2]), m22(array[3])
183  {
184  }
185 
194  constexpr Matrix(T e11, T e12, T e21, T e22) noexcept
195  : m11(e11), m12(e12)
196  , m21(e21), m22(e22)
197  {
198  }
199 
200  const T *getData() const noexcept {
201  return &m11;
202  }
203 
204  T *getData() noexcept {
205  return &m11;
206  }
207 
208  T operator()(std::size_t row, std::size_t col) const {
209  const T *grid[Rows][Cols] = {
210  { &m11, &m12 },
211  { &m21, &m22 }
212  };
213  return *grid[row][col];
214  }
215 
216  T& operator()(std::size_t row, std::size_t col) {
217  T *grid[Rows][Cols] = {
218  { &m11, &m12 },
219  { &m21, &m22 }
220  };
221  return *grid[row][col];
222  }
223 
224  constexpr void zero() noexcept {
225  m11 = m12 = T{};
226  m21 = m22 = T{};
227  }
228 
229  union {
230  T xx;
232  };
233 
234  union {
235  T xy;
237  };
238 
239  union {
240  T yx;
242  };
243 
244  union {
245  T yy;
247  };
248  };
249 
267  template<typename T>
268  struct Matrix<T, 3, 3> {
272  using value_type = T;
273 
277  static constexpr std::size_t Rows = 3;
278 
282  static constexpr std::size_t Cols = 3;
283 
287  Matrix() = default;
288 
289  constexpr Matrix(ZeroType) noexcept
290  {
291  zero();
292  }
293 
294  explicit constexpr Matrix(T val) noexcept
295  : m11(val), m12(val), m13(val)
296  , m21(val), m22(val), m23(val)
297  , m31(val), m32(val), m33(val)
298  {
299  }
300 
301  explicit constexpr Matrix(const T *array)
302  : m11(array[0]), m12(array[1]), m13(array[2])
303  , m21(array[3]), m22(array[4]), m23(array[5])
304  , m31(array[6]), m32(array[7]), m33(array[8])
305  {
306  }
307 
321  constexpr Matrix(T e11, T e12, T e13, T e21, T e22, T e23, T e31, T e32, T e33) noexcept
322  : m11(e11), m12(e12), m13(e13)
323  , m21(e21), m22(e22), m23(e23)
324  , m31(e31), m32(e32), m33(e33)
325  {
326  }
327 
328  const T *getData() const noexcept {
329  return &m11;
330  }
331 
332  T *getData() noexcept {
333  return &m11;
334  }
335 
336  T operator()(std::size_t row, std::size_t col) const {
337  const T *grid[Rows][Cols] = {
338  { &m11, &m12, &m13 },
339  { &m21, &m22, &m23 },
340  { &m31, &m32, &m33 }
341  };
342  return *grid[row][col];
343  }
344 
345  T& operator()(std::size_t row, std::size_t col) {
346  T *grid[Rows][Cols] = {
347  { &m11, &m12, &m13 },
348  { &m21, &m22, &m23 },
349  { &m31, &m32, &m33 }
350  };
351  return *grid[row][col];
352  }
353 
354  constexpr void zero() noexcept {
355  m11 = m12 = m13 = T{};
356  m21 = m22 = m23 = T{};
357  m31 = m32 = m33 = T{};
358  }
359 
360  union {
361  T xx;
363  };
364 
365  union {
366  T xy;
368  };
369 
370  union {
371  T xz;
373  };
374 
375  union {
376  T yx;
378  };
379 
380  union {
381  T yy;
383  };
384 
385  union {
386  T yz;
388  };
389 
390  union {
391  T zx;
393  };
394 
395  union {
396  T zy;
398  };
399 
400  union {
401  T zz;
403  };
404  };
405 
421  template<typename T>
422  struct Matrix<T, 4, 4> {
426  using value_type = T;
427 
431  static constexpr std::size_t Rows = 4;
432 
436  static constexpr std::size_t Cols = 4;
437 
441  Matrix() = default;
442 
443  constexpr Matrix(ZeroType) noexcept
444  {
445  zero();
446  }
447 
448  explicit constexpr Matrix(T val) noexcept
449  : m11(val), m12(val), m13(val), m14(val)
450  , m21(val), m22(val), m23(val), m24(val)
451  , m31(val), m32(val), m33(val), m34(val)
452  , m41(val), m42(val), m43(val), m44(val)
453  {
454  }
455 
456  explicit constexpr Matrix(const T *array)
457  : m11(array[ 0]), m12(array[ 1]), m13(array[ 2]), m14(array[ 3])
458  , m21(array[ 4]), m22(array[ 5]), m23(array[ 6]), m24(array[ 7])
459  , m31(array[ 8]), m32(array[ 9]), m33(array[10]), m34(array[11])
460  , m41(array[12]), m42(array[13]), m43(array[14]), m44(array[15])
461  {
462  }
463 
484  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
485  : m11(e11), m12(e12), m13(e13), m14(e14)
486  , m21(e21), m22(e22), m23(e23), m24(e24)
487  , m31(e31), m32(e32), m33(e33), m34(e34)
488  , m41(e41), m42(e42), m43(e43), m44(e44)
489  {
490  }
491 
492  const T *getData() const noexcept {
493  return &m11;
494  }
495 
496  T *getData() noexcept {
497  return &m11;
498  }
499 
500  T operator()(std::size_t row, std::size_t col) const {
501  const T *grid[Rows][Cols] = {
502  { &m11, &m12, &m13, &m14 },
503  { &m21, &m22, &m23, &m24 },
504  { &m31, &m32, &m33, &m34 },
505  { &m41, &m42, &m43, &m44 }
506  };
507  return *grid[row][col];
508  }
509 
510  T& operator()(std::size_t row, std::size_t col) {
511  T *grid[Rows][Cols] = {
512  { &m11, &m12, &m13, &m14 },
513  { &m21, &m22, &m23, &m24 },
514  { &m31, &m32, &m33, &m34 },
515  { &m41, &m42, &m43, &m44 }
516  };
517  return *grid[row][col];
518  }
519 
520  constexpr void zero() noexcept {
521  m11 = m12 = m13 = m14 = T{};
522  m21 = m22 = m23 = m24 = T{};
523  m31 = m32 = m33 = m34 = T{};
524  m41 = m42 = m43 = m44 = T{};
525  }
526 
527  union {
528  T xx;
530  };
531 
532  union {
533  T xy;
535  };
536 
537  union {
538  T xz;
540  };
541 
542  union {
543  T xw;
545  };
546 
547  union {
548  T yx;
550  };
551 
552  union {
553  T yy;
555  };
556 
557  union {
558  T yz;
560  };
561 
562  union {
563  T yw;
565  };
566 
567  union {
568  T zx;
570  };
571 
572  union {
573  T zy;
575  };
576 
577  union {
578  T zz;
580  };
581 
582  union {
583  T zw;
585  };
586 
587  union {
588  T wx;
590  };
591 
592  union {
593  T wy;
595  };
596 
597  union {
598  T wz;
600  };
601 
602  union {
603  T ww;
605  };
606  };
607 
615 
623 
631 
639 
647 
655 
656 // MSVC does not like extern template
657 #ifndef _MSC_VER
658  extern template struct GF_API Matrix<float, 2, 2>;
659  extern template struct GF_API Matrix<float, 3, 3>;
660  extern template struct GF_API Matrix<float, 4, 4>;
661 
662  extern template struct GF_API Matrix<double, 2, 2>;
663  extern template struct GF_API Matrix<double, 3, 3>;
664  extern template struct GF_API Matrix<double, 4, 4>;
665 #endif
666 
667  /*
668  * equality operations
669  */
670 
675  template<typename T, std::size_t ROWS, std::size_t COLS>
676  constexpr
678  for (std::size_t i = 0; i < ROWS; ++i) {
679  for (std::size_t j = 0; j < COLS; ++j) {
680  if (lhs(i,j) != rhs(i,j)) {
681  return false;
682  }
683  }
684  }
685 
686  return true;
687  }
688 
693  template<typename T, std::size_t ROWS, std::size_t COLS>
694  constexpr
696  return !(lhs == rhs);
697  }
698 
699  /*
700  * unary operators
701  */
702 
707  template<typename T, std::size_t ROWS, std::size_t COLS>
708  constexpr
711 
712  for (std::size_t i = 0; i < ROWS; ++i) {
713  for (std::size_t j = 0; j < COLS; ++j) {
714  out(i,j) = - val(i,j);
715  }
716  }
717 
718  return out;
719  }
720 
721  /*
722  * arithmetic component-wise operations
723  */
724 
729  template<typename T, std::size_t ROWS, std::size_t COLS>
730  constexpr
733 
734  for (std::size_t i = 0; i < ROWS; ++i) {
735  for (std::size_t j = 0; j < COLS; ++j) {
736  out(i,j) = lhs(i,j) + rhs(i,j);
737  }
738  }
739 
740  return out;
741  }
742 
747  template<typename T, std::size_t ROWS, std::size_t COLS>
748  constexpr
750  for (std::size_t i = 0; i < ROWS; ++i) {
751  for (std::size_t j = 0; j < COLS; ++j) {
752  lhs(i,j) += rhs(i,j);
753  }
754  }
755 
756  return lhs;
757  }
758 
759 
764  template<typename T, std::size_t ROWS, std::size_t COLS>
765  constexpr
768 
769  for (std::size_t i = 0; i < ROWS; ++i) {
770  for (std::size_t j = 0; j < COLS; ++j) {
771  out(i,j) = lhs(i,j) - rhs(i,j);
772  }
773  }
774 
775  return out;
776  }
777 
782  template<typename T, std::size_t ROWS, std::size_t COLS>
783  constexpr
785  for (std::size_t i = 0; i < ROWS; ++i) {
786  for (std::size_t j = 0; j < COLS; ++j) {
787  lhs(i,j) -= rhs(i,j);
788  }
789  }
790 
791  return lhs;
792  }
793 
794  /*
795  * multiplication and division
796  */
797 
802  template<typename T, std::size_t ROWS, std::size_t COLS>
803  constexpr
806 
807  for (std::size_t i = 0; i < ROWS; ++i) {
808  for (std::size_t j = 0; j < COLS; ++j) {
809  out(i,j) = lhs(i,j) * rhs;
810  }
811  }
812 
813  return out;
814  }
815 
820  template<typename T, std::size_t ROWS, std::size_t COLS>
821  constexpr
823  for (std::size_t i = 0; i < ROWS; ++i) {
824  for (std::size_t j = 0; j < COLS; ++j) {
825  lhs(i,j) *= rhs;
826  }
827  }
828 
829  return lhs;
830  }
831 
836  template<typename T, std::size_t ROWS, std::size_t COLS>
837  constexpr
840 
841  for (std::size_t i = 0; i < ROWS; ++i) {
842  for (std::size_t j = 0; j < COLS; ++j) {
843  out(i,j) = lhs * rhs(i,j);
844  }
845  }
846 
847  return out;
848  }
849 
854  template<typename T, std::size_t ROWS, std::size_t COLS>
855  constexpr
858 
859  for (std::size_t i = 0; i < ROWS; ++i) {
860  for (std::size_t j = 0; j < COLS; ++j) {
861  out(i,j) = lhs(i,j) / rhs;
862  }
863  }
864 
865  return out;
866  }
867 
872  template<typename T, std::size_t ROWS, std::size_t COLS>
873  constexpr
875  for (std::size_t i = 0; i < ROWS; ++i) {
876  for (std::size_t j = 0; j < COLS; ++j) {
877  lhs(i,j) /= rhs;
878  }
879  }
880 
881  return lhs;
882  }
883 
888  template<typename T, std::size_t S1, std::size_t S2>
889  constexpr
891  Vector<T, S1> out = gf::Zero;
892 
893  for (std::size_t i = 0; i < S1; ++i) {
894  T val{0};
895 
896  for (std::size_t j = 0; j < S2; ++j) {
897  val += lhs(i,j) * rhs[j];
898  }
899 
900  out[i] = val;
901  }
902 
903  return out;
904  }
905 
910  template<typename T, std::size_t S1, std::size_t S2>
911  constexpr
913  Vector<T, S2> out = gf::Zero;
914 
915  for (std::size_t j = 0; j < S2; ++j) {
916  T val{0};
917 
918  for (std::size_t i = 0; i < S1; ++i) {
919  val += lhs[i] * rhs(i,j);
920  }
921 
922  out[j] = val;
923  }
924 
925  return out;
926  }
927 
928 
933  template<typename T, std::size_t S1, std::size_t S2, std::size_t S3>
934  constexpr
937 
938  for (std::size_t i = 0; i < S1; ++i) {
939  for (std::size_t j = 0; j < S3; ++j) {
940  T val{0};
941 
942  for (std::size_t k = 0; k < S2; ++k) {
943  val += lhs(i,k) * rhs(k,j);
944  }
945 
946  out(i,j) = val;
947  }
948  }
949 
950  return out;
951  }
952 
959  template<typename T, std::size_t N>
960  constexpr
962  lhs = lhs * rhs;
963  return lhs;
964  }
965 
966  /*
967  * usual operations
968  */
969 
976  template<typename MatrixType>
977  constexpr
978  MatrixType identity() {
979  static_assert(MatrixType::Rows == MatrixType::Cols, "identity() is only defined for square matrices.");
980 
981  MatrixType out = gf::Zero;
982 
983  typedef typename MatrixType::value_type value_type;
984 
985  for (std::size_t i = 0; i < MatrixType::Rows; ++i) {
986  for (std::size_t j = 0; j < MatrixType::Cols; ++j) {
987  out(i,j) = (i == j) ? value_type{1} : value_type{0};
988  }
989  }
990 
991  return out;
992  }
993 
998  template<typename T, std::size_t S1, std::size_t S2>
999  constexpr
1002 
1003  for (std::size_t i = 0; i < S1; ++i) {
1004  for (std::size_t j = 0; j < S2; ++j) {
1005  out(j,i) = mat(i,j);
1006  }
1007  }
1008 
1009  return out;
1010  }
1011 
1012  // https://en.wikipedia.org/wiki/Invertible_matrix
1013 
1018  template<typename T>
1019  constexpr
1021  Matrix<T, 2, 2> out = gf::Zero;
1022 
1023  out.xx = mat.yy;
1024  out.xy = - mat.xy;
1025  out.yx = - mat.yx;
1026  out.yy = mat.xx;
1027 
1028  T det = mat.xx * mat.yy - mat.yx * mat.xy;
1029  out /= det;
1030  return out;
1031  }
1032 
1037  template<typename T>
1038  constexpr
1040  Matrix<T, 3, 3> out = gf::Zero;
1041 
1042  out.xx = mat.yy * mat.zz - mat.zy * mat.yz;
1043  out.xy = - (mat.xy * mat.zz - mat.zy * mat.xz);
1044  out.xz = mat.xy * mat.yz - mat.yy * mat.xz;
1045  out.yx = - (mat.yx * mat.zz - mat.zx * mat.yz);
1046  out.yy = mat.xx * mat.zz - mat.zx * mat.xz;
1047  out.yz = - (mat.xx * mat.yz - mat.yx * mat.xz);
1048  out.zx = mat.yx * mat.zy - mat.zx * mat.yy;
1049  out.zy = - (mat.xx * mat.zy - mat.zx * mat.xy);
1050  out.zz = mat.xx * mat.yy - mat.yx * mat.xy;
1051 
1052  T det = mat.xx * out.xx + mat.xy * out.yx + mat.xz * out.zx;
1053  out /= det;
1054  return out;
1055  }
1056 
1057 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1058 }
1059 #endif
1060 }
1061 
1062 #endif // GAME_MATRIX_H
constexpr Matrix< T, ROWS, COLS > operator-(const Matrix< T, ROWS, COLS > &val)
Component-wise unary minus.
Definition: Matrix.h:709
const T * getData() const noexcept
Definition: Matrix.h:492
T m43
Definition: Matrix.h:599
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:510
T m13
Definition: Matrix.h:539
T m34
Definition: Matrix.h:584
T m44
Definition: Matrix.h:604
T m41
Definition: Matrix.h:589
T yx
Definition: Matrix.h:240
T m21
Definition: Matrix.h:241
T * getData() noexcept
Definition: Matrix.h:332
T m24
Definition: Matrix.h:564
T m42
Definition: Matrix.h:594
constexpr void zero() noexcept
Definition: Matrix.h:224
constexpr Matrix< T, ROWS, COLS > operator/(const Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar division.
Definition: Matrix.h:856
T xy
Definition: Matrix.h:533
T zz
Definition: Matrix.h:401
constexpr Matrix< T, ROWS, COLS > operator*(T lhs, const Matrix< T, ROWS, COLS > &rhs)
Left scalar multiplication.
Definition: Matrix.h:838
T yy
Definition: Matrix.h:381
T wz
Definition: Matrix.h:598
T xx
Definition: Matrix.h:361
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:1000
T m13
Definition: Matrix.h:372
constexpr Vector< T, S2 > operator*(const Vector< T, S1 > &lhs, const Matrix< T, S1, S2 > &rhs)
Vector-matrix multiplication.
Definition: Matrix.h:912
constexpr Matrix< T, 2, 2 > invert(const Matrix< T, 2, 2 > &mat)
Inversion of a 2x2 matrix.
Definition: Matrix.h:1020
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:104
T m11
Definition: Matrix.h:529
T xy
Definition: Matrix.h:366
T zy
Definition: Matrix.h:573
constexpr Matrix(T e11, T e12, T e21, T e22) noexcept
Constructor that takes all the elements.
Definition: Matrix.h:194
constexpr Matrix(const T *array)
Definition: Matrix.h:301
constexpr Matrix< T, ROWS, COLS > operator-(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise substraction.
Definition: Matrix.h:766
T yx
Definition: Matrix.h:548
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:208
T * getData() noexcept
Definition: Matrix.h:496
T m23
Definition: Matrix.h:559
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:289
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:216
T zx
Definition: Matrix.h:568
constexpr Matrix< T, ROWS, COLS > operator*(const Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar multiplication.
Definition: Matrix.h:804
T m31
Definition: Matrix.h:392
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:169
constexpr MatrixType identity()
Identity matrix.
Definition: Matrix.h:978
T m32
Definition: Matrix.h:574
T wx
Definition: Matrix.h:588
constexpr Vector< T, S1 > operator*(const Matrix< T, S1, S2 > &lhs, const Vector< T, S2 > &rhs)
Matrix-vector multiplication.
Definition: Matrix.h:890
T xy
Definition: Matrix.h:235
T m21
Definition: Matrix.h:377
T m32
Definition: Matrix.h:397
T m14
Definition: Matrix.h:544
T yy
Definition: Matrix.h:245
T m22
Definition: Matrix.h:554
T yy
Definition: Matrix.h:553
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:731
constexpr Matrix< T, ROWS, COLS > & operator*=(Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar multiplication and assignment.
Definition: Matrix.h:822
T m12
Definition: Matrix.h:534
Matrix(T val) noexcept
Constructor that fills the matrix with a value.
Definition: Matrix.h:94
T zy
Definition: Matrix.h:396
float value_type
The value type of the elements of the matrix.
Definition: Matrix.h:69
T zw
Definition: Matrix.h:583
constexpr bool operator!=(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Inequality operator between two matrices.
Definition: Matrix.h:695
The namespace for gf classes.
Definition: Action.h:35
T yz
Definition: Matrix.h:558
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:321
T xz
Definition: Matrix.h:538
const T * getData() const noexcept
Definition: Matrix.h:328
T value_type
The value type of the elements of the matrix.
Definition: Matrix.h:426
T xz
Definition: Matrix.h:371
T m23
Definition: Matrix.h:387
constexpr void zero() noexcept
Definition: Matrix.h:354
T m31
Definition: Matrix.h:569
constexpr Matrix< T, ROWS, COLS > & operator/=(Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar division and assignment.
Definition: Matrix.h:874
T yw
Definition: Matrix.h:563
T xx
Definition: Matrix.h:230
T xx
Definition: Matrix.h:528
T m33
Definition: Matrix.h:579
T wy
Definition: Matrix.h:593
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:500
constexpr bool operator==(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Equality operator between two matrices.
Definition: Matrix.h:677
constexpr Matrix(T val) noexcept
Definition: Matrix.h:294
T value_type
The value type of the elements of the matrix.
Definition: Matrix.h:152
T zx
Definition: Matrix.h:391
constexpr ArrayRef< T > array(const T *data, std::size_t size)
Create a constant reference to an array.
Definition: ArrayRef.h:204
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:749
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:484
T m12
Definition: Matrix.h:367
T m22
Definition: Matrix.h:382
T yz
Definition: Matrix.h:386
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:961
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:86
T zz
Definition: Matrix.h:578
T m22
Definition: Matrix.h:246
Matrix(const T *array)
Definition: Matrix.h:99
T m21
Definition: Matrix.h:549
T value_type
The value type of the elements of the matrix.
Definition: Matrix.h:272
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:784
T m11
Definition: Matrix.h:231
T m12
Definition: Matrix.h:236
constexpr Matrix(ZeroType) noexcept
Definition: Matrix.h:443
constexpr Matrix< T, S1, S3 > operator*(const Matrix< T, S1, S2 > &lhs, const Matrix< T, S2, S3 > &rhs)
Matrix-matrix multiplication.
Definition: Matrix.h:935
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:108
T m33
Definition: Matrix.h:402
General purpose math vector.
Definition: Vector.h:61
T m11
Definition: Matrix.h:362
T operator()(std::size_t row, std::size_t col) const
Definition: Matrix.h:336
T ww
Definition: Matrix.h:603
constexpr Matrix(const T *array)
Definition: Matrix.h:456
T * getData() noexcept
Definition: Matrix.h:204
T xw
Definition: Matrix.h:543
T & operator()(std::size_t row, std::size_t col)
Definition: Matrix.h:345
A 3x3 matrix.
Definition: Matrix.h:268
A 2x2 matrix.
Definition: Matrix.h:148
constexpr void zero() noexcept
Definition: Matrix.h:520
constexpr Matrix< T, 3, 3 > invert(const Matrix< T, 3, 3 > &mat)
Inversion of a 3x3 matrix.
Definition: Matrix.h:1039
T yx
Definition: Matrix.h:376
constexpr Matrix(const T *array)
Definition: Matrix.h:180
constexpr Matrix(T val) noexcept
Definition: Matrix.h:448
const T * getData() const noexcept
Definition: Matrix.h:200
constexpr Matrix(T val) noexcept
Definition: Matrix.h:174
Semantic type to represent "zero".
Definition: Types.h:85