t
|
The \(4 \times 4\) matrix class. More...
#include <Matrix4x4.hpp>
Public Member Functions | |
Matrix4x4 (double _n11, double _n12, double _n13, double _n14, double _n21, double _n22, double _n23, double _n24, double _n31, double _n32, double _n33, double _n34, double _n41, double _n42, double _n43, double _n44) | |
Creates a new \(4 \times 4\) matrix with the specified elements. | |
Matrix4x4 | clone () const |
Returns a copy of this matrix. | |
Matrix4x4 & | copy (const Matrix4x4 &source) |
Copies the elements of another \(4 \times 4\) matrix into this matrix. | |
Matrix4x4 & | set (double _n11, double _n12, double _n13, double _n14, double _n21, double _n22, double _n23, double _n24, double _n31, double _n32, double _n33, double _n34, double _n41, double _n42, double _n43, double _n44) |
Sets the elements of this matrix. | |
double | get (int row, int column) const |
Gets the element at the specified row and column of this matrix with bounds checking. | |
Matrix4x4 & | set (int row, int column, int value) |
Sets the element at the specified row and column of this matrix to the specified value. | |
Matrix4x4 & | reset () |
Resets this matrix to the \(4 \times 4\) identity matrix. | |
double | determinant () const |
Returns the determinant of this matrix. | |
Matrix4x4 | transpose () const |
Returns the transpose of this matrix. | |
Matrix4x4 | inverse () const |
Returns the inverse of this matrix or the zero matrix if this matrix does not have an inverse. | |
Matrix3x3 | topLeft3x3Matrix () const |
Returns the top-left \(3 \times 3\) matrix of this matrix. | |
double | operator[] (std::size_t index) const |
Returns the element at the specified index of this matrix without bounds checking and assuming row-major ordering. | |
Matrix4x4 & | operator+= (const Matrix4x4 &m) |
Adds the specified \(4 \times 4\) matrix to this matrix. | |
Matrix4x4 & | operator+= (double s) |
Adds the specified constant to all elements in this matrix. | |
Matrix4x4 & | operator-= (const Matrix4x4 &m) |
Substracts the specified \(4 \times 4\) matrix from this matrix. | |
Matrix4x4 & | operator-= (double s) |
Substracts the specified constant from all elements in this matrix. | |
Matrix4x4 & | operator*= (const Matrix4x4 &m) |
Multiplies this matrix with another \(4 \times 4\) matrix and copies the result into this instance. | |
Matrix4x4 & | operator*= (double s) |
Multiplies the elements of this matrix with the specified constant. | |
Matrix4x4 & | operator/= (const Matrix4x4 &m) |
Divides the elements of this matrix by the corresponding elements of the specified \(3 \times 3\) matrix. | |
Matrix4x4 & | operator/= (double s) |
Divides the elements of this matrix with the specified constant. | |
Static Public Member Functions | |
static Matrix4x4 | identity () |
Returns a \(4 \times 4\) identity matrix. | |
static Matrix4x4 | zero () |
Returns a \(4 \times 4\) zero matrix. | |
static Matrix4x4 | fromTranslation (const Vector3 &distance) |
Returns a translation matrix for the specified translation for post-multiplication ( \(V' = AV\) where \(V\) is the homogeneous coordinates and \(A\) is the transformation matrix). | |
static Matrix4x4 | fromRotation (const EulerRotation &angle) |
Returns a rotation matrix for the specified rotation for post-multiplication ( \(V' = AV\) where \(V\) is the homogeneous coordinates and \(A\) is the transformation matrix). | |
static Matrix4x4 | fromScale (const Vector3 &scaleFactor) |
Returns a scale matrix for the specified scale factor. | |
Public Attributes | |
std::array< double, 16 > | elements |
The array containing the elements of this matrix in row-major order. | |
Friends | |
bool | operator== (const Matrix4x4 &a, const Matrix4x4 &b)=default |
Returns whether two \(4 \times 4\) matrices are equal. | |
Matrix4x4 | operator+ (const Matrix4x4 &a, const Matrix4x4 &b) |
Adds two \(4 \times 4\) matrices. | |
Matrix4x4 | operator+ (const Matrix4x4 &a, double s) |
Adds a constant to all elements of a \(4 \times 4\) matrix. | |
Matrix4x4 | operator+ (double s, const Matrix4x4 &a) |
Adds a constant to all elements of a \(4 \times 4\) matrix. | |
Matrix4x4 | operator- (const Matrix4x4 &a, const Matrix4x4 &b) |
Substracts 2 \(4 \times 4\) matrices. | |
Matrix4x4 | operator- (const Matrix4x4 &a, double s) |
Substracts a constant from all elements of a \(4 \times 4\) matrix. | |
Matrix4x4 | operator- (double s, const Matrix4x4 &a) |
Substracts a \(4 \times 4\) matrix from a \(4 \times 4\) constant matrix. | |
Matrix4x4 | operator* (const Matrix4x4 &a, const Matrix4x4 &b) |
Multiplies two \(4 \times 4\) matrices. | |
Matrix4x4 | operator* (const Matrix4x4 &a, double s) |
Multiplies all elements of a \(4 \times 4\) matrix with a constant. | |
Matrix4x4 | operator* (double s, const Matrix4x4 &a) |
Multiplies all elements of a \(4 \times 4\) matrix with a constant. | |
Vector4 | operator* (const Matrix4x4 &a, const Vector4 &v) |
Multiplies a \(4 \times 4\) matrix with a four-dimensional vector. | |
Matrix4x4 | operator/ (const Matrix4x4 &a, const Matrix4x4 &b) |
Returns the element-wise division of two \(4 \times 4\) matrices. | |
Matrix4x4 | operator/ (const Matrix4x4 &a, double s) |
Divides all elements of a \(4 \times 4\) matrix by a constant. | |
Matrix4x4 | operator/ (double s, const Matrix4x4 &a) |
Returns the element-wise division of a \(4 \times 4\) constant matrix and a \(4 \times 4\) matrix. | |
The \(4 \times 4\) matrix class.
|
inline |
Creates a new \(4 \times 4\) matrix with the specified elements.
_n11 | The \((1, 1)\) element of the new matrix. |
_n12 | The \((1, 2)\) element of the new matrix. |
_n13 | The \((1, 3)\) element of the new matrix. |
_n14 | The \((1, 4)\) element of the new matrix. |
_n21 | The \((2, 1)\) element of the new matrix. |
_n22 | The \((2, 2)\) element of the new matrix. |
_n23 | The \((2, 3)\) element of the new matrix. |
_n24 | The \((2, 4)\) element of the new matrix. |
_n31 | The \((3, 1)\) element of the new matrix. |
_n32 | The \((3, 2)\) element of the new matrix. |
_n33 | The \((3, 3)\) element of the new matrix. |
_n34 | The \((3, 4)\) element of the new matrix. |
_n41 | The \((4, 1)\) element of the new matrix. |
_n42 | The \((4, 2)\) element of the new matrix. |
_n43 | The \((4, 3)\) element of the new matrix. |
_n44 | The \((4, 4)\) element of the new matrix. |
|
inline |
Returns a copy of this matrix.
Copies the elements of another \(4 \times 4\) matrix into this matrix.
source | The \(4 \times 4\) matrix to copy from. |
|
inline |
Returns the determinant of this matrix.
|
inlinestatic |
Returns a rotation matrix for the specified rotation for post-multiplication ( \(V' = AV\) where \(V\) is the homogeneous coordinates and \(A\) is the transformation matrix).
If you want to use pre-multiplication i.e. \(V' = VA\), transpose the returned matrix.
angle | An Euler rotation. |
angle
. Returns a scale matrix for the specified scale factor.
scaleFactor | The scale factor along the x, y, and z axes. |
scaleFactor
. Returns a translation matrix for the specified translation for post-multiplication ( \(V' = AV\) where \(V\) is the homogeneous coordinates and \(A\) is the transformation matrix).
If you want to use pre-multiplication i.e. \(V' = VA\), transpose the returned matrix.
distance | The distance to translate along the x, y, and z axes. |
distance
.
|
inline |
Gets the element at the specified row and column of this matrix with bounds checking.
row | The 0-based index of the row of the element. |
column | The 0-based index of the column of the element. |
operator[]
for accessing without bounds checking.
|
inlinestatic |
Returns a \(4 \times 4\) identity matrix.
|
inline |
Returns the inverse of this matrix or the zero matrix if this matrix does not have an inverse.
The inverse of a matrix \(A\) is the matrix \(A^{-1}\) such that \(AA^{-1} = I\) where \(I\) is the identity matrix. A matrix does not have an inverse if its determinant is zero.
Note that this method does not modify this instance.
Multiplies this matrix with another \(4 \times 4\) matrix and copies the result into this instance.
Note that this is not an element-wise multiplication, but matrix multiplication.
m | A \(4 \times 4\) matrix to multiply with. |
|
inline |
Multiplies the elements of this matrix with the specified constant.
s | A constant. |
Adds the specified \(4 \times 4\) matrix to this matrix.
m | A \(4 \times 4\) matrix. |
|
inline |
Adds the specified constant to all elements in this matrix.
s | A constant. |
Substracts the specified \(4 \times 4\) matrix from this matrix.
m | A \(4 \times 4\) matrix. |
|
inline |
Substracts the specified constant from all elements in this matrix.
s | A constant. |
Divides the elements of this matrix by the corresponding elements of the specified \(3 \times 3\) matrix.
m | A \(4 \times 4\) matrix. |
|
inline |
Divides the elements of this matrix with the specified constant.
s | A constant. |
|
inline |
Returns the element at the specified index of this matrix without bounds checking and assuming row-major ordering.
The element at row \(i\) and column \(j\) of this matrix has the index \(4i + j\) assuming \(i\) and \(j\) are zero-based.
index | The 0-based index of the element in row-major order. |
get
for accessing with bounds checking.
|
inline |
Resets this matrix to the \(4 \times 4\) identity matrix.
|
inline |
Sets the elements of this matrix.
_n11 | The new \((1, 1)\) element of this matrix. |
_n12 | The new \((1, 2)\) element of this matrix. |
_n13 | The new \((1, 3)\) element of this matrix. |
_n14 | The new \((1, 4)\) element of this matrix. |
_n21 | The new \((2, 1)\) element of this matrix. |
_n22 | The new \((2, 2)\) element of this matrix. |
_n23 | The new \((2, 3)\) element of this matrix. |
_n24 | The new \((2, 4)\) element of this matrix. |
_n31 | The new \((3, 1)\) element of this matrix. |
_n32 | The new \((3, 2)\) element of this matrix. |
_n33 | The new \((3, 3)\) element of this matrix. |
_n34 | The new \((3, 4)\) element of this matrix. |
_n41 | The new \((4, 1)\) element of this matrix. |
_n42 | The new \((4, 2)\) element of this matrix. |
_n43 | The new \((4, 3)\) element of this matrix. |
_n44 | The new \((4, 4)\) element of this matrix. |
|
inline |
Sets the element at the specified row and column of this matrix to the specified value.
row | The 0-based index of the row of the element. |
column | The 0-based index of the column of the element. |
value | The new value for the element. |
|
inline |
Returns the top-left \(3 \times 3\) matrix of this matrix.
For a transformation matrix, this method may be used to extract the rotation and scale components of the transformation, while discarding the translation component.
|
inline |
Returns the transpose of this matrix.
Note that this method does not modify this instance.
|
inlinestatic |
Returns a \(4 \times 4\) zero matrix.
Multiplies two \(4 \times 4\) matrices.
Note that this is not an element-wise multiplication, but matrix multiplication.
a | A \(4 \times 4\) matrix. |
b | Another \(4 \times 4\) matrix. |
a
and b
. Multiplies a \(4 \times 4\) matrix with a four-dimensional vector.
a | A \(4 \times 4\) matrix. |
v | A four-dimensional vector. |
a
and v
. Multiplies all elements of a \(4 \times 4\) matrix with a constant.
a | A \(4 \times 4\) matrix. |
s | A constant. |
a
with s
. Multiplies all elements of a \(4 \times 4\) matrix with a constant.
s | A constant. |
a | A \(4 \times 4\) matrix. |
a
with s
. Adds two \(4 \times 4\) matrices.
a | A \(4 \times 4\) matrix. |
b | Another \(4 \times 4\) matrix. |
a
and b
. Adds a constant to all elements of a \(4 \times 4\) matrix.
a | A \(4 \times 4\) matrix. |
s | A constant. |
s
to all elements of a
. Adds a constant to all elements of a \(4 \times 4\) matrix.
s | A constant. |
a | A \(4 \times 4\) matrix. |
s
to all elements of a
. Substracts 2 \(4 \times 4\) matrices.
a | A \(4 \times 4\) matrix. |
b | Another \(4 \times 4\) matrix. |
a
and b
. Substracts a constant from all elements of a \(4 \times 4\) matrix.
a | A \(4 \times 4\) matrix. |
s | A constant. |
s
from all elements of a
. Substracts a \(4 \times 4\) matrix from a \(4 \times 4\) constant matrix.
s | A constant for a \(4 \times 4\) constant matrix. |
a | A \(4 \times 4\) matrix. |
a
from the constant matrix of s
. Returns the element-wise division of two \(4 \times 4\) matrices.
a | A \(4 \times 4\) matrix. |
b | Another \(4 \times 4\) matrix. |
a
and b
. Divides all elements of a \(4 \times 4\) matrix by a constant.
a | A \(4 \times 4\) matrix. |
s | A constant. |
a
by s
. Returns the element-wise division of a \(4 \times 4\) constant matrix and a \(4 \times 4\) matrix.
s | A constant for a \(4 \times 4\) constant matrix. |
a | Another \(4 \times 4\) matrix. |
a
. Returns whether two \(4 \times 4\) matrices are equal.
a | A \(4 \times 4\) matrix. |
b | Another \(4 \times 4\) matrix. |
true
if a
equals b
, false
otherwise.