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

A row major 3x3 rotation matrix. More...

#include <3esmatrix3.h>

Public Member Functions

 Matrix3 ()
 Empty constructor; contents are undefined.
 
 Matrix3 (const T *array9)
 Array initialisation constructor from an array of at least 9 elements. More...
 
 Matrix3 (const Matrix3< T > &other)
 Copy constructor. More...
 
template<typename Q >
 Matrix3 (const Matrix3< Q > &other)
 Copy constructor from a different numeric type. More...
 
 Matrix3 (const T &rc00, const T &rc01, const T &rc02, const T &rc10, const T &rc11, const T &rc12, const T &rc20, const T &rc21, const T &rc22)
 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...
 
Matrix3< T > & initRotationX (const T &angle)
 
Matrix3< T > & initRotationY (const T &angle)
 
Matrix3< T > & initRotationZ (const T &angle)
 
Matrix3< T > & initRotation (const T &x, const T &y, const T &z)
 
Matrix3< T > & initScaling (const Vector3< T > &scale)
 
Matrix3< 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...
 
Matrix3< T > & transpose ()
 Transposes this matrix. More...
 
Matrix3< T > transposed () const
 Returns the transpose of this matrix, leaving this matrix unchanged. More...
 
Matrix3< T > & invert ()
 Inverts this matrix. More...
 
Matrix3< T > inverse () const
 Returns the inverse of this matrix, leaving this matrix unchanged. More...
 
getAdjoint (Matrix3< T > &adj) const
 Gets the adjoint of this matrix. More...
 
Matrix3< T > & rigidBodyInvert ()
 Inverts this matrix assuming this matrix represents a rigid body transformation. More...
 
Matrix3< 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 > axis (int index) const
 Returns one of the axes of this matrix. More...
 
Matrix3< T > & setAxisX (const Vector3< T > &axis)
 Sets the X axis of this matrix. More...
 
Matrix3< T > & setAxisY (const Vector3< T > &axis)
 Sets the Y axis of this matrix. More...
 
Matrix3< T > & setAxisZ (const Vector3< T > &axis)
 Sets the Z axis of this matrix. More...
 
Matrix3< 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...
 
Matrix3< 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...
 
Vector3< T > rotate (const Vector3< T > &v) const
 An alias for transform(). More...
 

Static Public Member Functions

static Matrix3< T > rotationX (const T &angle)
 Create a matrix which represents a rotation around the X axis. More...
 
static Matrix3< T > rotationY (const T &angle)
 Create a matrix which represents a rotation around the Y axis. More...
 
static Matrix3< T > rotationZ (const T &angle)
 Create a matrix which represents a rotation around the Z axis. More...
 
static Matrix3< 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 Matrix3< T > scaling (const Vector3< T > &scale)
 Create a scaling matrix. More...
 
static Matrix3< 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 [3][3]
 Row/column indexing representation.
 
   T   m [9]
 Array representation.
 
}; 
 

Static Public Attributes

static const Matrix3< T > zero
 A matrix with all zero elements.
 
static const Matrix3< T > identity
 The identity matrix.
 

Detailed Description

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

A row major 3x3 rotation matrix.

The matrix is laid out as follows:

| rc00 rc01 rc02 | | 0 1 2 | | xx yx zx |
M = | rc10 rc11 rc12 | = | 3 4 5 | = | xy yy zy |
| rc20 rc21 rc22 | | 6 7 8 | | xz yz zz |

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.

Constructor & Destructor Documentation

◆ Matrix3() [1/4]

template<typename T>
tes::Matrix3< T >::Matrix3 ( const T *  array9)

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

No bounds checking.

Parameters
array9The array of at least 9 value to initialise from.

◆ Matrix3() [2/4]

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

Copy constructor.

Parameters
otherThe matrix to copy from.

◆ Matrix3() [3/4]

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

Copy constructor from a different numeric type.

Parameters
otherThe matrix to copy from.

◆ Matrix3() [4/4]

template<typename T>
tes::Matrix3< T >::Matrix3 ( const T &  rc00,
const T &  rc01,
const T &  rc02,
const T &  rc10,
const T &  rc11,
const T &  rc12,
const T &  rc20,
const T &  rc21,
const T &  rc22 
)

Per element constructor, specifying each row in order.

Parameters
rc00Element at row/column 00
rc01Element at row/column 01
rc02Element at row/column 02
rc10Element at row/column 10
rc11Element at row/column 11
rc12Element at row/column 12
rc20Element at row/column 20
rc21Element at row/column 21
rc22Element at row/column 22

Member Function Documentation

◆ axis()

template<typename T>
Vector3<T> tes::Matrix3< 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.
Returns
The axis of interest.

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

◆ axisX()

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

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

Returns
The X axis.

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

◆ axisY()

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

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

Returns
The Y axis.

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

◆ axisZ()

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

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

Returns
The Z axis.

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

◆ determinant()

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

Calculates the determinant of this matrix.

Returns
The determinant.

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

◆ getAdjoint()

template<typename T>
T tes::Matrix3< T >::getAdjoint ( Matrix3< T > &  adj) const

Gets the adjoint of this matrix.

Parameters
[out]mThe adjoint is written here.
Returns
The determinant.

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

◆ initLookAt()

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

Initialise this matrix as a model or camera matrix.

See also
lookAt().
Parameters
eyeThe position of the eye/camera (dropped after rotation is calculated).
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
this

References tes::Matrix3< T >::axis(), tes::Matrix3< T >::axisX(), tes::Matrix3< T >::axisY(), tes::Matrix3< T >::axisZ(), tes::Matrix3< T >::determinant(), tes::Matrix3< T >::getAdjoint(), tes::Matrix3< T >::inverse(), tes::Matrix3< T >::invert(), tes::Matrix3< T >::lookAt(), tes::Matrix3< T >::rigidBodyInverse(), tes::Matrix3< T >::rigidBodyInvert(), tes::Matrix3< T >::rotate(), tes::Matrix3< T >::scale(), tes::Matrix3< T >::setAxis(), tes::Matrix3< T >::setAxisX(), tes::Matrix3< T >::setAxisY(), tes::Matrix3< T >::setAxisZ(), tes::Matrix3< T >::transform(), tes::Matrix3< T >::transpose(), and tes::Matrix3< T >::transposed().

◆ inverse()

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

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

Returns
The inverse of this matrix.

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

◆ invert()

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

Inverts this matrix.

Returns
This matrix after the operation.

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

◆ lookAt()

template<typename T>
static Matrix3<T> tes::Matrix3< 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.

Note: the resulting matrix can only represent the rotation part of the matrix and the eye translation is essentially dropped. Use Matrix4 where the translation is required.

Parameters
eyeThe position of the eye/camera (dropped after rotation is calculated).
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::Matrix3< T >::initLookAt(), and tes::Matrix3< T >::operator[]().

◆ operator()() [1/2]

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

Row/column access.

Not bounds checked.

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

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

◆ operator()() [2/2]

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

Row/column immutable access.

Not bounds checked.

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

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

◆ operator[]() [1/2]

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

Indexing operator (no bounds checking).

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

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

◆ operator[]() [2/2]

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

Indexing operator (no bounds checking).

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

References tes::Matrix3< T >::lookAt(), tes::Matrix3< T >::m, tes::Matrix3< T >::rotation(), tes::Matrix3< T >::rotationX(), tes::Matrix3< T >::rotationY(), tes::Matrix3< T >::rotationZ(), tes::Matrix3< T >::scale(), and tes::Matrix3< T >::scaling().

◆ rigidBodyInverse()

template<typename T>
Matrix3<T> tes::Matrix3< 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::Matrix3< T >::initLookAt().

◆ rigidBodyInvert()

template<typename T>
Matrix3<T>& tes::Matrix3< 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::Matrix3< T >::initLookAt().

◆ rotate()

template<typename T>
Vector3<T> tes::Matrix3< T >::rotate ( const Vector3< T > &  v) const

An alias for transform().

Returns
Av, where A is this matrix.

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

◆ rotation()

template<typename T>
static Matrix3<T> tes::Matrix3< 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::Matrix3< T >::operator[]().

◆ rotationX()

template<typename T>
static Matrix3<T> tes::Matrix3< 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::Matrix3< T >::operator[]().

◆ rotationY()

template<typename T>
static Matrix3<T> tes::Matrix3< 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::Matrix3< T >::operator[]().

◆ rotationZ()

template<typename T>
static Matrix3<T> tes::Matrix3< 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::Matrix3< T >::operator[]().

◆ scale() [1/2]

template<typename T>
Vector3<T> tes::Matrix3< 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::Matrix3< T >::initLookAt(), and tes::Matrix3< T >::operator[]().

◆ scale() [2/2]

template<typename T>
Matrix3<T>& tes::Matrix3< 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 Matrix3<T> tes::Matrix3< 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::Matrix3< T >::operator[]().

◆ setAxis()

template<typename T>
Matrix3<T>& tes::Matrix3< 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.
axisThe value to set the axis to.
Returns
This matrix after the operation.

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

◆ setAxisX()

template<typename T>
Matrix3<T>& tes::Matrix3< 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::Matrix3< T >::initLookAt().

◆ setAxisY()

template<typename T>
Matrix3<T>& tes::Matrix3< 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::Matrix3< T >::initLookAt().

◆ setAxisZ()

template<typename T>
Matrix3<T>& tes::Matrix3< 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::Matrix3< T >::initLookAt().

◆ transform()

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

Transforms the vector v by this matrix.

Returns
Av, where A is this matrix.

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

◆ transpose()

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

Transposes this matrix.

Returns
This matrix after the operation.

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

◆ transposed()

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

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

Returns
The transpose of this matrix.

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


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