3es  0.7
tes::Matrix4< T > Class Template Reference

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...
 
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.
 

Detailed Description

template<typename T>
class tes::Matrix4< T >

A row major 4x4 transformation matrix.

The matrix is laid out as follows:

| rc00 rc01 rc02 rc03 | | 0 1 2 3 | | xx yx zx tx |
M = | rc10 rc11 rc12 rc13 | = | 4 5 6 7 | = | xy yy zy ty |
| rc20 rc21 rc22 rc23 | | 8 9 10 11 | | xz yz zz tz |
| rc30 rc31 rc32 rc33 | | 12 13 14 15 | | 0 0 0 1 |

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.

Constructor & Destructor Documentation

◆ Matrix4() [1/4]

template<typename T>
tes::Matrix4< T >::Matrix4 ( const T *  array16)

Array initialisation constructor from an array of at least 16 elements.

No bounds checking.

Parameters
array16The array of at least 16 value to initialise from.

◆ Matrix4() [2/4]

template<typename T>
tes::Matrix4< T >::Matrix4 ( const Matrix4< T > &  other)

Copy constructor.

Parameters
otherThe matrix to copy from.

◆ Matrix4() [3/4]

template<typename T>
template<typename Q >
tes::Matrix4< T >::Matrix4 ( const Matrix4< Q > &  other)

Copy constructor from a different numeric type.

Parameters
otherThe matrix to copy from.

◆ Matrix4() [4/4]

template<typename T>
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.

Parameters
rc00Element at row/column 00
rc01Element at row/column 01
rc02Element at row/column 02
rc03Element at row/column 03
rc10Element at row/column 10
rc11Element at row/column 11
rc12Element at row/column 12
rc13Element at row/column 13
rc20Element at row/column 20
rc21Element at row/column 21
rc22Element at row/column 22
rc23Element at row/column 23
rc30Element at row/column 30
rc31Element at row/column 31
rc32Element at row/column 32
rc33Element at row/column 33

Member Function Documentation

◆ axis()

template<typename T>
Vector3<T> tes::Matrix4< T >::axis ( int  index) const

Returns one of the axes of this matrix.

Parameters
indexThe index of the axis of interest. 0 => X, 1 => Y, 2 => Z, 3 => T/translation.
Returns
The axis of interest.

Referenced by tes::Matrix4< T >::initLookAt().

◆ axisT()

template<typename T>
Vector3<T> tes::Matrix4< T >::axisT ( ) const

Returns the T axis or translation component of this matrix (elements (0, 3), (1, 3), (2, 3)).

Returns
The translation component.

Referenced by tes::Matrix4< T >::initLookAt().

◆ axisX()

template<typename T>
Vector3<T> tes::Matrix4< T >::axisX ( ) const

Returns the X axis of this matrix (elements (0, 0), (1, 0), (2, 0)).

Returns
The X axis.

Referenced by tes::Matrix4< T >::initLookAt().

◆ axisY()

template<typename T>
Vector3<T> tes::Matrix4< T >::axisY ( ) const

Returns the Y axis of this matrix (elements (0, 1), (1, 1), (2, 1)).

Returns
The Y axis.

Referenced by tes::Matrix4< T >::initLookAt().

◆ axisZ()

template<typename T>
Vector3<T> tes::Matrix4< T >::axisZ ( ) const

Returns the Z axis of this matrix (elements (0, 2), (1, 2), (2, 2)).

Returns
The Z axis.

Referenced by tes::Matrix4< T >::initLookAt().

◆ determinant()

template<typename T>
T tes::Matrix4< T >::determinant ( ) const

Calculates the determinant of this matrix.

Returns
The determinant.

Referenced by tes::Matrix4< T >::initLookAt().

◆ initLookAt()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::initLookAt ( const Vector3< T > &  eye,
const Vector3< T > &  target,
const Vector3< T > &  axisUp,
int  forwardAxisIndex = 1,
int  upAxisIndex = 2 
)
inline

◆ initRotation()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::initRotation ( const T &  x,
const T &  y,
const T &  z 
)
inline

Initialise this matrix as a rotation using the given Euler angles.

Parameters
xRotation around the X axis (radians).
yRotation around the Y axis (radians).
zRotation around the Z axis (radians).
Returns
this

References tes::Matrix4< T >::rotation(), and tes::Matrix4< T >::translation().

◆ initRotationTranslation()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::initRotationTranslation ( const T &  x,
const T &  y,
const T &  z,
const Vector3< T > &  trans 
)
inline

◆ initRotationX()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::initRotationX ( const T &  angle)
inline

Initialise this matrix as a rotation around the X axis.

Parameters
angleThe rotation angle (radians).
Returns
this

References tes::Matrix4< T >::rotationX(), and tes::Matrix4< T >::rotationY().

◆ initRotationY()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::initRotationY ( const T &  angle)
inline

Initialise this matrix as a rotation around the Y axis.

Parameters
angleThe rotation angle (radians).
Returns
this

References tes::Matrix4< T >::rotationY(), and tes::Matrix4< T >::rotationZ().

◆ initRotationZ()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::initRotationZ ( const T &  angle)
inline

Initialise this matrix as a rotation around the Z axis.

Parameters
angleThe rotation angle (radians).
Returns
this

References tes::Matrix4< T >::rotation(), and tes::Matrix4< T >::rotationZ().

◆ initScaling()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::initScaling ( const Vector3< T > &  scale)
inline

Initialise this matrix as scaling matrix with no rotation or translation.

Parameters
scaleThe scaling vector. Each component corresponds to each axis.
Returns
this

References tes::Matrix4< T >::lookAt(), and tes::Matrix4< T >::scaling().

◆ initTranslation()

template<typename T>
Matrix4<T> tes::Matrix4< T >::initTranslation ( const Vector3< T > &  trans)
inline

Initialise this matrix as a translation only matrix.

Parameters
transThe translation.
Returns
this

References tes::Matrix4< T >::rotationTranslation(), and tes::Matrix4< T >::translation().

◆ inverse()

template<typename T>
Matrix4<T> tes::Matrix4< T >::inverse ( ) const

Returns the inverse of this matrix, leaving this matrix unchanged.

Returns
The inverse of this matrix.

Referenced by tes::Matrix4< T >::initLookAt().

◆ invert()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::invert ( )

Inverts this matrix.

Returns
This matrix after the operation.

Referenced by tes::Matrix4< T >::initLookAt().

◆ lookAt()

template<typename T>
static Matrix4<T> tes::Matrix4< T >::lookAt ( const Vector3< T > &  eye,
const Vector3< T > &  target,
const Vector3< T > &  axisUp,
int  forwardAxisIndex = 1,
int  upAxisIndex = 2 
)
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.

Parameters
eyeThe position of the eye/camera.
targetThe target to look at. Should not be equal to eye.
axisUpThe axis defining the initial up vector. Must be normalised.
forwardAxisIndexThe index of the forward axis. This is to point at target.
upAxisIndexThe index of the up axis. Must not be equal to forwardAxisIndex.
Returns
A model matrix at 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().

◆ operator()() [1/2]

template<typename T>
T& tes::Matrix4< T >::operator() ( int  r,
int  c 
)
inline

Row/column access.

Not bounds checked.

Parameters
rThe row to access [0, 3]
cThe column to access [0, 3].

References tes::Matrix4< T >::rc.

◆ operator()() [2/2]

template<typename T>
const T& tes::Matrix4< T >::operator() ( int  r,
int  c 
) const
inline

Row/column immutable access.

Not bounds checked.

Parameters
rThe row to access [0, 3]
cThe column to access [0, 3].

References tes::Matrix4< T >::rc.

◆ operator[]() [1/2]

template<typename T>
T& tes::Matrix4< T >::operator[] ( int  index)
inline

Indexing operator (no bounds checking).

Parameters
indexThe element to access [0, 15].
Returns
The matrix element at index.

References tes::Matrix4< T >::m.

◆ operator[]() [2/2]

template<typename T>
const T& tes::Matrix4< T >::operator[] ( int  index) const
inline

Indexing operator (no bounds checking).

Parameters
indexThe element to access [0, 15].
Returns
The matrix element at index.

References tes::Matrix4< T >::m, and tes::Matrix4< T >::rotationX().

◆ removeScale()

template<typename T>
Vector3<T> tes::Matrix4< T >::removeScale ( )

Removes scale from the matrix, leaving a rotation/translation matrix.

Returns
The scale which was present along each axis.

Referenced by tes::Matrix4< T >::initLookAt().

◆ rigidBodyInverse()

template<typename T>
Matrix4<T> tes::Matrix4< T >::rigidBodyInverse ( ) const

Returns the inverse of this matrix assuming this is a rigid body transformation.

See rigidBodyInvert().

Returns
The inverse of this matrix.

Referenced by tes::Matrix4< T >::initLookAt().

◆ rigidBodyInvert()

template<typename T>
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.

Returns
This matrix after the operation.

Referenced by tes::Matrix4< T >::initLookAt().

◆ rotate() [1/2]

template<typename T>
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.

Returns
Av, where A is this matrix converted to a 3x3 rotation matrix (no translation).

Referenced by tes::Matrix4< T >::initLookAt().

◆ rotate() [2/2]

template<typename T>
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.

Returns
Av, where A is this matrix converted to a 3x3 rotation matrix (no translation).

◆ rotation()

template<typename T>
static Matrix4<T> tes::Matrix4< T >::rotation ( const T &  x,
const T &  y,
const T &  z 
)
static

Create a matrix which represents a rotation around each axis (Euler angles).

Rotations are applied in x, y, z order.

Parameters
xRotation around the X axis (radians).
yRotation around the Y axis (radians).
zRotation around the Z axis (radians).
Returns
The rotation matrix.

Referenced by tes::Matrix4< T >::initRotation(), and tes::Matrix4< T >::initRotationZ().

◆ rotationTranslation()

template<typename T>
static Matrix4<T> tes::Matrix4< T >::rotationTranslation ( const T &  x,
const T &  y,
const T &  z,
const Vector3< T > &  trans 
)
static

Create a transformation matrix with rotation (Euler angles) and translation.

Rotation is applied first.

Parameters
xRotation around the X axis (radians).
yRotation around the Y axis (radians).
zRotation around the Z axis (radians).
transThe translation the matrix applies.
Returns
The transformation matrix.

Referenced by tes::Matrix4< T >::initRotationTranslation(), and tes::Matrix4< T >::initTranslation().

◆ rotationX()

template<typename T>
static Matrix4<T> tes::Matrix4< T >::rotationX ( const T &  angle)
static

Create a matrix which represents a rotation around the X axis.

Parameters
angleThe rotation angle in radians.
Returns
The rotation matrix.

Referenced by tes::Matrix4< T >::initRotationX(), and tes::Matrix4< T >::operator[]().

◆ rotationY()

template<typename T>
static Matrix4<T> tes::Matrix4< T >::rotationY ( const T &  angle)
static

Create a matrix which represents a rotation around the Y axis.

Parameters
angleThe rotation angle in radians.
Returns
The rotation matrix.

Referenced by tes::Matrix4< T >::initRotationX(), and tes::Matrix4< T >::initRotationY().

◆ rotationZ()

template<typename T>
static Matrix4<T> tes::Matrix4< T >::rotationZ ( const T &  angle)
static

Create a matrix which represents a rotation around the Z axis.

Parameters
angleThe rotation angle in radians.
Returns
The rotation matrix.

Referenced by tes::Matrix4< T >::initRotationY(), and tes::Matrix4< T >::initRotationZ().

◆ scale() [1/2]

template<typename T>
Vector3<T> tes::Matrix4< T >::scale ( ) const

Returns the scale contained in this matrix.

This is the length of each axis.

Returns
The scale of each rotation axis in this matrix.

Referenced by tes::Matrix4< T >::initLookAt(), and tes::Matrix4< T >::initRotationTranslation().

◆ scale() [2/2]

template<typename T>
Matrix4<T>& tes::Matrix4< T >::scale ( const Vector3< T > &  scaling)

Scales this matrix, adjusting the scale of each rotation, but leaving the translation.

Parameters
scalingThe scaling to apply.
Returns
This matrix after the operation.

◆ scaling()

template<typename T>
static Matrix4<T> tes::Matrix4< T >::scaling ( const Vector3< T > &  scale)
static

Create a scaling matrix.

Parameters
scaleThe scaling to apply along each axis.
Returns
The scaling matrix.

Referenced by tes::Matrix4< T >::initRotationTranslation(), and tes::Matrix4< T >::initScaling().

◆ setAxis()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::setAxis ( int  index,
const Vector3< T > &  axis 
)

Sets the indexed axis of this matrix.

See axis().

Parameters
indexThe index of the axis of interest. 0 => X, 1 => Y, 2 => Z, 3 => T/translation.
axisThe value to set the axis to.
Returns
This matrix after the operation.

Referenced by tes::Matrix4< T >::initLookAt().

◆ setAxisT()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::setAxisT ( const Vector3< T > &  axis)

Sets the translation of this matrix.

See translation().

Parameters
axisThe value to set the translation to.
Returns
This matrix after the operation.

Referenced by tes::Matrix4< T >::initLookAt().

◆ setAxisX()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::setAxisX ( const Vector3< T > &  axis)

Sets the X axis of this matrix.

See axisX().

Parameters
axisThe value to set the axis to.
Returns
This matrix after the operation.

Referenced by tes::Matrix4< T >::initLookAt().

◆ setAxisY()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::setAxisY ( const Vector3< T > &  axis)

Sets the Y axis of this matrix.

See axisY().

Parameters
axisThe value to set the axis to.
Returns
This matrix after the operation.

Referenced by tes::Matrix4< T >::initLookAt().

◆ setAxisZ()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::setAxisZ ( const Vector3< T > &  axis)

Sets the Z axis of this matrix.

See axisZ().

Parameters
axisThe value to set the axis to.
Returns
This matrix after the operation.

Referenced by tes::Matrix4< T >::initLookAt().

◆ setTranslation()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::setTranslation ( const Vector3< T > &  axis)

Sets the translation of this matrix.

See translation().

Parameters
axisThe value to set the translation to.
Returns
This matrix after the operation.

Referenced by tes::Matrix4< T >::initLookAt().

◆ transform() [1/2]

template<typename T>
Vector3<T> tes::Matrix4< T >::transform ( const Vector3< T > &  v) const

Transforms the vector v by this matrix.

Returns
Av, where A is this matrix.

Referenced by tes::Matrix4< T >::initLookAt().

◆ transform() [2/2]

template<typename T>
Vector4<T> tes::Matrix4< T >::transform ( const Vector4< T > &  v) const

Transforms the vector v by this matrix.

Returns
Av, where A is this matrix.

◆ translation() [1/2]

template<typename T>
static Matrix4<T> tes::Matrix4< T >::translation ( const Vector3< T > &  trans)
static

Create a translation matrix (no rotation).

Parameters
transThe translation the matrix applies.
Returns
The translation matrix.

◆ translation() [2/2]

template<typename T>
Vector3<T> tes::Matrix4< T >::translation ( ) const

Returns the T axis or translation component of this matrix (elements (0, 3), (1, 3), (2, 3)).

Returns
The translation component.

Referenced by tes::Matrix4< T >::initLookAt(), tes::Matrix4< T >::initRotation(), and tes::Matrix4< T >::initTranslation().

◆ transpose()

template<typename T>
Matrix4<T>& tes::Matrix4< T >::transpose ( )

Transposes this matrix.

Returns
This matrix after the operation.

Referenced by tes::Matrix4< T >::initLookAt().

◆ transposed()

template<typename T>
Matrix4<T> tes::Matrix4< T >::transposed ( ) const

Returns the transpose of this matrix, leaving this matrix unchanged.

Returns
The transpose of this matrix.

Referenced by tes::Matrix4< T >::initLookAt().


The documentation for this class was generated from the following file: