3es
0.7
|
A row major 4x4 transformation matrix. More...
#include <3esmatrix4.h>
Public Member Functions | |
Matrix4 () | |
Empty constructor; contents are undefined. | |
Matrix4 (const T *array16) | |
Array initialisation constructor from an array of at least 16 elements. More... | |
Matrix4 (const Matrix4< T > &other) | |
Copy constructor. More... | |
template<typename Q > | |
Matrix4 (const Matrix4< Q > &other) | |
Copy constructor from a different numeric type. More... | |
Matrix4 (const T &rc00, const T &rc01, const T &rc02, const T &rc03, const T &rc10, const T &rc11, const T &rc12, const T &rc13, const T &rc20, const T &rc21, const T &rc22, const T &rc23, const T &rc30, const T &rc31, const T &rc32, const T &rc33) | |
Per element constructor, specifying each row in order. More... | |
T & | operator() (int r, int c) |
Row/column access. More... | |
const T & | operator() (int r, int c) const |
Row/column immutable access. More... | |
T & | operator[] (int index) |
Indexing operator (no bounds checking). More... | |
const T & | operator[] (int index) const |
Indexing operator (no bounds checking). More... | |
Matrix4< T > & | initRotationX (const T &angle) |
Initialise this matrix as a rotation around the X axis. More... | |
Matrix4< T > & | initRotationY (const T &angle) |
Initialise this matrix as a rotation around the Y axis. More... | |
Matrix4< T > & | initRotationZ (const T &angle) |
Initialise this matrix as a rotation around the Z axis. More... | |
Matrix4< T > & | initRotation (const T &x, const T &y, const T &z) |
Initialise this matrix as a rotation using the given Euler angles. More... | |
Matrix4< T > | initTranslation (const Vector3< T > &trans) |
Initialise this matrix as a translation only matrix. More... | |
Matrix4< T > & | initRotationTranslation (const T &x, const T &y, const T &z, const Vector3< T > &trans) |
Matrix4< T > & | initScaling (const Vector3< T > &scale) |
Initialise this matrix as scaling matrix with no rotation or translation. More... | |
Matrix4< T > & | initLookAt (const Vector3< T > &eye, const Vector3< T > &target, const Vector3< T > &axisUp, int forwardAxisIndex=1, int upAxisIndex=2) |
Initialise this matrix as a model or camera matrix. More... | |
Matrix4< T > & | transpose () |
Transposes this matrix. More... | |
Matrix4< T > | transposed () const |
Returns the transpose of this matrix, leaving this matrix unchanged. More... | |
Matrix4< T > & | invert () |
Inverts this matrix. More... | |
Matrix4< T > | inverse () const |
Returns the inverse of this matrix, leaving this matrix unchanged. More... | |
Matrix4< T > & | rigidBodyInvert () |
Inverts this matrix assuming this matrix represents a rigid body transformation. More... | |
Matrix4< T > | rigidBodyInverse () const |
Returns the inverse of this matrix assuming this is a rigid body transformation. More... | |
T | determinant () const |
Calculates the determinant of this matrix. More... | |
Vector3< T > | axisX () const |
Returns the X axis of this matrix (elements (0, 0), (1, 0), (2, 0)). More... | |
Vector3< T > | axisY () const |
Returns the Y axis of this matrix (elements (0, 1), (1, 1), (2, 1)). More... | |
Vector3< T > | axisZ () const |
Returns the Z axis of this matrix (elements (0, 2), (1, 2), (2, 2)). More... | |
Vector3< T > | axisT () const |
Returns the T axis or translation component of this matrix (elements (0, 3), (1, 3), (2, 3)). More... | |
Vector3< T > | translation () const |
Returns the T axis or translation component of this matrix (elements (0, 3), (1, 3), (2, 3)). More... | |
Vector3< T > | axis (int index) const |
Returns one of the axes of this matrix. More... | |
Matrix4< T > & | setAxisX (const Vector3< T > &axis) |
Sets the X axis of this matrix. More... | |
Matrix4< T > & | setAxisY (const Vector3< T > &axis) |
Sets the Y axis of this matrix. More... | |
Matrix4< T > & | setAxisZ (const Vector3< T > &axis) |
Sets the Z axis of this matrix. More... | |
Matrix4< T > & | setAxisT (const Vector3< T > &axis) |
Sets the translation of this matrix. More... | |
Matrix4< T > & | setTranslation (const Vector3< T > &axis) |
Sets the translation of this matrix. More... | |
Matrix4< T > & | setAxis (int index, const Vector3< T > &axis) |
Sets the indexed axis of this matrix. More... | |
Vector3< T > | scale () const |
Returns the scale contained in this matrix. More... | |
Vector3< T > | removeScale () |
Removes scale from the matrix, leaving a rotation/translation matrix. More... | |
Matrix4< T > & | scale (const Vector3< T > &scaling) |
Scales this matrix, adjusting the scale of each rotation, but leaving the translation. More... | |
Vector3< T > | transform (const Vector3< T > &v) const |
Transforms the vector v by this matrix. More... | |
Vector4< T > | transform (const Vector4< T > &v) const |
Transforms the vector v by this matrix. More... | |
Vector3< T > | rotate (const Vector3< T > &v) const |
Transforms the vector v by the rotation component of this matrix. More... | |
Vector4< T > | rotate (const Vector4< T > &v) const |
Transforms the vector v by the rotation component of this matrix. More... | |
Static Public Member Functions | |
static Matrix4< T > | rotationX (const T &angle) |
Create a matrix which represents a rotation around the X axis. More... | |
static Matrix4< T > | rotationY (const T &angle) |
Create a matrix which represents a rotation around the Y axis. More... | |
static Matrix4< T > | rotationZ (const T &angle) |
Create a matrix which represents a rotation around the Z axis. More... | |
static Matrix4< T > | rotation (const T &x, const T &y, const T &z) |
Create a matrix which represents a rotation around each axis (Euler angles). More... | |
static Matrix4< T > | translation (const Vector3< T > &trans) |
Create a translation matrix (no rotation). More... | |
static Matrix4< T > | rotationTranslation (const T &x, const T &y, const T &z, const Vector3< T > &trans) |
Create a transformation matrix with rotation (Euler angles) and translation. More... | |
static Matrix4< T > | scaling (const Vector3< T > &scale) |
Create a scaling matrix. More... | |
static Matrix4< T > | lookAt (const Vector3< T > &eye, const Vector3< T > &target, const Vector3< T > &axisUp, int forwardAxisIndex=1, int upAxisIndex=2) |
Create a model or camera matrix at eye looking at target . More... | |
Public Attributes | |
union { | |
T rc [4][4] | |
Row/column indexing representation. | |
T m [16] | |
Array representation. | |
}; | |
Static Public Attributes | |
static const Matrix4< T > | zero |
A matrix with all zero elements. | |
static const Matrix4< T > | identity |
The identity matrix. | |
A row major 4x4 transformation matrix.
The matrix is laid out as follows:
Where (xx, xy, xz) are the components of the X axis. Similarly, yn and zn form the Y axis and Z axis of the basis vectors respectively. Finally, (tx, ty, tz) is the translation.
tes::Matrix4< T >::Matrix4 | ( | const T * | array16 | ) |
Array initialisation constructor from an array of at least 16 elements.
No bounds checking.
array16 | The array of at least 16 value to initialise from. |
tes::Matrix4< T >::Matrix4 | ( | const Matrix4< T > & | other | ) |
Copy constructor.
other | The matrix to copy from. |
Copy constructor from a different numeric type.
other | The matrix to copy from. |
tes::Matrix4< T >::Matrix4 | ( | const T & | rc00, |
const T & | rc01, | ||
const T & | rc02, | ||
const T & | rc03, | ||
const T & | rc10, | ||
const T & | rc11, | ||
const T & | rc12, | ||
const T & | rc13, | ||
const T & | rc20, | ||
const T & | rc21, | ||
const T & | rc22, | ||
const T & | rc23, | ||
const T & | rc30, | ||
const T & | rc31, | ||
const T & | rc32, | ||
const T & | rc33 | ||
) |
Per element constructor, specifying each row in order.
rc00 | Element at row/column 00 |
rc01 | Element at row/column 01 |
rc02 | Element at row/column 02 |
rc03 | Element at row/column 03 |
rc10 | Element at row/column 10 |
rc11 | Element at row/column 11 |
rc12 | Element at row/column 12 |
rc13 | Element at row/column 13 |
rc20 | Element at row/column 20 |
rc21 | Element at row/column 21 |
rc22 | Element at row/column 22 |
rc23 | Element at row/column 23 |
rc30 | Element at row/column 30 |
rc31 | Element at row/column 31 |
rc32 | Element at row/column 32 |
rc33 | Element at row/column 33 |
Vector3<T> tes::Matrix4< T >::axis | ( | int | index | ) | const |
Returns one of the axes of this matrix.
index | The index of the axis of interest. 0 => X, 1 => Y, 2 => Z, 3 => T/translation. |
Referenced by tes::Matrix4< T >::initLookAt().
Vector3<T> tes::Matrix4< T >::axisT | ( | ) | const |
Returns the T axis or translation component of this matrix (elements (0, 3), (1, 3), (2, 3)).
Referenced by tes::Matrix4< T >::initLookAt().
Vector3<T> tes::Matrix4< T >::axisX | ( | ) | const |
Returns the X axis of this matrix (elements (0, 0), (1, 0), (2, 0)).
Referenced by tes::Matrix4< T >::initLookAt().
Vector3<T> tes::Matrix4< T >::axisY | ( | ) | const |
Returns the Y axis of this matrix (elements (0, 1), (1, 1), (2, 1)).
Referenced by tes::Matrix4< T >::initLookAt().
Vector3<T> tes::Matrix4< T >::axisZ | ( | ) | const |
Returns the Z axis of this matrix (elements (0, 2), (1, 2), (2, 2)).
Referenced by tes::Matrix4< T >::initLookAt().
T tes::Matrix4< T >::determinant | ( | ) | const |
Calculates the determinant of this matrix.
Referenced by tes::Matrix4< T >::initLookAt().
|
inline |
Initialise this matrix as a model or camera matrix.
lookAt()
. eye | The position of the eye/camera. |
target | The target to look at. Should not be equal to eye . |
axisUp | The axis defining the initial up vector. Must be normalised. |
forwardAxisIndex | The index of the forward axis. This is to point at target . |
upAxisIndex | The index of the up axis. Must not be equal to forwardAxisIndex . |
this
References tes::Matrix4< T >::axis(), tes::Matrix4< T >::axisT(), tes::Matrix4< T >::axisX(), tes::Matrix4< T >::axisY(), tes::Matrix4< T >::axisZ(), tes::Matrix4< T >::determinant(), tes::Matrix4< T >::inverse(), tes::Matrix4< T >::invert(), tes::Matrix4< T >::lookAt(), tes::Matrix4< T >::removeScale(), tes::Matrix4< T >::rigidBodyInverse(), tes::Matrix4< T >::rigidBodyInvert(), tes::Matrix4< T >::rotate(), tes::Matrix4< T >::scale(), tes::Matrix4< T >::setAxis(), tes::Matrix4< T >::setAxisT(), tes::Matrix4< T >::setAxisX(), tes::Matrix4< T >::setAxisY(), tes::Matrix4< T >::setAxisZ(), tes::Matrix4< T >::setTranslation(), tes::Matrix4< T >::transform(), tes::Matrix4< T >::translation(), tes::Matrix4< T >::transpose(), and tes::Matrix4< T >::transposed().
|
inline |
Initialise this matrix as a rotation using the given Euler angles.
x | Rotation around the X axis (radians). |
y | Rotation around the Y axis (radians). |
z | Rotation around the Z axis (radians). |
this
References tes::Matrix4< T >::rotation(), and tes::Matrix4< T >::translation().
|
inline |
this
References tes::Matrix4< T >::rotationTranslation(), tes::Matrix4< T >::scale(), and tes::Matrix4< T >::scaling().
|
inline |
Initialise this matrix as a rotation around the X axis.
angle | The rotation angle (radians). |
this
References tes::Matrix4< T >::rotationX(), and tes::Matrix4< T >::rotationY().
|
inline |
Initialise this matrix as a rotation around the Y axis.
angle | The rotation angle (radians). |
this
References tes::Matrix4< T >::rotationY(), and tes::Matrix4< T >::rotationZ().
|
inline |
Initialise this matrix as a rotation around the Z axis.
angle | The rotation angle (radians). |
this
References tes::Matrix4< T >::rotation(), and tes::Matrix4< T >::rotationZ().
|
inline |
Initialise this matrix as scaling matrix with no rotation or translation.
scale | The scaling vector. Each component corresponds to each axis. |
this
References tes::Matrix4< T >::lookAt(), and tes::Matrix4< T >::scaling().
|
inline |
Initialise this matrix as a translation only matrix.
trans | The translation. |
this
References tes::Matrix4< T >::rotationTranslation(), and tes::Matrix4< T >::translation().
Matrix4<T> tes::Matrix4< T >::inverse | ( | ) | const |
Returns the inverse of this matrix, leaving this matrix unchanged.
Referenced by tes::Matrix4< T >::initLookAt().
Matrix4<T>& tes::Matrix4< T >::invert | ( | ) |
Inverts this matrix.
Referenced by tes::Matrix4< T >::initLookAt().
|
static |
Create a model or camera matrix at eye
looking at target
.
Supports specifying the up and forward axes (inferring the left/right axis), where the indices [0, 1, 2] correspond to the axes (X, Y, Z).
The default behaviour is to use Y as the forward axis and Z as up.
eye | The position of the eye/camera. |
target | The target to look at. Should not be equal to eye . |
axisUp | The axis defining the initial up vector. Must be normalised. |
forwardAxisIndex | The index of the forward axis. This is to point at target . |
upAxisIndex | The index of the up axis. Must not be equal to forwardAxisIndex . |
eye
pointing at target
. Returns identity if there are errors in the specification of forwardAxisIndex
and upAxisIndex
. Referenced by tes::Matrix4< T >::initLookAt(), and tes::Matrix4< T >::initScaling().
|
inline |
Row/column access.
Not bounds checked.
r | The row to access [0, 3] |
c | The column to access [0, 3]. |
References tes::Matrix4< T >::rc.
|
inline |
Row/column immutable access.
Not bounds checked.
r | The row to access [0, 3] |
c | The column to access [0, 3]. |
References tes::Matrix4< T >::rc.
|
inline |
Indexing operator (no bounds checking).
index | The element to access [0, 15]. |
index
. References tes::Matrix4< T >::m.
|
inline |
Indexing operator (no bounds checking).
index | The element to access [0, 15]. |
index
. References tes::Matrix4< T >::m, and tes::Matrix4< T >::rotationX().
Vector3<T> tes::Matrix4< T >::removeScale | ( | ) |
Removes scale from the matrix, leaving a rotation/translation matrix.
Referenced by tes::Matrix4< T >::initLookAt().
Matrix4<T> tes::Matrix4< T >::rigidBodyInverse | ( | ) | const |
Returns the inverse of this matrix assuming this is a rigid body transformation.
See rigidBodyInvert()
.
Referenced by tes::Matrix4< T >::initLookAt().
Matrix4<T>& tes::Matrix4< T >::rigidBodyInvert | ( | ) |
Inverts this matrix assuming this matrix represents a rigid body transformation.
A rigid body transformation contains no skewing. That is, the basis vectors are orthogonal.
The inverse is calculated by transposing the rotation and inverting the translation.
Referenced by tes::Matrix4< T >::initLookAt().
Vector3<T> tes::Matrix4< T >::rotate | ( | const Vector3< T > & | v | ) | const |
Transforms the vector v
by the rotation component of this matrix.
No translation is applied.
Referenced by tes::Matrix4< T >::initLookAt().
Vector4<T> tes::Matrix4< T >::rotate | ( | const Vector4< T > & | v | ) | const |
Transforms the vector v
by the rotation component of this matrix.
No translation is applied.
|
static |
Create a matrix which represents a rotation around each axis (Euler angles).
Rotations are applied in x, y, z order.
x | Rotation around the X axis (radians). |
y | Rotation around the Y axis (radians). |
z | Rotation around the Z axis (radians). |
Referenced by tes::Matrix4< T >::initRotation(), and tes::Matrix4< T >::initRotationZ().
|
static |
Create a transformation matrix with rotation (Euler angles) and translation.
Rotation is applied first.
x | Rotation around the X axis (radians). |
y | Rotation around the Y axis (radians). |
z | Rotation around the Z axis (radians). |
trans | The translation the matrix applies. |
Referenced by tes::Matrix4< T >::initRotationTranslation(), and tes::Matrix4< T >::initTranslation().
|
static |
Create a matrix which represents a rotation around the X axis.
angle | The rotation angle in radians. |
Referenced by tes::Matrix4< T >::initRotationX(), and tes::Matrix4< T >::operator[]().
|
static |
Create a matrix which represents a rotation around the Y axis.
angle | The rotation angle in radians. |
Referenced by tes::Matrix4< T >::initRotationX(), and tes::Matrix4< T >::initRotationY().
|
static |
Create a matrix which represents a rotation around the Z axis.
angle | The rotation angle in radians. |
Referenced by tes::Matrix4< T >::initRotationY(), and tes::Matrix4< T >::initRotationZ().
Vector3<T> tes::Matrix4< T >::scale | ( | ) | const |
Returns the scale contained in this matrix.
This is the length of each axis.
Referenced by tes::Matrix4< T >::initLookAt(), and tes::Matrix4< T >::initRotationTranslation().
Matrix4<T>& tes::Matrix4< T >::scale | ( | const Vector3< T > & | scaling | ) |
Scales this matrix, adjusting the scale of each rotation, but leaving the translation.
scaling | The scaling to apply. |
|
static |
Create a scaling matrix.
scale | The scaling to apply along each axis. |
Referenced by tes::Matrix4< T >::initRotationTranslation(), and tes::Matrix4< T >::initScaling().
Matrix4<T>& tes::Matrix4< T >::setAxis | ( | int | index, |
const Vector3< T > & | axis | ||
) |
Sets the indexed axis of this matrix.
See axis()
.
index | The index of the axis of interest. 0 => X, 1 => Y, 2 => Z, 3 => T/translation. |
axis | The value to set the axis to. |
Referenced by tes::Matrix4< T >::initLookAt().
Matrix4<T>& tes::Matrix4< T >::setAxisT | ( | const Vector3< T > & | axis | ) |
Sets the translation of this matrix.
See translation()
.
axis | The value to set the translation to. |
Referenced by tes::Matrix4< T >::initLookAt().
Matrix4<T>& tes::Matrix4< T >::setAxisX | ( | const Vector3< T > & | axis | ) |
Sets the X axis of this matrix.
See axisX()
.
axis | The value to set the axis to. |
Referenced by tes::Matrix4< T >::initLookAt().
Matrix4<T>& tes::Matrix4< T >::setAxisY | ( | const Vector3< T > & | axis | ) |
Sets the Y axis of this matrix.
See axisY()
.
axis | The value to set the axis to. |
Referenced by tes::Matrix4< T >::initLookAt().
Matrix4<T>& tes::Matrix4< T >::setAxisZ | ( | const Vector3< T > & | axis | ) |
Sets the Z axis of this matrix.
See axisZ()
.
axis | The value to set the axis to. |
Referenced by tes::Matrix4< T >::initLookAt().
Matrix4<T>& tes::Matrix4< T >::setTranslation | ( | const Vector3< T > & | axis | ) |
Sets the translation of this matrix.
See translation()
.
axis | The value to set the translation to. |
Referenced by tes::Matrix4< T >::initLookAt().
Vector3<T> tes::Matrix4< T >::transform | ( | const Vector3< T > & | v | ) | const |
Transforms the vector v
by this matrix.
Referenced by tes::Matrix4< T >::initLookAt().
Vector4<T> tes::Matrix4< T >::transform | ( | const Vector4< T > & | v | ) | const |
Transforms the vector v
by this matrix.
|
static |
Create a translation matrix (no rotation).
trans | The translation the matrix applies. |
Vector3<T> tes::Matrix4< T >::translation | ( | ) | const |
Returns the T axis or translation component of this matrix (elements (0, 3), (1, 3), (2, 3)).
Referenced by tes::Matrix4< T >::initLookAt(), tes::Matrix4< T >::initRotation(), and tes::Matrix4< T >::initTranslation().
Matrix4<T>& tes::Matrix4< T >::transpose | ( | ) |
Transposes this matrix.
Referenced by tes::Matrix4< T >::initLookAt().
Matrix4<T> tes::Matrix4< T >::transposed | ( | ) | const |
Returns the transpose of this matrix, leaving this matrix unchanged.
Referenced by tes::Matrix4< T >::initLookAt().