Gamedev Framework (gf)  0.3.0
A C++11 framework for 2D games
Matrix.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016 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 
30 namespace gf {
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 inline namespace v1 {
33 #endif
34 
35  /**
36  * @ingroup core
37  * @brief General purpose math matrix
38  *
39  * gf::Matrix represents a matrix with `ROWS` rows and `COLS` columns. The
40  * internal representation uses a [row-major order](https://en.wikipedia.org/wiki/Row-major_order).
41  *
42  * The template parameter `T` is the type of coordinates. . It can be any
43  * type that supports arithmetic operations (+, -, *, /).
44  *
45  * Several specializations are defined for common use cases, especially for
46  * [square matrices](https://en.wikipedia.org/wiki/Square_matrix):
47  *
48  * - For dimension 2: gf::Matrix<T, 2, 2>
49  * - For dimension 3: gf::Matrix<T, 3, 3>
50  * - For dimension 4: gf::Matrix<T, 4, 4>
51  *
52  * This class was designed according to the article
53  * [On Vector Math Libraries](http://www.reedbeta.com/blog/2013/12/28/on-vector-math-libraries/)
54  * by Nathan Reed.
55  *
56  * @sa gf::Array2D
57  */
58  template<typename T, std::size_t ROWS, std::size_t COLS>
59  struct Matrix {
60  #ifndef DOXYGEN_SHOULD_SKIP_THIS
61  static_assert(ROWS > 0, "ROWS must be strictly positive");
62  static_assert(COLS > 0, "COLS must be strictly positive");
63  #endif
64 
65  /**
66  * @brief The value type of the elements of the matrix
67  */
68  using value_type = T;
69 
70  /**
71  * @brief The number of rows in the matrix
72  */
73  static constexpr std::size_t Rows = ROWS;
74 
75  /**
76  * @brief The number of columns in the matrix
77  */
78  static constexpr std::size_t Cols = COLS;
79 
80  /**
81  * @brief Default constructor
82  */
83  Matrix() = default;
84 
85  /**
86  * @brief Constructor that fills the matrix with a value.
87  */
88  explicit Matrix(T val) {
89  std::fill_n(data, ROWS * COLS, val);
90  }
91 
92  /**
93  * An anonymous union to handle the various representations
94  */
95  union {
96  T grid[ROWS][COLS]; ///< Grid representation
97  T data[ROWS * COLS]; ///< Array representation
98  };
99  };
100 
101  /**
102  * @ingroup core
103  * @brief A 2x2 matrix
104  *
105  * This specialization of gf::Matrix handles linear transformation of 2D
106  * vectors. As translation is not a linear transformation but an affine
107  * transformation, this specialization is not used in the library. Instead
108  * use a gf::Matrix<T, 3, 3>. It is provided for convinience.
109  *
110  * Each element of the matrix can be accessed through a name with a double
111  * letter indicating the column and row of the element (e.g. `xy` indicates
112  * the first row and second column).
113  *
114  * A common typedef is defined:
115  *
116  * - gf::Matrix2f with `float` as `T`
117  */
118  template<typename T>
119  struct Matrix<T, 2, 2> {
120  /**
121  * @brief The value type of the elements of the matrix
122  */
123  using value_type = T;
124 
125  /**
126  * @brief The number of rows in the matrix
127  */
128  static constexpr std::size_t Rows = 2;
129 
130  /**
131  * @brief The number of columns in the matrix
132  */
133  static constexpr std::size_t Cols = 2;
134 
135  /**
136  * @brief Default constructor
137  */
138  Matrix() = default;
139 
140  /**
141  * @brief Constructor that takes all the elements
142  *
143  * @param xx The element in the first row and first column
144  * @param xy The element in the first row and second column
145  * @param yx The element in the second row and first column
146  * @param yy The element in the second row and second column
147  */
148  constexpr Matrix(T xx, T xy, T yx, T yy)
149  : data{xx, xy, yx, yy}
150  {
151 
152  }
153 
154  /**
155  * An anonymous union to handle the various representations
156  */
157  union {
158  T grid[2][2]; ///< Grid representation
159  T data[4]; ///< Array representation
160  struct {
161  T xx, xy;
162  T yx, yy;
163  };
164  };
165  };
166 
167  /**
168  * @ingroup core
169  * @brief A 3x3 matrix
170  *
171  * This specialization of gf::Matrix handles affine transformation of 2D
172  * vectors (using homogeneous coordinates).
173  *
174  * Each element of the matrix can be accessed through a name with a double
175  * letter indicating the column and row of the element (e.g. `xy` indicates
176  * the first row and second column).
177  *
178  * A common typedef is defined:
179  *
180  * - gf::Matrix3f with `float` as `T`
181  *
182  * @sa transform, translate, translation, rotate, rotation, scale, scaling
183  */
184  template<typename T>
185  struct Matrix<T, 3, 3> {
186  /**
187  * @brief The value type of the elements of the matrix
188  */
189  using value_type = T;
190 
191  /**
192  * @brief The number of rows in the matrix
193  */
194  static constexpr std::size_t Rows = 3;
195 
196  /**
197  * @brief The number of columns in the matrix
198  */
199  static constexpr std::size_t Cols = 3;
200 
201  /**
202  * @brief Default constructor
203  */
204  Matrix() = default;
205 
206  /**
207  * @brief Constructor that takes all the elements
208  *
209  * @param xx The element in the first row and first column
210  * @param xy The element in the first row and second column
211  * @param xz The element in the first row and third column
212  * @param yx The element in the second row and first column
213  * @param yy The element in the second row and second column
214  * @param yz The element in the second row and third column
215  * @param zx The element in the third row and first column
216  * @param zy The element in the third row and second column
217  * @param zz The element in the third row and third column
218  */
219  constexpr Matrix(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
220  : data{xx, xy, xz, yx, yy, yz, zx, zy, zz}
221  {
222 
223  }
224 
225  /**
226  * An anonymous union to handle the various representations
227  */
228  union {
229  T grid[3][3]; ///< Grid representation
230  T data[9]; ///< Array representation
231  struct {
232  T xx, xy, xz;
233  T yx, yy, yz;
234  T zx, zy, zz;
235  };
236  };
237  };
238 
239  /**
240  * @ingroup core
241  * @brief A 4x4 matrix
242  *
243  * This specialization of gf::Matrix handles affine transformation of 3D
244  * vectors (using homogeneous coordinates).
245  *
246  * Each element of the matrix can be accessed through a name with a double
247  * letter indicating the column and row of the element (e.g. `xy` indicates
248  * the first row and second column).
249  *
250  * A common typedef is defined:
251  *
252  * - gf::Matrix4f with `float` as `T`
253  */
254  template<typename T>
255  struct Matrix<T, 4, 4> {
256  /**
257  * @brief The value type of the elements of the matrix
258  */
259  using value_type = T;
260 
261  /**
262  * @brief The number of rows in the matrix
263  */
264  static constexpr std::size_t Rows = 4;
265 
266  /**
267  * @brief The number of columns in the matrix
268  */
269  static constexpr std::size_t Cols = 4;
270 
271  /**
272  * @brief Constructor that takes all the elements
273  *
274  * @param xx The element in the first row and first column
275  * @param xy The element in the first row and second column
276  * @param xz The element in the first row and third column
277  * @param xw The element in the first row and fourth column
278  * @param yx The element in the second row and first column
279  * @param yy The element in the second row and second column
280  * @param yz The element in the second row and third column
281  * @param yw The element in the second row and fourth column
282  * @param zx The element in the third row and first column
283  * @param zy The element in the third row and second column
284  * @param zz The element in the third row and third column
285  * @param zw The element in the third row and fourth column
286  * @param wx The element in the fourth row and first column
287  * @param wy The element in the fourth row and second column
288  * @param wz The element in the fourth row and third column
289  * @param ww The element in the fourth row and fourth column
290  */
291  constexpr Matrix(T xx, T xy, T xz, T xw, T yx, T yy, T yz, T yw, T zx, T zy, T zz, T zw, T wx, T wy, T wz, T ww)
292  : data{xx, xy, xz, xw, yx, yy, yz, yw, zx, zy, zz, zw, wx, wy, wz, ww}
293  {
294 
295  }
296 
297  /**
298  * An anonymous union to handle the various representations
299  */
300  union {
301  T grid[4][4]; ///< Grid representation
302  T data[16]; ///< Array representation
303  struct {
304  T xx, xy, xz, xw;
305  T yx, yy, yz, yw;
306  T zx, zy, zz, zw;
307  T wx, wy, wz, ww;
308  };
309  };
310  };
311 
312  /**
313  * @ingroup core
314  * @brief A float square matrix of size 2
315  *
316  * @sa Matrix<T, 2, 2>
317  */
318  using Matrix2f = Matrix<float, 2, 2>;
319 
320  /**
321  * @ingroup core
322  * @brief A float square matrix of size 3
323  *
324  * @sa Matrix<T, 3, 3>
325  */
326  using Matrix3f = Matrix<float, 3, 3>;
327 
328  /**
329  * @ingroup core
330  * @brief A float square matrix of size 4
331  *
332  * @sa Matrix<T, 4, 4>
333  */
334  using Matrix4f = Matrix<float, 4, 4>;
335 
336 // MSVC does not like extern template
337 #ifndef _MSC_VER
338  extern template struct Matrix<float, 2, 2>;
339  extern template struct Matrix<float, 3, 3>;
340  extern template struct Matrix<float, 4, 4>;
341 #endif
342 
343  /*
344  * equality operations
345  */
346 
347  /**
348  * @relates Matrix
349  * @brief Equality operator between two matrices
350  */
351  template<typename T, std::size_t ROWS, std::size_t COLS>
352  inline
353  bool operator==(const Matrix<T, ROWS, COLS>& lhs, const Matrix<T, ROWS, COLS>& rhs) {
354  for (std::size_t i = 0; i < ROWS; ++i) {
355  for (std::size_t j = 0; j < COLS; ++j) {
356  if (lhs.grid[i][j] != rhs.grid[i][j]) {
357  return false;
358  }
359  }
360  }
361 
362  return true;
363  }
364 
365  /**
366  * @relates Matrix
367  * @brief Inequality operator between two matrices
368  */
369  template<typename T, std::size_t ROWS, std::size_t COLS>
370  inline
371  bool operator!=(const Matrix<T, ROWS, COLS>& lhs, const Matrix<T, ROWS, COLS>& rhs) {
372  return !(lhs == rhs);
373  }
374 
375  /*
376  * unary operators
377  */
378 
379  /**
380  * @relates Matrix
381  * @brief Component-wise unary minus
382  */
383  template<typename T, std::size_t ROWS, std::size_t COLS>
384  inline
385  Matrix<T, ROWS, COLS> operator-(const Matrix<T, ROWS, COLS>& val) {
386  Matrix<T, ROWS, COLS> out;
387 
388  for (std::size_t i = 0; i < ROWS; ++i) {
389  for (std::size_t j = 0; j < COLS; ++j) {
390  out.grid[i][j] = - val.grid[i][j];
391  }
392  }
393 
394  return out;
395  }
396 
397  /*
398  * arithmetic component-wise operations
399  */
400 
401  /**
402  * @relates Matrix
403  * @brief Component-wise addition
404  */
405  template<typename T, std::size_t ROWS, std::size_t COLS>
406  inline
407  Matrix<T, ROWS, COLS> operator+(const Matrix<T, ROWS, COLS>& lhs, const Matrix<T, ROWS, COLS>& rhs) {
408  Matrix<T, ROWS, COLS> out;
409 
410  for (std::size_t i = 0; i < ROWS; ++i) {
411  for (std::size_t j = 0; j < COLS; ++j) {
412  out.grid[i][j] = lhs.grid[i][j] + rhs.grid[i][j];
413  }
414  }
415 
416  return out;
417  }
418 
419  /**
420  * @relates Matrix
421  * @brief Component-wise addition and assignment
422  */
423  template<typename T, std::size_t ROWS, std::size_t COLS>
424  inline
425  Matrix<T, ROWS, COLS>& operator+=(Matrix<T, ROWS, COLS>& lhs, const Matrix<T, ROWS, COLS>& rhs) {
426  for (std::size_t i = 0; i < ROWS; ++i) {
427  for (std::size_t j = 0; j < COLS; ++j) {
428  lhs.grid[i][j] += rhs.grid[i][j];
429  }
430  }
431 
432  return lhs;
433  }
434 
435 
436  /**
437  * @relates Matrix
438  * @brief Component-wise substraction
439  */
440  template<typename T, std::size_t ROWS, std::size_t COLS>
441  inline
442  Matrix<T, ROWS, COLS> operator-(const Matrix<T, ROWS, COLS>& lhs, const Matrix<T, ROWS, COLS>& rhs) {
443  Matrix<T, ROWS, COLS> out;
444 
445  for (std::size_t i = 0; i < ROWS; ++i) {
446  for (std::size_t j = 0; j < COLS; ++j) {
447  out.grid[i][j] = lhs.grid[i][j] - rhs.grid[i][j];
448  }
449  }
450 
451  return out;
452  }
453 
454  /**
455  * @relates Matrix
456  * @brief Component-wise substraction and assignment
457  */
458  template<typename T, std::size_t ROWS, std::size_t COLS>
459  inline
460  Matrix<T, ROWS, COLS>& operator-=(Matrix<T, ROWS, COLS>& lhs, const Matrix<T, ROWS, COLS>& rhs) {
461  for (std::size_t i = 0; i < ROWS; ++i) {
462  for (std::size_t j = 0; j < COLS; ++j) {
463  lhs.grid[i][j] -= rhs.grid[i][j];
464  }
465  }
466 
467  return lhs;
468  }
469 
470  /*
471  * multiplication and division
472  */
473 
474  /**
475  * @relates Matrix
476  * @brief Right scalar multiplication
477  */
478  template<typename T, std::size_t ROWS, std::size_t COLS>
479  inline
480  Matrix<T, ROWS, COLS> operator*(const Matrix<T, ROWS, COLS>& lhs, T rhs) {
481  Matrix<T, ROWS, COLS> out;
482 
483  for (std::size_t i = 0; i < ROWS; ++i) {
484  for (std::size_t j = 0; j < COLS; ++j) {
485  out.grid[i][j] = lhs.grid[i][j] * rhs;
486  }
487  }
488 
489  return out;
490  }
491 
492  /**
493  * @relates Matrix
494  * @brief Right scalar multiplication and assignment
495  */
496  template<typename T, std::size_t ROWS, std::size_t COLS>
497  inline
498  Matrix<T, ROWS, COLS>& operator*=(Matrix<T, ROWS, COLS>& lhs, T rhs) {
499  for (std::size_t i = 0; i < ROWS; ++i) {
500  for (std::size_t j = 0; j < COLS; ++j) {
501  lhs.grid[i][j] *= rhs;
502  }
503  }
504 
505  return lhs;
506  }
507 
508  /**
509  * @relates Matrix
510  * @brief Left scalar multiplication
511  */
512  template<typename T, std::size_t ROWS, std::size_t COLS>
513  inline
514  Matrix<T, ROWS, COLS> operator*(T lhs, const Matrix<T, ROWS, COLS>& rhs) {
515  Matrix<T, ROWS, COLS> out;
516 
517  for (std::size_t i = 0; i < ROWS; ++i) {
518  for (std::size_t j = 0; j < COLS; ++j) {
519  out.grid[i][j] = lhs * rhs.grid[i][j];
520  }
521  }
522 
523  return out;
524  }
525 
526  /**
527  * @relates Matrix
528  * @brief Right scalar division
529  */
530  template<typename T, std::size_t ROWS, std::size_t COLS>
531  inline
532  Matrix<T, ROWS, COLS> operator/(const Matrix<T, ROWS, COLS>& lhs, T rhs) {
533  Matrix<T, ROWS, COLS> out;
534 
535  for (std::size_t i = 0; i < ROWS; ++i) {
536  for (std::size_t j = 0; j < COLS; ++j) {
537  out.grid[i][j] = lhs.grid[i][j] / rhs;
538  }
539  }
540 
541  return out;
542  }
543 
544  /**
545  * @relates Matrix
546  * @brief Right scalar division and assignment
547  */
548  template<typename T, std::size_t ROWS, std::size_t COLS>
549  inline
550  Matrix<T, ROWS, COLS>& operator/=(Matrix<T, ROWS, COLS>& lhs, T rhs) {
551  for (std::size_t i = 0; i < ROWS; ++i) {
552  for (std::size_t j = 0; j < COLS; ++j) {
553  lhs.grid[i][j] /= rhs;
554  }
555  }
556 
557  return lhs;
558  }
559 
560  /**
561  * @relates Matrix
562  * @brief Matrix-vector multiplication
563  */
564  template<typename T, std::size_t S1, std::size_t S2>
565  inline
566  Vector<T, S1> operator*(const Matrix<T, S1, S2>& lhs, const Vector<T, S2>& rhs) {
567  Vector<T, S1> out;
568 
569  for (std::size_t i = 0; i < S1; ++i) {
570  T val{0};
571 
572  for (std::size_t j = 0; j < S2; ++j) {
573  val += lhs.grid[i][j] * rhs.data[j];
574  }
575 
576  out.data[i] = val;
577  }
578 
579  return out;
580  }
581 
582  /**
583  * @relates Matrix
584  * @brief Vector-matrix multiplication
585  */
586  template<typename T, std::size_t S1, std::size_t S2>
587  inline
588  Vector<T, S2> operator*(const Vector<T, S1>& lhs, const Matrix<T, S1, S2>& rhs) {
589  Vector<T, S2> out;
590 
591  for (std::size_t j = 0; j < S2; ++j) {
592  T val{0};
593 
594  for (std::size_t i = 0; i < S1; ++i) {
595  val += lhs.data[i] * rhs.grid[i][j];
596  }
597 
598  out.data[j] = val;
599  }
600 
601  return out;
602  }
603 
604 
605  /**
606  * @relates Matrix
607  * @brief Matrix-matrix multiplication
608  */
609  template<typename T, std::size_t S1, std::size_t S2, std::size_t S3>
610  inline
611  Matrix<T, S1, S3> operator*(const Matrix<T, S1, S2>& lhs, const Matrix<T, S2, S3>& rhs) {
612  Matrix<T, S1, S3> out;
613 
614  for (std::size_t i = 0; i < S1; ++i) {
615  for (std::size_t j = 0; j < S3; ++j) {
616  T val{0};
617 
618  for (std::size_t k = 0; k < S2; ++k) {
619  val += lhs.grid[i][k] * rhs.grid[k][j];
620  }
621 
622  out.grid[i][j] = val;
623  }
624  }
625 
626  return out;
627  }
628 
629  /**
630  * @relates Matrix
631  * @brief Matrix-matrix multiplication and assignment
632  *
633  * This operation is only available for square matrices.
634  */
635  template<typename T, std::size_t N>
636  inline
637  Matrix<T, N, N>& operator*=(Matrix<T, N, N>& lhs, const Matrix<T, N, N>& rhs) {
638  lhs = lhs * rhs;
639  return lhs;
640  }
641 
642  /*
643  * usual operations
644  */
645 
646  /**
647  * @relates Matrix
648  * @brief Identity matrix
649  *
650  * @sa gf::identityTransform()
651  */
652  template<typename MatrixType>
653  inline
654  MatrixType identity() {
655  static_assert(MatrixType::Rows == MatrixType::Cols, "identity() is only defined for square matrices.");
656 
657  MatrixType out;
658 
659  typedef typename MatrixType::value_type value_type;
660 
661  for (std::size_t i = 0; i < MatrixType::Rows; ++i) {
662  for (std::size_t j = 0; j < MatrixType::Cols; ++j) {
663  out.grid[i][j] = (i == j) ? value_type{1} : value_type{0};
664  }
665  }
666 
667  return out;
668  }
669 
670  /**
671  * @relates Matrix
672  * @brief Transposition of a matrix
673  */
674  template<typename T, std::size_t S1, std::size_t S2>
675  inline
676  Matrix<T, S2, S1> transpose(const Matrix<T, S1, S2>& mat) {
677  Matrix<T, S2, S1> out;
678 
679  for (std::size_t i = 0; i < S1; ++i) {
680  for (std::size_t j = 0; j < S2; ++j) {
681  out.grid[j][i] = mat.grid[i][j];
682  }
683  }
684 
685  return out;
686  }
687 
688  // https://en.wikipedia.org/wiki/Invertible_matrix
689 
690  /**
691  * @relates Matrix
692  * @brief Inversion of a 2x2 matrix
693  */
694  template<typename T>
695  inline
696  Matrix<T, 2, 2> invert(const Matrix<T, 2, 2>& mat) {
697  Matrix<T, 2, 2> out;
698 
699  out.xx = mat.yy;
700  out.xy = - mat.xy;
701  out.yx = - mat.yx;
702  out.yy = mat.xx;
703 
704  T det = mat.xx * mat.yy - mat.yx * mat.xy;
705  out /= det;
706  return out;
707  }
708 
709  /**
710  * @relates Matrix
711  * @brief Inversion of a 3x3 matrix
712  */
713  template<typename T>
714  inline
715  Matrix<T, 3, 3> invert(const Matrix<T, 3, 3>& mat) {
716  Matrix<T, 3, 3> out;
717 
718  out.xx = mat.yy * mat.zz - mat.zy * mat.yz;
719  out.xy = - (mat.xy * mat.zz - mat.zy * mat.xz);
720  out.xz = mat.xy * mat.yz - mat.yy * mat.xz;
721  out.yx = - (mat.yx * mat.zz - mat.zx * mat.yz);
722  out.yy = mat.xx * mat.zz - mat.zx * mat.xz;
723  out.yz = - (mat.xx * mat.yz - mat.yx * mat.xz);
724  out.zx = mat.yx * mat.zy - mat.zx * mat.yy;
725  out.zy = - (mat.xx * mat.zy - mat.zx * mat.xy);
726  out.zz = mat.xx * mat.yy - mat.yx * mat.xy;
727 
728  T det = mat.xx * out.xx + mat.xy * out.yx + mat.xz * out.zx;
729  out /= det;
730  return out;
731  }
732 
733 #ifndef DOXYGEN_SHOULD_SKIP_THIS
734 }
735 #endif
736 }
737 
738 #endif // GAME_MATRIX_H
static constexpr std::size_t Rows
The number of rows in the matrix.
Definition: Matrix.h:128
Matrix< T, 3, 3 > invert(const Matrix< T, 3, 3 > &mat)
Inversion of a 3x3 matrix.
Definition: Matrix.h:715
Matrix< T, S2, S1 > transpose(const Matrix< T, S1, S2 > &mat)
Transposition of a matrix.
Definition: Matrix.h:676
bool operator==(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Equality operator between two matrices.
Definition: Matrix.h:353
Matrix< T, ROWS, COLS > operator+(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise addition.
Definition: Matrix.h:407
Matrix< T, ROWS, COLS > operator*(T lhs, const Matrix< T, ROWS, COLS > &rhs)
Left scalar multiplication.
Definition: Matrix.h:514
Matrix< T, 2, 2 > invert(const Matrix< T, 2, 2 > &mat)
Inversion of a 2x2 matrix.
Definition: Matrix.h:696
Matrix< T, ROWS, COLS > & operator/=(Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar division and assignment.
Definition: Matrix.h:550
constexpr Matrix(T xx, T xy, T yx, T yy)
Constructor that takes all the elements.
Definition: Matrix.h:148
bool operator!=(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Inequality operator between two matrices.
Definition: Matrix.h:371
MatrixType identity()
Identity matrix.
Definition: Matrix.h:654
Vector< T, S2 > operator*(const Vector< T, S1 > &lhs, const Matrix< T, S1, S2 > &rhs)
Vector-matrix multiplication.
Definition: Matrix.h:588
friend class RenderTarget
Definition: Shader.h:387
Matrix(T val)
Constructor that fills the matrix with a value.
Definition: Matrix.h:88
Matrix< T, ROWS, COLS > & operator-=(Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise substraction and assignment.
Definition: Matrix.h:460
Matrix< T, ROWS, COLS > operator-(const Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise substraction.
Definition: Matrix.h:442
Matrix< T, ROWS, COLS > operator/(const Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar division.
Definition: Matrix.h:532
Vector< T, S1 > operator*(const Matrix< T, S1, S2 > &lhs, const Vector< T, S2 > &rhs)
Matrix-vector multiplication.
Definition: Matrix.h:566
Matrix< T, S1, S3 > operator*(const Matrix< T, S1, S2 > &lhs, const Matrix< T, S2, S3 > &rhs)
Matrix-matrix multiplication.
Definition: Matrix.h:611
static constexpr std::size_t Rows
The number of rows in the matrix.
Definition: Matrix.h:264
Matrix()=default
Default constructor.
General purpose math matrix.
Definition: Matrix.h:59
Definition: Action.h:34
static constexpr std::size_t Cols
The number of columns in the matrix.
Definition: Matrix.h:269
Matrix()=default
Default constructor.
static constexpr std::size_t Cols
The number of columns in the matrix.
Definition: Matrix.h:78
Matrix< T, ROWS, COLS > & operator*=(Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar multiplication and assignment.
Definition: Matrix.h:498
constexpr Matrix(T xx, T xy, T xz, T yx, T yy, T yz, T zx, T zy, T zz)
Constructor that takes all the elements.
Definition: Matrix.h:219
Matrix< T, N, N > & operator*=(Matrix< T, N, N > &lhs, const Matrix< T, N, N > &rhs)
Matrix-matrix multiplication and assignment.
Definition: Matrix.h:637
Matrix< T, ROWS, COLS > & operator+=(Matrix< T, ROWS, COLS > &lhs, const Matrix< T, ROWS, COLS > &rhs)
Component-wise addition and assignment.
Definition: Matrix.h:425
static constexpr std::size_t Cols
The number of columns in the matrix.
Definition: Matrix.h:133
Matrix()=default
Default constructor.
Matrix< T, ROWS, COLS > operator-(const Matrix< T, ROWS, COLS > &val)
Component-wise unary minus.
Definition: Matrix.h:385
static constexpr std::size_t Rows
The number of rows in the matrix.
Definition: Matrix.h:73
General purpose math vector.
Definition: Vector.h:60
constexpr Matrix(T xx, T xy, T xz, T xw, T yx, T yy, T yz, T yw, T zx, T zy, T zz, T zw, T wx, T wy, T wz, T ww)
Constructor that takes all the elements.
Definition: Matrix.h:291
Matrix< T, ROWS, COLS > operator*(const Matrix< T, ROWS, COLS > &lhs, T rhs)
Right scalar multiplication.
Definition: Matrix.h:480
static constexpr std::size_t Cols
The number of columns in the matrix.
Definition: Matrix.h:199
static constexpr std::size_t Rows
The number of rows in the matrix.
Definition: Matrix.h:194