ezEngine  Milestone 7
ezMat4Template< Type > Class Template Reference

A 4x4 component matrix class. More...

#include <Mat4.h>

Public Types

typedef Type ComponentType
 

Public Member Functions

 EZ_DECLARE_POD_TYPE ()
 
Type & Element (ezInt32 column, ezInt32 row)
 
Type Element (ezInt32 column, ezInt32 row) const
 
 ezMat4Template ()
 Default Constructor DOES NOT INITIALIZE the matrix, at all.
 
 ezMat4Template (const Type *const pData, ezMatrixLayout::Enum layout)
 Copies 16 values from pData into the matrix. Can handle the data in row-major or column-major order. More...
 
 ezMat4Template (Type c1r1, Type c2r1, Type c3r1, Type c4r1, Type c1r2, Type c2r2, Type c3r2, Type c4r2, Type c1r3, Type c2r3, Type c3r3, Type c4r3, Type c1r4, Type c2r4, Type c3r4, Type c4r4)
 Sets each element manually: Naming is "column-n row-m".
 
 ezMat4Template (const ezMat3Template< Type > &Rotation, const ezVec3Template< Type > &vTranslation)
 Creates a transformation matrix from a rotation and a translation.
 
void SetFromArray (const Type *const pData, ezMatrixLayout::Enum layout)
 Copies 16 values from pData into the matrix. Can handle the data in row-major or column-major order. More...
 
void GetAsArray (Type *out_pData, ezMatrixLayout::Enum layout) const
 Copies the 16 values of this matrix into the given array. 'layout' defines whether the data should end up in column-major or row-major format.
 
void SetElements (Type c1r1, Type c2r1, Type c3r1, Type c4r1, Type c1r2, Type c2r2, Type c3r2, Type c4r2, Type c1r3, Type c2r3, Type c3r3, Type c4r3, Type c1r4, Type c2r4, Type c3r4, Type c4r4)
 Sets each element manually: Naming is "column-n row-m".
 
void SetTransformationMatrix (const ezMat3Template< Type > &Rotation, const ezVec3Template< Type > &vTranslation)
 Sets a transformation matrix from a rotation and a translation.
 
void SetZero ()
 Sets all elements to zero.
 
void SetIdentity ()
 Sets all elements to zero, except the diagonal, which is set to one.
 
void SetTranslationMatrix (const ezVec3Template< Type > &vTranslation)
 Sets the matrix to all zero, except the last column, which is set to x,y,z,1.
 
void SetScalingMatrix (const ezVec3Template< Type > &vScale)
 Sets the matrix to all zero, except the diagonal, which is set to x,y,z,1.
 
void SetRotationMatrixX (ezAngle angle)
 Sets this matrix to be a rotation matrix around the X-axis.
 
void SetRotationMatrixY (ezAngle angle)
 Sets this matrix to be a rotation matrix around the Y-axis.
 
void SetRotationMatrixZ (ezAngle angle)
 Sets this matrix to be a rotation matrix around the Z-axis.
 
void SetRotationMatrix (const ezVec3Template< Type > &vAxis, ezAngle angle)
 Sets this matrix to be a rotation matrix around the given axis.
 
void SetPerspectiveProjectionMatrix (Type fViewWidth, Type fViewHeight, Type fNearZ, Type fFarZ, ezProjectionDepthRange::Enum DepthRange=ezProjectionDepthRange::Default)
 Creates a perspective projection matrix with Left = -fViewWidth/2, Right = +fViewWidth/2, Bottom = -fViewHeight/2, Top = +fViewHeight/2.
 
void SetPerspectiveProjectionMatrix (Type fLeft, Type fRight, Type fBottom, Type fTop, Type fNearZ, Type fFarZ, ezProjectionDepthRange::Enum DepthRange=ezProjectionDepthRange::Default)
 Creates a perspective projection matrix.
 
void SetPerspectiveProjectionMatrixFromFovX (ezAngle fieldOfViewX, Type fAspectRatioWidthDivHeight, Type fNearZ, Type fFarZ, ezProjectionDepthRange::Enum DepthRange=ezProjectionDepthRange::Default)
 Creates a perspective projection matrix. More...
 
void SetPerspectiveProjectionMatrixFromFovY (ezAngle fieldOfViewY, Type fAspectRatioWidthDivHeight, Type fNearZ, Type fFarZ, ezProjectionDepthRange::Enum DepthRange=ezProjectionDepthRange::Default)
 Creates a perspective projection matrix. More...
 
void SetOrthographicProjectionMatrix (Type fViewWidth, Type fViewHeight, Type fNearZ, Type fFarZ, ezProjectionDepthRange::Enum DepthRange=ezProjectionDepthRange::Default)
 Creates an orthographic projection matrix with Left = -fViewWidth/2, Right = +fViewWidth/2, Bottom = -fViewHeight/2, Top = +fViewHeight/2.
 
void SetOrthographicProjectionMatrix (Type fLeft, Type fRight, Type fBottom, Type fTop, Type fNearZ, Type fFarZ, ezProjectionDepthRange::Enum DepthRange=ezProjectionDepthRange::Default)
 Creates an orthographic projection matrix.
 
void SetLookAtMatrix (const ezVec3Template< Type > &vStartPos, const ezVec3Template< Type > &vTargetPos, const ezVec3Template< Type > &vUpDir)
 Creates a look-at matrix.
 
void Transpose ()
 Transposes this matrix.
 
const ezMat4Template< Type > GetTranspose () const
 Returns the transpose of this matrix.
 
ezResult Invert (Type fEpsilon=ezMath::BasicType< Type >::SmallEpsilon())
 Inverts this matrix. Return value indicates whether the matrix could be inverted.
 
const ezMat4Template< Type > GetInverse () const
 Returns the inverse of this matrix.
 
bool IsZero (Type fEpsilon=ezMath::BasicType< Type >::DefaultEpsilon()) const
 Checks whether all elements are zero.
 
bool IsIdentity (Type fEpsilon=ezMath::BasicType< Type >::DefaultEpsilon()) const
 Checks whether this is an identity matrix.
 
bool IsValid () const
 Checks whether all components are finite numbers.
 
bool IsNaN () const
 Checks whether any component is NaN.
 
ezVec4Template< Type > GetRow (ezUInt32 uiRow) const
 Returns all 4 components of the i-th row.
 
void SetRow (ezUInt32 uiRow, const ezVec4Template< Type > &row)
 Sets all 4 components of the i-th row.
 
ezVec4Template< Type > GetColumn (ezUInt32 uiColumn) const
 Returns all 4 components of the i-th column.
 
void SetColumn (ezUInt32 uiColumn, const ezVec4Template< Type > &column)
 Sets all 4 components of the i-th column.
 
ezVec4Template< Type > GetDiagonal () const
 Returns all 4 components on the diagonal of the matrix.
 
void SetDiagonal (const ezVec4Template< Type > &diag)
 Sets all 4 components on the diagonal of the matrix.
 
const ezVec3Template< Type > GetTranslationVector () const
 Returns the first 3 components of the last column.
 
void SetTranslationVector (const ezVec3Template< Type > &v)
 Sets the first 3 components of the last column.
 
void SetRotationalPart (const ezMat3Template< Type > &Rotation)
 Sets the 3x3 rotational part of the matrix.
 
const ezMat3Template< Type > GetRotationalPart () const
 Returns the 3x3 rotational part of the matrix.
 
const ezVec3Template< Type > GetScalingFactors () const
 Returns the 3 scaling factors that are encoded in the matrix.
 
ezResult SetScalingFactors (const ezVec3Template< Type > &vXYZ, Type fEpsilon=ezMath::BasicType< Type >::DefaultEpsilon())
 Tries to set the three scaling factors in the matrix. Returns EZ_FAILURE if the matrix columns cannot be normalized and thus no rescaling is possible.
 
const ezVec3Template< Type > TransformPosition (const ezVec3Template< Type > &v) const
 Matrix-vector multiplication, assuming the 4th component of the vector is one (default behavior).
 
void TransformPosition (ezVec3Template< Type > *inout_v, ezUInt32 uiNumVectors, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) const
 Matrix-vector multiplication, assuming the 4th component of the vector is one (default behavior).
 
const ezVec3Template< Type > TransformDirection (const ezVec3Template< Type > &v) const
 Matrix-vector multiplication, assuming the 4th component of the vector is zero. So, rotation/scaling only. Useful as an optimization.
 
void TransformDirection (ezVec3Template< Type > *inout_v, ezUInt32 uiNumVectors, ezUInt32 uiStride=sizeof(ezVec3Template< Type >)) const
 Matrix-vector multiplication, assuming the 4th component of the vector is zero. So, rotation/scaling only. Useful as an optimization.
 
const ezVec4Template< Type > Transform (const ezVec4Template< Type > &v) const
 Matrix-vector multiplication.
 
void Transform (ezVec4Template< Type > *inout_v, ezUInt32 uiNumVectors, ezUInt32 uiStride=sizeof(ezVec4Template< Type >)) const
 Matrix-vector multiplication.
 
void operator*= (Type f)
 Component-wise multiplication (commutative)
 
void operator/= (Type f)
 Component-wise division.
 
bool IsIdentical (const ezMat4Template< Type > &rhs) const
 Equality Check.
 
bool IsEqual (const ezMat4Template< Type > &rhs, Type fEpsilon) const
 Equality Check with epsilon.
 

Static Public Member Functions

static const ezMat4Template< Type > IdentityMatrix ()
 Returns an Identity Matrix.
 
static const ezMat4Template< Type > ZeroMatrix ()
 Returns a Zero Matrix.
 

Public Attributes

Type m_fElementsCM [16]
 The matrix as a 16-element Type array (column-major)
 

Detailed Description

template<typename Type>
class ezMat4Template< Type >

A 4x4 component matrix class.

Constructor & Destructor Documentation

template<typename Type>
ezMat4Template< Type >::ezMat4Template ( const Type *const  pData,
ezMatrixLayout::Enum  layout 
)

Copies 16 values from pData into the matrix. Can handle the data in row-major or column-major order.

Parameters
pDataThe array of Type values from which to set the matrix data.
layoutThe layout in which pData stores the matrix. The data will get transposed, if necessary. The data should be in column-major format, if you want to prevent unnecessary transposes.

Member Function Documentation

template<typename Type>
void ezMat4Template< Type >::SetFromArray ( const Type *const  pData,
ezMatrixLayout::Enum  layout 
)

Copies 16 values from pData into the matrix. Can handle the data in row-major or column-major order.

Parameters
pDataThe array of Type values from which to set the matrix data.
layoutThe layout in which pData stores the matrix. The data will get transposed, if necessary. The data should be in column-major format, if you want to prevent unnecessary transposes.
template<typename Type>
void ezMat4Template< Type >::SetPerspectiveProjectionMatrixFromFovX ( ezAngle  fieldOfViewX,
Type  fAspectRatioWidthDivHeight,
Type  fNearZ,
Type  fFarZ,
ezProjectionDepthRange::Enum  DepthRange = ezProjectionDepthRange::Default 
)

Creates a perspective projection matrix.

Parameters
fFieldOfViewXHorizontal field of view.
template<typename Type>
void ezMat4Template< Type >::SetPerspectiveProjectionMatrixFromFovY ( ezAngle  fieldOfViewY,
Type  fAspectRatioWidthDivHeight,
Type  fNearZ,
Type  fFarZ,
ezProjectionDepthRange::Enum  DepthRange = ezProjectionDepthRange::Default 
)

Creates a perspective projection matrix.

Parameters
fFieldOfViewYVertical field of view.

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