Cafu Engine
Matrix4x4T< T > Class Template Reference

This class represents a generic 4x4 matrix. More...

#include "Matrix.hpp"

Public Member Functions

 Matrix4x4T ()
 The default constructor for creating a "1" (identity) matrix. More...
 
 Matrix4x4T (const float M[4][4])
 Constructor for creating an arbitrary matrix. More...
 
 Matrix4x4T (const double M[4][4])
 Constructor for creating an arbitrary matrix. More...
 
 Matrix4x4T (T m00, T m01, T m02, T m03, T m10, T m11, T m12, T m13, T m20, T m21, T m22, T m23, T m30, T m31, T m32, T m33)
 Constructor for creating an arbitrary matrix. More...
 
 Matrix4x4T (const Vector3T< T > &t, const cf::math::QuaternionT< T > &q, const Vector3T< T > &s=Vector3T< T >(1, 1, 1))
 Constructor for creating a matrix from a translation, a quaternion, and an optional scale. More...
 
T * operator[] (unsigned int i)
 Returns the i-th row of this matrix. More...
 
const T * operator[] (unsigned int i) const
 Returns the i-th row of this matrix. More...
 
Matrix4x4T operator* (const Matrix4x4T &Other) const
 Computes M*Other, that is, the matrix product of this and the Other matrix. More...
 
void Translate_MT (const Vector3dT &Trans)
 Computes M=M*T, where T=GetTranslationMatrix(Trans). Assumes that the last row is (0 0 0 1). More...
 
void Translate_MT (T tx, T ty, T tz)
 Computes M=M*T, where T=GetTranslationMatrix(Trans). Assumes that the last row is (0 0 0 1). More...
 
void Translate_TM (const Vector3dT &Trans)
 Computes M=T*M, where T=GetTranslationMatrix(Trans). Assumes that the last row is (0 0 0 1). More...
 
void Scale_MS (T sx, T sy, T sz)
 Computes M=M*S, where S=GetScaleMatrix (sx, sy, sz). More...
 
void Scale_SM (T sx, T sy, T sz)
 Computes M=S*M, where S=GetScaleMatrix (sx, sy, sz). More...
 
void RotateX_MR (T Angle)
 Computes M=M*R, where R=GetRotateXMatrix (Angle). More...
 
void RotateX_RM (T Angle)
 Computes M=R*M, where R=GetRotateXMatrix (Angle). More...
 
void RotateY_MR (T Angle)
 Computes M=M*R, where R=GetRotateYMatrix (Angle). More...
 
void RotateY_RM (T Angle)
 Computes M=R*M, where R=GetRotateYMatrix (Angle). More...
 
void RotateZ_MR (T Angle)
 Computes M=M*R, where R=GetRotateZMatrix (Angle). More...
 
void RotateZ_RM (T Angle)
 Computes M=R*M, where R=GetRotateZMatrix (Angle). More...
 
Vector3dT Mul0 (const Vector3dT &v) const
 Computes M*v, where M is this matrix. More...
 
Vector3fT Mul0 (const Vector3fT &v) const
 
Vector3dT Mul1 (const Vector3dT &v) const
 Computes M*v, where M is this matrix. More...
 
Vector3fT Mul1 (const Vector3fT &v) const
 
Vector3T< T > Mul_xyz1 (const Vector3T< T > &v) const
 Computes M*v, where M is this matrix. More...
 
void Mul_xyz1 (const T v[3], T out[3]) const
 Computes M*v, where M is this matrix. More...
 
Vector3T< T > ProjectPoint (const Vector3T< T > &v) const
 Computes M*v, where M is this matrix. More...
 
void Mul (const T v[4], T out[4]) const
 Computes M*v, where M is this matrix. More...
 
bool IsEqual (const Matrix4x4T &Other, const T Epsilon=0) const
 Returns whether this matrix is equal to Other. More...
 
Vector3T< T > InvXForm (Vector3T< T > v) const
 If this matrix represents a rigid transformation (rotation and translation only, no scale, shear, etc.), this is a faster shortcut for GetInverse().Mul1(v). More...
 
Matrix4x4T GetInverse (bool *Result=NULL) const
 Computes the inverse of this matrix. More...
 
Matrix4x4T GetTranspose () const
 Returns the transpose of this matrix. More...
 

Public Attributes

m [4][4]
 The matrix values. More...
 

Named constructors

static Matrix4x4T GetProjOrthoMatrix (T left, T right, T bottom, T top, T zNear, T zFar)
 Returns a matrix for orthographic projection. More...
 
static Matrix4x4T GetProjFrustumMatrix (T left, T right, T bottom, T top, T zNear, T zFar)
 Returns a matrix for perspective projection. If zFar <= zNear, the far plane is assumed to be at infinity (a useful special case for stencil shadow projections). More...
 
static Matrix4x4T GetProjPerspectiveMatrix (T fovY, T aspect, T zNear, T zFar)
 Returns a matrix for perspective projection. If zFar <= zNear, the far plane is assumed to be at infinity (a useful special case for stencil shadow projections). More...
 
static Matrix4x4T GetProjPickMatrix (T x, T y, T width, T height, int viewport[4])
 Returns a matrix for picking, i.e. the same matrix that gluPickMatrix() uses. More...
 
static Matrix4x4T GetTranslateMatrix (const Vector3T< T > &t)
 Returns a translate matrix about t. More...
 
static Matrix4x4T GetScaleMatrix (T sx, T sy, T sz)
 Returns a scale matrix with scale factors (sx sy sz). More...
 
static Matrix4x4T GetRotateXMatrix (T Angle)
 Returns a rotation matrix about Angle degrees around the x-axis. More...
 
static Matrix4x4T GetRotateYMatrix (T Angle)
 Returns a rotation matrix about Angle degrees around the y-axis. More...
 
static Matrix4x4T GetRotateZMatrix (T Angle)
 Returns a rotation matrix about Angle degrees around the z-axis. More...
 
static Matrix4x4T GetRotateMatrix (T Angle, const Vector3T< T > &Axis)
 Returns a rotation matrix about Angle degrees around Axis. More...
 

Detailed Description

template<class T>
class Matrix4x4T< T >

This class represents a generic 4x4 matrix.

It has special helper methods for affine geometric transformations in 3D, but can be used for general purposes. Contrary to earlier test versions, it stores the fourth row explicitly, so that easy compatibility with OpenGL matrices is given and no problems occur with general-case use (e.g. as projection matrix etc.).

Constructor & Destructor Documentation

template<class T>
Matrix4x4T< T >::Matrix4x4T ( )
inline

The default constructor for creating a "1" (identity) matrix.

template<class T>
Matrix4x4T< T >::Matrix4x4T ( const float  M[4][4])
inline

Constructor for creating an arbitrary matrix.

template<class T>
Matrix4x4T< T >::Matrix4x4T ( const double  M[4][4])
inline

Constructor for creating an arbitrary matrix.

template<class T>
Matrix4x4T< T >::Matrix4x4T ( m00,
m01,
m02,
m03,
m10,
m11,
m12,
m13,
m20,
m21,
m22,
m23,
m30,
m31,
m32,
m33 
)
inline

Constructor for creating an arbitrary matrix.

template<class T>
Matrix4x4T< T >::Matrix4x4T ( const Vector3T< T > &  t,
const cf::math::QuaternionT< T > &  q,
const Vector3T< T > &  s = Vector3T<T>(1, 1, 1) 
)

Constructor for creating a matrix from a translation, a quaternion, and an optional scale.

The resulting matrix is equal to the matrix product T*R*S of three matrices T, R and S, where T is the translation matrix that corresponds to the given translation vector t, R is the rotation matrix that is constructed from the given quaternion q, and S is the scale matrix that corresponds to the given scale s.

The resulting matrix is of the form:

x1*s.x x2*s.y x3*s.z t.x
y1*s.x y2*s.y y3*s.z t.y
z1*s.x z2*s.y z3*s.z t.z
0 0 0 1
Parameters
tThe translation that is expressed in the matrix.
qThe quaternion that describes the rotation that is expressed in the matrix.
sThe scale that is expressed in the matrix.

Member Function Documentation

template<class T >
Matrix4x4T< T > Matrix4x4T< T >::GetInverse ( bool *  Result = NULL) const

Computes the inverse of this matrix.

Parameters
ResultWhether the inversion was successful.
Returns
If this matrix is invertible, the inverse is returned by this method and *Result, if not at NULL, is set to true. Otherwise, an undefined matrix is returned and *Result, if not at NULL, is set to false.
template<class T>
Matrix4x4T< T > Matrix4x4T< T >::GetProjFrustumMatrix ( left,
right,
bottom,
top,
zNear,
zFar 
)
static

Returns a matrix for perspective projection. If zFar <= zNear, the far plane is assumed to be at infinity (a useful special case for stencil shadow projections).

template<class T>
Matrix4x4T< T > Matrix4x4T< T >::GetProjOrthoMatrix ( left,
right,
bottom,
top,
zNear,
zFar 
)
static

Returns a matrix for orthographic projection.

template<class T>
Matrix4x4T< T > Matrix4x4T< T >::GetProjPerspectiveMatrix ( fovY,
aspect,
zNear,
zFar 
)
static

Returns a matrix for perspective projection. If zFar <= zNear, the far plane is assumed to be at infinity (a useful special case for stencil shadow projections).

template<class T>
Matrix4x4T< T > Matrix4x4T< T >::GetProjPickMatrix ( x,
y,
width,
height,
int  viewport[4] 
)
static

Returns a matrix for picking, i.e. the same matrix that gluPickMatrix() uses.

template<class T>
Matrix4x4T< T > Matrix4x4T< T >::GetRotateMatrix ( Angle,
const Vector3T< T > &  Axis 
)
static

Returns a rotation matrix about Angle degrees around Axis.

template<class T>
Matrix4x4T< T > Matrix4x4T< T >::GetRotateXMatrix ( Angle)
static

Returns a rotation matrix about Angle degrees around the x-axis.

template<class T>
Matrix4x4T< T > Matrix4x4T< T >::GetRotateYMatrix ( Angle)
static

Returns a rotation matrix about Angle degrees around the y-axis.

template<class T>
Matrix4x4T< T > Matrix4x4T< T >::GetRotateZMatrix ( Angle)
static

Returns a rotation matrix about Angle degrees around the z-axis.

template<class T>
Matrix4x4T< T > Matrix4x4T< T >::GetScaleMatrix ( sx,
sy,
sz 
)
static

Returns a scale matrix with scale factors (sx sy sz).

template<class T>
Matrix4x4T< T > Matrix4x4T< T >::GetTranslateMatrix ( const Vector3T< T > &  t)
static

Returns a translate matrix about t.

template<class T >
Matrix4x4T< T > Matrix4x4T< T >::GetTranspose ( ) const

Returns the transpose of this matrix.

Returns
The transpose of this matrix.
template<class T>
Vector3T<T> Matrix4x4T< T >::InvXForm ( Vector3T< T >  v) const
inline

If this matrix represents a rigid transformation (rotation and translation only, no scale, shear, etc.), this is a faster shortcut for GetInverse().Mul1(v).

It employs the transpose of the rotational part for inverting the rotation, and properly accounts for the translation.

Parameters
vDOCTODO
template<class T>
bool Matrix4x4T< T >::IsEqual ( const Matrix4x4T< T > &  Other,
const T  Epsilon = 0 
) const
inline

Returns whether this matrix is equal to Other.

The matrices are considered equal if the element-wise comparison yields no difference larger than Epsilon.

Parameters
OtherMatrix to compare to.
EpsilonTolerance value.
template<class T>
void Matrix4x4T< T >::Mul ( const T  v[4],
out[4] 
) const
inline

Computes M*v, where M is this matrix.

Parameters
vThe four-component vector that is multiplied with M.
outThe four-component result vector.
Returns
The four-component result vector M*v is returned via the out parameter.
template<class T>
Vector3dT Matrix4x4T< T >::Mul0 ( const Vector3dT v) const
inline

Computes M*v, where M is this matrix.

The w-component of v is assumed to be 0 (v being a direction vector, not a point). The last row of M is assumed to be (0 0 0 1). That means that only the rotation (and scale) of M is applied to v.

Parameters
vA direction vector.
Returns
M*v. The w-component of the returned vector is implied to be 0.
template<class T>
Vector3fT Matrix4x4T< T >::Mul0 ( const Vector3fT v) const
inline
Parameters
vA direction vector.
Returns
M*v. The w-component of the returned vector is implied to be 0.
template<class T>
Vector3dT Matrix4x4T< T >::Mul1 ( const Vector3dT v) const
inline

Computes M*v, where M is this matrix.

The w-component of v is assumed to be 1 (v being a point, not a direction vector). The last row of M is assumed to be (0 0 0 1). That means that both the rotation (and scale) and the translation of M is applied to v.

Parameters
vA point.
Returns
M*v. The w-component of the returned vector is implied to be 1.
template<class T>
Vector3fT Matrix4x4T< T >::Mul1 ( const Vector3fT v) const
inline
Parameters
vA point.
Returns
M*v. The w-component of the returned vector is implied to be 1.
template<class T>
Vector3T<T> Matrix4x4T< T >::Mul_xyz1 ( const Vector3T< T > &  v) const
inline

Computes M*v, where M is this matrix.

The w-component of v is assumed to be 1 (v being a point, not a direction vector). The last row of M is assumed to be (0 0 0 1). That means that both the rotation (and scale) and the translation of M is applied to v.

Parameters
vA point.
Returns
M*v. The w-component of the returned vector is implied to be 1.
template<class T>
void Matrix4x4T< T >::Mul_xyz1 ( const T  v[3],
out[3] 
) const
inline

Computes M*v, where M is this matrix.

The w-component of v is assumed to be 1 (v being a point, not a direction vector). The last row of M is assumed to be (0 0 0 1). That means that both the rotation (and scale) and the translation of M is applied to v.

Parameters
vA point.
outThe result of M*v.
template<class T >
Matrix4x4T< T > Matrix4x4T< T >::operator* ( const Matrix4x4T< T > &  Other) const

Computes M*Other, that is, the matrix product of this and the Other matrix.

Parameters
OtherThe other matrix (right side).
Returns
The matrix product of this and the Other matrix.
template<class T>
T* Matrix4x4T< T >::operator[] ( unsigned int  i)
inline

Returns the i-th row of this matrix.

template<class T>
const T* Matrix4x4T< T >::operator[] ( unsigned int  i) const
inline

Returns the i-th row of this matrix.

template<class T>
Vector3T<T> Matrix4x4T< T >::ProjectPoint ( const Vector3T< T > &  v) const
inline

Computes M*v, where M is this matrix.

The w-component of v is assumed to be 1 (v being a point, not a direction vector). The resulting 4-tuple is divided by the w-component so that only the xyz components must be returned.

Parameters
vA point.
Returns
M*v. The w-component of the returned vector is implied to be 1.
template<class T>
void Matrix4x4T< T >::RotateX_MR ( Angle)

Computes M=M*R, where R=GetRotateXMatrix (Angle).

template<class T>
void Matrix4x4T< T >::RotateX_RM ( Angle)

Computes M=R*M, where R=GetRotateXMatrix (Angle).

template<class T>
void Matrix4x4T< T >::RotateY_MR ( Angle)

Computes M=M*R, where R=GetRotateYMatrix (Angle).

template<class T>
void Matrix4x4T< T >::RotateY_RM ( Angle)

Computes M=R*M, where R=GetRotateYMatrix (Angle).

template<class T>
void Matrix4x4T< T >::RotateZ_MR ( Angle)

Computes M=M*R, where R=GetRotateZMatrix (Angle).

template<class T>
void Matrix4x4T< T >::RotateZ_RM ( Angle)

Computes M=R*M, where R=GetRotateZMatrix (Angle).

template<class T>
void Matrix4x4T< T >::Scale_MS ( sx,
sy,
sz 
)

Computes M=M*S, where S=GetScaleMatrix (sx, sy, sz).

template<class T>
void Matrix4x4T< T >::Scale_SM ( sx,
sy,
sz 
)

Computes M=S*M, where S=GetScaleMatrix (sx, sy, sz).

template<class T >
void Matrix4x4T< T >::Translate_MT ( const Vector3dT Trans)

Computes M=M*T, where T=GetTranslationMatrix(Trans). Assumes that the last row is (0 0 0 1).

template<class T>
void Matrix4x4T< T >::Translate_MT ( tx,
ty,
tz 
)

Computes M=M*T, where T=GetTranslationMatrix(Trans). Assumes that the last row is (0 0 0 1).

template<class T >
void Matrix4x4T< T >::Translate_TM ( const Vector3dT Trans)

Computes M=T*M, where T=GetTranslationMatrix(Trans). Assumes that the last row is (0 0 0 1).

Member Data Documentation

template<class T>
T Matrix4x4T< T >::m[4][4]

The matrix values.


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