PixelLightAPI  .
Public Member Functions | Public Attributes | Static Public Attributes
PLMath::Matrix4x4 Class Reference

4x4 matrix More...

#include <Matrix4x4.h>

List of all members.

Public Member Functions

 Matrix4x4 ()
 Default constructor setting an identity matrix.
 Matrix4x4 (const float fS[])
PLMATH_API Matrix4x4 (const Matrix3x3 &mM)
PLMATH_API Matrix4x4 (const Matrix3x4 &mM)
 Matrix4x4 (const Matrix4x4 &mM)
 Matrix4x4 (float fXX, float fXY, float fXZ, float fXW, float fYX, float fYY, float fYZ, float fYW, float fZX, float fZY, float fZZ, float fZW, float fWX, float fWY, float fWZ, float fWW)
 ~Matrix4x4 ()
PLMATH_API bool operator== (const Matrix3x4 &mM) const
PLMATH_API bool operator== (const Matrix4x4 &mM) const
PLMATH_API bool operator!= (const Matrix3x4 &mM) const
PLMATH_API bool operator!= (const Matrix4x4 &mM) const
PLMATH_API bool CompareScale (const Matrix4x4 &mM, float fEpsilon=Math::Epsilon) const
PLMATH_API bool CompareTranslation (const Matrix4x4 &mM, float fEpsilon=Math::Epsilon) const
PLMATH_API bool CompareRotation (const Matrix4x4 &mM, float fEpsilon=Math::Epsilon) const
Matrix4x4operator= (const float fS[])
PLMATH_API Matrix4x4operator= (const Matrix3x3 &mM)
PLMATH_API Matrix4x4operator= (const Matrix3x4 &mM)
Matrix4x4operator= (const Matrix4x4 &mM)
Matrix4x4 operator+ (const Matrix4x4 &mM) const
void operator+= (const Matrix4x4 &mM)
Matrix4x4 operator- () const
Matrix4x4 operator- (const Matrix4x4 &mM) const
void operator-= (const Matrix4x4 &mM)
Matrix4x4 operator* (float fS) const
void operator*= (float fS)
Vector2 operator* (const Vector2 &vV) const
Vector3 operator* (const Vector3 &vV) const
Vector4 operator* (const Vector4 &vV) const
PLMATH_API Matrix4x4 operator* (const Matrix3x4 &mM) const
PLMATH_API Matrix4x4 operator* (const Matrix4x4 &mM) const
void operator*= (const Matrix3x4 &mM)
void operator*= (const Matrix4x4 &mM)
Matrix4x4 operator/ (float fS) const
void operator/= (float fS)
float operator[] (int nIndex) const
float & operator[] (int nIndex)
float operator() (PLCore::uint32 nRow=0, PLCore::uint32 nColumn=0) const
float & operator() (PLCore::uint32 nRow=0, PLCore::uint32 nColumn=0)
 operator float * ()
 operator const float * () const
bool IsZero () const
 Returns whether or not this matrix is the zero matrix using an epsilon environment.
bool IsTrueZero () const
 Returns whether or not this matrix is truly the zero matrix.
void SetZero ()
 Sets a zero matrix.
bool IsIdentity () const
 Returns whether or not this matrix is the identity matrix using an epsilon environment.
bool IsTrueIdentity () const
 Returns whether or not this matrix is truly the identity matrix.
void SetIdentity ()
 Sets an identity matrix.
PLMATH_API void Set (float fXX, float fXY, float fXZ, float fXW, float fYX, float fYY, float fYZ, float fYW, float fZX, float fZY, float fZZ, float fZW, float fWX, float fWY, float fWZ, float fWW)
 Sets the elements of the matrix.
Vector4 GetRow (PLCore::uint8 nRow) const
 Returns a requested row.
void SetRow (PLCore::uint8 nRow, const Vector4 &vRow)
 Sets a row.
Vector4 GetColumn (PLCore::uint8 nColumn) const
 Returns a requested column.
void SetColumn (PLCore::uint8 nColumn, const Vector4 &vColumn)
 Sets a column.
bool IsSymmetric () const
 Returns true if the matrix is symmetric.
bool IsOrthogonal () const
 Returns true if this matrix is orthogonal.
bool IsRotationMatrix () const
 Returns true if this matrix is a rotation matrix.
bool IsRotationTranslationMatrix () const
 Returns true if this matrix is a rotation and translation matrix.
float GetTrace () const
 Returns the trace of the matrix.
PLMATH_API float GetDeterminant () const
 Returns the determinant of the matrix.
PLMATH_API void Transpose ()
 Transpose this matrix.
PLMATH_API Matrix4x4 GetTransposed () const
 Returns the transposed matrix.
PLMATH_API bool Invert ()
 Inverts the matrix.
PLMATH_API Matrix4x4 GetInverted () const
 Returns the inverse of the matrix.
PLMATH_API Vector3 RotateVector (float fX, float fY, float fZ, bool bUniformScale=false) const
 Rotates a vector.
PLMATH_API Vector3 RotateVector (const Vector3 &vV, bool bUniformScale=false) const
 Rotates a vector.
void SetScaleMatrix (float fX, float fY, float fZ)
 Sets a scale matrix.
void SetScaleMatrix (const Vector3 &vV)
PLMATH_API void GetScale (float &fX, float &fY, float &fZ) const
 Extracts the scale vector from the matrix as good as possible.
Vector3 GetScale () const
void GetScale (float fV[]) const
void SetTranslationMatrix (float fX, float fY, float fZ)
 Sets a translation matrix.
void SetTranslationMatrix (const Vector3 &vV)
void GetTranslation (float &fX, float &fY, float &fZ) const
Vector3 GetTranslation () const
void GetTranslation (float fV[]) const
void SetTranslation (float fX=0.0f, float fY=0.0f, float fZ=0.0f)
void SetTranslation (const Vector3 &vV)
void SetTranslation (const float fV[])
PLMATH_API void FromEulerAngleX (float fAngleX)
 Sets an x axis rotation matrix by using one given Euler angle.
PLMATH_API void FromEulerAngleY (float fAngleY)
 Sets an y axis rotation matrix by using one given Euler angle.
PLMATH_API void FromEulerAngleZ (float fAngleZ)
 Sets an z axis rotation matrix by using one given Euler angle.
PLMATH_API void ToAxisAngle (float &fX, float &fY, float &fZ, float &fAngle) const
 Returns a rotation matrix as a selected axis and angle.
PLMATH_API void FromAxisAngle (float fX, float fY, float fZ, float fAngle)
 Sets a rotation matrix by using a selected axis and angle.
Vector3 GetXAxis () const
 Returns the x (left) axis.
Vector3 GetYAxis () const
 Returns the y (up) axis.
Vector3 GetZAxis () const
 Returns the z (forward) axis.
PLMATH_API void ToAxis (Vector3 &vX, Vector3 &vY, Vector3 &vZ) const
 Returns the three axis of a rotation matrix (not normalized)
PLMATH_API void FromAxis (const Vector3 &vX, const Vector3 &vY, const Vector3 &vZ)
 Sets a rotation matrix by using three given axis.
PLMATH_API Matrix4x4LookAt (const Vector3 &vEye, const Vector3 &vAt, const Vector3 &vUp)
 Builds a look-at matrix.
PLMATH_API Matrix4x4View (const Quaternion &qRotation, const Vector3 &vPosition)
 Builds a view matrix.
PLMATH_API Matrix4x4FromQuatTrans (const Quaternion &qRotation, const Vector3 &vTranslation)
 Sets a matrix using a given quaternion and translation.
Matrix4x4SetShearing (float fShearXY, float fShearXZ, float fShearYX, float fShearYZ, float fShearZX, float fShearZY)
 Sets a shearing matrix.
PLMATH_API Matrix4x4SetReflection (const Plane &cPlane)
 Sets a matrix that reflects the coordinate system about a plane.
PLMATH_API Matrix4x4SetShadowProjection (const Vector4 &vLight, const Plane &cPlane)
 Sets a shadow projection matrix.
PLMATH_API void RestrictedProjection (const Vector2 &vStartPos, const Vector2 &vEndPos, int nX, int nY, int nWidth, int nHeight)
 Creates a projection matrix that restricts drawing to a small region of the given viewport.
PLMATH_API Matrix4x4Perspective (float fWidth, float fHeight, float fZNear, float fZFar)
 Builds a perspective projection matrix.
PLMATH_API Matrix4x4PerspectiveFov (float fFov, float fAspect, float fZNear, float fZFar)
 Builds a perspective projection matrix based on a field of view.
PLMATH_API Matrix4x4PerspectiveInfinite (float fWidth, float fHeight, float fZNear)
 Builds an infinite perspective projection matrix.
PLMATH_API Matrix4x4PerspectiveFovInfinite (float fFov, float fAspect, float fZNear)
 Builds an infinite perspective projection matrix based on a field of view.
PLMATH_API Matrix4x4PerspectiveOffCenter (float fL, float fR, float fB, float fT, float fZNear, float fZFar)
 Builds a customized, perspective projection matrix.
PLMATH_API Matrix4x4Ortho (float fWidth, float fHeight, float fZNear, float fZFar)
 Builds a orthogonal projection matrix.
PLMATH_API Matrix4x4OrthoOffCenter (float fL, float fR, float fT, float fB, float fZNear, float fZFar)
 Builds a customized, orthogonal projection matrix.

Public Attributes

union {
   float   fM [16]
 One dimensional array representation.
   struct {
      float   xx
      float   yx
      float   zx
      float   wx
      float   xy
      float   yy
      float   zy
      float   wy
      float   xz
      float   yz
      float   zz
      float   wz
      float   xw
      float   yw
      float   zw
      float   ww
   } 
 Direct element representation.
   struct {
      float   fM44 [4][4]
   } 
 Two dimensional array representation.
}; 
 Some direct matrix accesses.

Static Public Attributes

static PLMATH_API const Matrix4x4 Zero
static PLMATH_API const Matrix4x4 Identity

Detailed Description

4x4 matrix

Remarks:
Matrices are stored in column major order like OpenGL does. (right-handed matrix) So, it's possible to give OpenGL the matrix data without transposing it first.
Note:
  • Some symbols within the comments: T = transposed, I = identity

Constructor & Destructor Documentation

Default constructor setting an identity matrix.

PLMath::Matrix4x4::Matrix4x4 ( const float  fS[]) [inline]
PLMATH_API PLMath::Matrix4x4::Matrix4x4 ( const Matrix3x3 mM)
PLMATH_API PLMath::Matrix4x4::Matrix4x4 ( const Matrix3x4 mM)
PLMath::Matrix4x4::Matrix4x4 ( const Matrix4x4 mM) [inline]
PLMath::Matrix4x4::Matrix4x4 ( float  fXX,
float  fXY,
float  fXZ,
float  fXW,
float  fYX,
float  fYY,
float  fYZ,
float  fYW,
float  fZX,
float  fZY,
float  fZZ,
float  fZW,
float  fWX,
float  fWY,
float  fWZ,
float  fWW 
) [inline]

Member Function Documentation

PLMATH_API bool PLMath::Matrix4x4::operator== ( const Matrix3x4 mM) const

3x4: The last row is compared with (0, 0, 0, 1)

PLMATH_API bool PLMath::Matrix4x4::operator== ( const Matrix4x4 mM) const
PLMATH_API bool PLMath::Matrix4x4::operator!= ( const Matrix3x4 mM) const

3x4: The last row is compared with (0, 0, 0, 1)

PLMATH_API bool PLMath::Matrix4x4::operator!= ( const Matrix4x4 mM) const
PLMATH_API bool PLMath::Matrix4x4::CompareScale ( const Matrix4x4 mM,
float  fEpsilon = Math::Epsilon 
) const
PLMATH_API bool PLMath::Matrix4x4::CompareTranslation ( const Matrix4x4 mM,
float  fEpsilon = Math::Epsilon 
) const
PLMATH_API bool PLMath::Matrix4x4::CompareRotation ( const Matrix4x4 mM,
float  fEpsilon = Math::Epsilon 
) const
Matrix4x4 & PLMath::Matrix4x4::operator= ( const float  fS[]) [inline]
PLMATH_API Matrix4x4& PLMath::Matrix4x4::operator= ( const Matrix3x3 mM)
PLMATH_API Matrix4x4& PLMath::Matrix4x4::operator= ( const Matrix3x4 mM)
Matrix4x4 & PLMath::Matrix4x4::operator= ( const Matrix4x4 mM) [inline]
Matrix4x4 PLMath::Matrix4x4::operator+ ( const Matrix4x4 mM) const [inline]
void PLMath::Matrix4x4::operator+= ( const Matrix4x4 mM) [inline]
Matrix4x4 PLMath::Matrix4x4::operator- ( ) const [inline]
Matrix4x4 PLMath::Matrix4x4::operator- ( const Matrix4x4 mM) const [inline]
void PLMath::Matrix4x4::operator-= ( const Matrix4x4 mM) [inline]
Matrix4x4 PLMath::Matrix4x4::operator* ( float  fS) const [inline]
void PLMath::Matrix4x4::operator*= ( float  fS) [inline]
Vector2 PLMath::Matrix4x4::operator* ( const Vector2 vV) const [inline]
Vector3 PLMath::Matrix4x4::operator* ( const Vector3 vV) const [inline]
Vector4 PLMath::Matrix4x4::operator* ( const Vector4 vV) const [inline]
PLMATH_API Matrix4x4 PLMath::Matrix4x4::operator* ( const Matrix3x4 mM) const

A 4x4*3x4 matrix multiplication is NOT defined, so we use the given 3x4 matrix with a fourth row (0, 0, 0, 1) which result in a 4x4*4x4 matrix multiplication which is allowed

PLMATH_API Matrix4x4 PLMath::Matrix4x4::operator* ( const Matrix4x4 mM) const
void PLMath::Matrix4x4::operator*= ( const Matrix3x4 mM) [inline]
See also:
- *(const Matrix3x4 &mM)
void PLMath::Matrix4x4::operator*= ( const Matrix4x4 mM) [inline]
Matrix4x4 PLMath::Matrix4x4::operator/ ( float  fS) const [inline]
void PLMath::Matrix4x4::operator/= ( float  fS) [inline]
float PLMath::Matrix4x4::operator[] ( int  nIndex) const [inline]
float & PLMath::Matrix4x4::operator[] ( int  nIndex) [inline]
float PLMath::Matrix4x4::operator() ( PLCore::uint32  nRow = 0,
PLCore::uint32  nColumn = 0 
) const [inline]
float & PLMath::Matrix4x4::operator() ( PLCore::uint32  nRow = 0,
PLCore::uint32  nColumn = 0 
) [inline]
PLMath::Matrix4x4::operator float * ( ) [inline]
PLMath::Matrix4x4::operator const float * ( ) const [inline]
bool PLMath::Matrix4x4::IsZero ( ) const [inline]

Returns whether or not this matrix is the zero matrix using an epsilon environment.

Returns:
'true' if this matrix is the zero matrix, else 'false'
bool PLMath::Matrix4x4::IsTrueZero ( ) const [inline]

Returns whether or not this matrix is truly the zero matrix.

Returns whether or not this matrix is truely the zero matrix.

Remarks:
All components MUST be exactly 0. Floating point inaccuracy is not taken into account.
Returns:
'true' if this matrix is truly the zero matrix, else 'false'
void PLMath::Matrix4x4::SetZero ( ) [inline]

Sets a zero matrix.

Remarks:
    | 0 0 0 0 |
    | 0 0 0 0 |
    | 0 0 0 0 |
    | 0 0 0 0 |
bool PLMath::Matrix4x4::IsIdentity ( ) const [inline]

Returns whether or not this matrix is the identity matrix using an epsilon environment.

Returns:
'true' if this matrix is the identity matrix, else 'false'
bool PLMath::Matrix4x4::IsTrueIdentity ( ) const [inline]

Returns whether or not this matrix is truly the identity matrix.

Returns whether or not this matrix is truely the identity matrix.

Remarks:
All components MUST be exactly either 0 or 1. Floating point inaccuracy is not taken into account.
Returns:
'true' if this matrix is truly the identity matrix, else 'false'
void PLMath::Matrix4x4::SetIdentity ( ) [inline]

Sets an identity matrix.

Remarks:
    | 1 0 0 0 |
    | 0 1 0 0 |
    | 0 0 1 0 |
    | 0 0 0 1 |
PLMATH_API void PLMath::Matrix4x4::Set ( float  fXX,
float  fXY,
float  fXZ,
float  fXW,
float  fYX,
float  fYY,
float  fYZ,
float  fYW,
float  fZX,
float  fZY,
float  fZZ,
float  fZW,
float  fWX,
float  fWY,
float  fWZ,
float  fWW 
)

Sets the elements of the matrix.

Vector4 PLMath::Matrix4x4::GetRow ( PLCore::uint8  nRow) const [inline]

Returns a requested row.

Parameters:
[in]nRowIndex of the row to return (0-3)
Returns:
The requested row (null vector on error)
Remarks:
    | x y z w | <- Row 0
    | 0 0 0 0 |
    | 0 0 0 0 |
    | 0 0 0 0 |
void PLMath::Matrix4x4::SetRow ( PLCore::uint8  nRow,
const Vector4 vRow 
) [inline]

Sets a row.

Parameters:
[in]nRowIndex of the row to set (0-3)
[in]vRowRow vector
See also:
Vector4 PLMath::Matrix4x4::GetColumn ( PLCore::uint8  nColumn) const [inline]

Returns a requested column.

Parameters:
[in]nColumnIndex of the column to return (0-3)
Returns:
The requested column (null vector on error)
Remarks:
    | x 0 0 0 |
    | y 0 0 0 |
    | z 0 0 0 |
    | w 0 0 0 |
      ^
      |
      Column 0
void PLMath::Matrix4x4::SetColumn ( PLCore::uint8  nColumn,
const Vector4 vColumn 
) [inline]

Sets a column.

Parameters:
[in]nColumnIndex of the column to set (0-3)
[in]vColumnColumn vector
See also:
bool PLMath::Matrix4x4::IsSymmetric ( ) const [inline]

Returns true if the matrix is symmetric.

Returns true if this matrix is symmetric.

Returns:
'true' if the matrix is symmetric, else 'false'
Remarks:
A matrix is symmetric if it is equal to it's transposed matrix.
A = A^T -> a(i, j) = a(j, i)
bool PLMath::Matrix4x4::IsOrthogonal ( ) const [inline]

Returns true if this matrix is orthogonal.

Returns:
'true' if the matrix is orthogonal, else 'false'
Remarks:
A matrix is orthogonal if it's transposed matrix is equal to it's inversed matrix.
A^T = A^-1 or A*A^T = A^T*A = I
Note:
  • An orthogonal matrix is always nonsingular (invertible) and it's inverse is equal to it's transposed
  • The transpose and inverse of the matrix is orthogonal, too
  • Products of orthogonal matrices are orthogonal, too
  • The determinant of a orthogonal matrix is +/- 1
  • The row and column vectors of an orthogonal matrix form an orthonormal basis, that is, these vectors are unit-length and they are mutually perpendicular
bool PLMath::Matrix4x4::IsRotationMatrix ( ) const [inline]

Returns true if this matrix is a rotation matrix.

Returns:
'true' if this matrix is a rotation matrix, else 'false'
Remarks:
A rotation matrix is orthogonal and it's determinant is 1 to rule out reflections.
See also:

Returns true if this matrix is a rotation and translation matrix.

Returns:
'true' if this matrix is a rotation and translation matrix, else 'false'
Remarks:
A rotation and translation matrix looks like this:
      | x x x x |
      | x x x x |
      | x x x x |
      | 0 0 0 1 |
Were 'x' means this field is used and as you see the last row must be empty.
See also:
float PLMath::Matrix4x4::GetTrace ( ) const [inline]

Returns the trace of the matrix.

Returns:
The trace of the matrix
Remarks:
The trace of the matrix is the sum of the main diagonal elements:
xx+yy+zz+ww
PLMATH_API float PLMath::Matrix4x4::GetDeterminant ( ) const

Returns the determinant of the matrix.

Returns:
Determinant of the matrix
Note:
  • If the determinant is non-zero, then an inverse matrix exists
  • If the determinant is 0, the matrix is called singular, else nonsingular (invertible) matrix
  • If the determinant is 1, the inverse matrix is equal to the transpose of the matrix
PLMATH_API void PLMath::Matrix4x4::Transpose ( )

Transpose this matrix.

Remarks:
The transpose of matrix is the matrix generated when every element in the matrix is swapped with the opposite relative to the major diagonal This can be expressed as the mathematical operation:
      M'   = M
        ij    ji

      | xx xy xz xw |                    | xx yx zx wx |
      | yx yy yz yw |  the transpose is  | xy yy zy wy |
      | zx zy zz zw |                    | xz yz zz wz |
      | wx wy wz ww |                    | xw yw zw ww |
Note:
  • If the matrix is a rotation matrix (= isotropic matrix = determinant is 1), then the transpose is guaranteed to be the inverse of the matrix

Returns the transposed matrix.

Returns:
Transposed matrix
See also:
PLMATH_API bool PLMath::Matrix4x4::Invert ( )

Inverts the matrix.

Returns:
'true' if all went fine, else 'false' (maybe the determinant is null?)
Note:
  • If the determinant is 1, the inversed matrix is equal to the transposed one

Returns the inverse of the matrix.

Returns:
Inverse of the matrix, if the determinant is null, an identity matrix is returned
PLMATH_API Vector3 PLMath::Matrix4x4::RotateVector ( float  fX,
float  fY,
float  fZ,
bool  bUniformScale = false 
) const

Rotates a vector.

Parameters:
[in]fXX component of the vector to rotate
[in]fYY component of the vector to rotate
[in]fZZ component of the vector to rotate
[in]bUniformScaleIs this a uniform scale matrix? (all axis are scaled equally) If you know EXACTLY it's one, set this to 'true' to gain some more speed, else DON'T set to 'true'!
Returns:
The rotated vector
Remarks:
This function is similar to a matrix * vector operation - except that the translation of the matrix is ignored and this function can deal with none uniform scale. So, this function can for instance be used to rotate a direction vector. (matrix * direction vector)
Note:
  • You can't assume that the resulting vector is normalized
  • Use this function to rotate for example a normal vector
PLMATH_API Vector3 PLMath::Matrix4x4::RotateVector ( const Vector3 vV,
bool  bUniformScale = false 
) const

Rotates a vector.

Parameters:
[in]vVVector to rotate
[in]bUniformScaleIs this a uniform scale matrix? (all axis are scaled equally) If you know EXACTLY it's one, set this to 'true' to gain some more speed, else DON'T set to 'true'!
Returns:
The rotated vector
See also:
  • RotateVector(float, float, float) above
void PLMath::Matrix4x4::SetScaleMatrix ( float  fX,
float  fY,
float  fZ 
) [inline]

Sets a scale matrix.

Parameters:
[in]fXX scale
[in]fYY scale
[in]fZZ scale
Remarks:
    | x 0 0 0 |
    | 0 y 0 0 |
    | 0 0 z 0 |
    | 0 0 0 1 |
void PLMath::Matrix4x4::SetScaleMatrix ( const Vector3 vV) [inline]
PLMATH_API void PLMath::Matrix4x4::GetScale ( float &  fX,
float &  fY,
float &  fZ 
) const

Extracts the scale vector from the matrix as good as possible.

Parameters:
[out]fXReceives the x scale
[out]fYReceives the y scale
[out]fZReceives the z scale
Note:
  • This function will not work correctly if one or two components are negative while another is/are not (we can't figure out WHICH axis are negative!)
void PLMath::Matrix4x4::GetScale ( float  fV[]) const [inline]
void PLMath::Matrix4x4::SetTranslationMatrix ( float  fX,
float  fY,
float  fZ 
) [inline]

Sets a translation matrix.

Parameters:
[in]fXX translation
[in]fYY translation
[in]fZZ translation
Remarks:
    | 1 0 0 x |
    | 0 1 0 y |
    | 0 0 1 z |
    | 0 0 0 1 |
void PLMath::Matrix4x4::SetTranslationMatrix ( const Vector3 vV) [inline]
void PLMath::Matrix4x4::GetTranslation ( float &  fX,
float &  fY,
float &  fZ 
) const [inline]
void PLMath::Matrix4x4::GetTranslation ( float  fV[]) const [inline]
void PLMath::Matrix4x4::SetTranslation ( float  fX = 0.0f,
float  fY = 0.0f,
float  fZ = 0.0f 
) [inline]
void PLMath::Matrix4x4::SetTranslation ( const Vector3 vV) [inline]
void PLMath::Matrix4x4::SetTranslation ( const float  fV[]) [inline]
PLMATH_API void PLMath::Matrix4x4::FromEulerAngleX ( float  fAngleX)

Sets an x axis rotation matrix by using one given Euler angle.

Parameters:
[in]fAngleXRotation angle around the x axis (in radian, between [0, Math::Pi2])
Remarks:
         |    1       0       0    0 |
    RX = |    0     cos(a) -sin(a) 0 |
         |    0     sin(a)  cos(a) 0 |
         |    0       0       0    1 |
where a > 0 indicates a counterclockwise rotation in the yz-plane (if you look along -x)
PLMATH_API void PLMath::Matrix4x4::FromEulerAngleY ( float  fAngleY)

Sets an y axis rotation matrix by using one given Euler angle.

Parameters:
[in]fAngleYRotation angle around the y axis (in radian, between [0, Math::Pi2])
Remarks:
         |  cos(a)    0     sin(a) 0 |
    RY = |    0       1       0    0 |
         | -sin(a)    0     cos(a) 0 |
         |    0       0       0    1 |
where a > 0 indicates a counterclockwise rotation in the zx-plane (if you look along -y)
PLMATH_API void PLMath::Matrix4x4::FromEulerAngleZ ( float  fAngleZ)

Sets an z axis rotation matrix by using one given Euler angle.

Parameters:
[in]fAngleZRotation angle around the z axis (in radian, between [0, Math::Pi2])
Remarks:
         |  cos(a) -sin(a)    0    0 |
    RZ = |  sin(a)  cos(a)    0    0 |
         |    0       0       1    0 |
         |    0       0       0    1 |
where a > 0 indicates a counterclockwise rotation in the xy-plane (if you look along -z)
PLMATH_API void PLMath::Matrix4x4::ToAxisAngle ( float &  fX,
float &  fY,
float &  fZ,
float &  fAngle 
) const

Returns a rotation matrix as a selected axis and angle.

Parameters:
[out]fXWill receive the x component of the selected axis
[out]fYWill receive the y component of the selected axis
[out]fZWill receive the z component of the selected axis
[out]fAngleWill receive the rotation angle around the selected axis (in radian, between [0, Math::Pi])
PLMATH_API void PLMath::Matrix4x4::FromAxisAngle ( float  fX,
float  fY,
float  fZ,
float  fAngle 
)

Sets a rotation matrix by using a selected axis and angle.

Parameters:
[in]fXX component of the selected axis
[in]fYY component of the selected axis
[in]fZZ component of the selected axis
[in]fAngleRotation angle around the selected axis (in radian, between [0, Math::Pi])
Note:
  • The given selected axis must be normalized!

Returns the x (left) axis.

Returns:
The x (left) axis
Remarks:
    | x 0 0 0 |
    | y 0 0 0 |
    | z 0 0 0 |
    | 0 0 0 1 |
Note:
  • It's possible that the axis vector is not normalized because for instance the matrix was scaled

Returns the y (up) axis.

Returns:
The y (up) axis
Remarks:
    | 0 x 0 0 |
    | 0 y 0 0 |
    | 0 z 0 0 |
    | 0 0 0 1 |
See also:

Returns the z (forward) axis.

Returns:
The z (forward) axis
Remarks:
    | 0 0 x 0 |
    | 0 0 y 0 |
    | 0 0 z 0 |
    | 0 0 0 1 |
See also:
PLMATH_API void PLMath::Matrix4x4::ToAxis ( Vector3 vX,
Vector3 vY,
Vector3 vZ 
) const

Returns the three axis of a rotation matrix (not normalized)

Parameters:
[out]vXWill receive the x axis
[out]vYWill receive the y axis
[out]vZWill receive the z axis
Remarks:
    | vX.x vY.x vZ.x 0 |
    | vX.y vY.y vZ.y 0 |
    | vX.z vY.z vZ.z 0 |
    | 0    0    0    1 |
PLMATH_API void PLMath::Matrix4x4::FromAxis ( const Vector3 vX,
const Vector3 vY,
const Vector3 vZ 
)

Sets a rotation matrix by using three given axis.

Parameters:
[in]vXX axis
[in]vYY axis
[in]vZZ axis
See also:
PLMATH_API Matrix4x4& PLMath::Matrix4x4::LookAt ( const Vector3 vEye,
const Vector3 vAt,
const Vector3 vUp 
)

Builds a look-at matrix.

Parameters:
[in]vEyeEye position
[in]vAtCamera look-at target
[in]vUpCurrent world's up, usually [0, 1, 0]
Returns:
This instance
PLMATH_API Matrix4x4& PLMath::Matrix4x4::View ( const Quaternion qRotation,
const Vector3 vPosition 
)

Builds a view matrix.

Parameters:
[in]qRotationRotation quaternion
[in]vPositionPosition vector
Returns:
This instance
Remarks:
    | RotT.xx RotT.xy RotT.xz T.x |
    | RotT.yx RotT.yy RotT.yz T.y |
    | RotT.zx RotT.zy RotT.zz T.z |
    | 0       0       0       1   |

RotT = Transposed(Rot) T = -(Transposed(Rot) * Pos)

PLMATH_API Matrix4x4& PLMath::Matrix4x4::FromQuatTrans ( const Quaternion qRotation,
const Vector3 vTranslation 
)

Sets a matrix using a given quaternion and translation.

Parameters:
[in]qRotationRotation quaternion
[in]vTranslationTranslation vector
Returns:
This instance
Remarks:
First this function is using Quaternion::ToRotationMatrix() to create a rotation matrix. Then the translation components are set. (Matrix4x4::SetTranslation())
Matrix4x4 & PLMath::Matrix4x4::SetShearing ( float  fShearXY,
float  fShearXZ,
float  fShearYX,
float  fShearYZ,
float  fShearZX,
float  fShearZY 
) [inline]

Sets a shearing matrix.

Parameters:
[in]fShearXYShear X by Y
[in]fShearXZShear X by Z
[in]fShearYXShear Y by X
[in]fShearYZShear Y by Z
[in]fShearZXShear Z by X
[in]fShearZYShear Z by Y
Returns:
This instance
Remarks:
A shearing matrix can be used to for instance make a 3D model appear to slant sideways. Here's a table showing how a combined shearing matrix looks like:
    | 1        fShearYX  fShearZX  0 |
    | fShearXY 1         fShearZY  0 |
    | fShearXZ fShearYZ  1         0 |
    | 0        0         0         1 |
If you only want to shear one axis it's recommended to construct the matrix by yourself.
PLMATH_API Matrix4x4& PLMath::Matrix4x4::SetReflection ( const Plane cPlane)

Sets a matrix that reflects the coordinate system about a plane.

Parameters:
[in]cPlaneReflection plane (must be normalized!)
Returns:
This instance
Remarks:
    | -2*cPlane.a*cPlane.a+1 -2*cPlane.a*cPlane.b   -2*cPlane.a*cPlane.c   -2*cPlane.a*cPlane.d |
    | -2*cPlane.b*cPlane.a   -2*cPlane.b*cPlane.b+1 -2*cPlane.b*cPlane.c   -2*cPlane.b*cPlane.d |
    | -2*cPlane.c*cPlane.a   -2*cPlane.c*cPlane.b   -2*cPlane.c*cPlane.c+1 -2*cPlane.c*cPlane.d |
    |                      0                      0                      0                    1 |
PLMATH_API Matrix4x4& PLMath::Matrix4x4::SetShadowProjection ( const Vector4 vLight,
const Plane cPlane 
)

Sets a shadow projection matrix.

Parameters:
[in]vLightLight source position (if the light is directional, the w value should be 0)
[in]cPlanePlane where to project the shadow onto
Returns:
This instance
Remarks:
    | fDot-vLight.x*cPlane.a     -vLight.x*cPlane.b     -vLight.x*cPlane.c     -vLight.x*cPlane.d |
    |     -vLight.y*cPlane.a fDot-vLight.y*cPlane.b     -vLight.y*cPlane.c     -vLight.y*cPlane.d |
    |     -vLight.z*cPlane.a     -vLight.z*cPlane.b fDot-vLight.z*cPlane.c     -vLight.z*cPlane.d |
    |     -vLight.w*cPlane.a     -vLight.w*cPlane.b     -vLight.w*cPlane.c fDot-vLight.w*cPlane.d |

    where:
      float fDot = cPlane.a*vLight.x + cPlane.b*vLight.y + cPlane.c*vLight.z + cPlane.d*vLight.w;
PLMATH_API void PLMath::Matrix4x4::RestrictedProjection ( const Vector2 vStartPos,
const Vector2 vEndPos,
int  nX,
int  nY,
int  nWidth,
int  nHeight 
)

Creates a projection matrix that restricts drawing to a small region of the given viewport.

Parameters:
[in]vStartPosRegion start position
[in]vEndPosRegion end position
[in]nXX component of the pixel coordinate of the upper-left corner of the viewport
[in]nYY component of the pixel coordinate of the upper-left corner of the viewport
[in]nWidthWidth of the clip volume, in pixels
[in]nHeightHeight of the clip volume, in pixels
Note:
  • The start and end positions are within the given viewport
  • Multiply this projection matrix with our standard projection matrix to get a restricted version
PLMATH_API Matrix4x4& PLMath::Matrix4x4::Perspective ( float  fWidth,
float  fHeight,
float  fZNear,
float  fZFar 
)

Builds a perspective projection matrix.

Parameters:
[in]fWidthWidth of the view volume at the near view-plane
[in]fHeightHeight of the view volume at the near view-plane
[in]fZNearZ-value of the near view-plane (always positive)
[in]fZFarZ-value of the far view-plane (always positive)
Returns:
This instance
Remarks:
    | 2*fZNear/fWidth 0                0                    0                           |
    | 0               2*fZNear/fHeight 0                    0                           |
    | 0               0                fZFar/(fZNear-fZFar) fZNear*fZFar/(fZNear-fZFar) |
    | 0               0                -1                   0                           |
PLMATH_API Matrix4x4& PLMath::Matrix4x4::PerspectiveFov ( float  fFov,
float  fAspect,
float  fZNear,
float  fZFar 
)

Builds a perspective projection matrix based on a field of view.

Parameters:
[in]fFovThe field of view angle in the y direction (in radian)
[in]fAspectThe aspect ratio that determines the field of view in the x-direction The aspect ratio is the ratio of x (width) to y (height) (width/height)
[in]fZNearThe distance from the viewer to the near clipping plane (always positive)
[in]fZFarThe distance from the viewer to the far clipping plane (always positive)
Returns:
This instance
Remarks:
    | e/fAspect 0    0                             0                               |
    | 0         e    0                             0                               |
    | 0         0    (fZFar+fZNear)/(fZNear-fZFar) (2*fZNear*fZFar)/(fZNear-fZFar) |
    | 0         0    -1                            0                               |

    where:
      float e = 1/tanf(fFov/2); // Focal length
PLMATH_API Matrix4x4& PLMath::Matrix4x4::PerspectiveInfinite ( float  fWidth,
float  fHeight,
float  fZNear 
)

Builds an infinite perspective projection matrix.

Parameters:
[in]fWidthWidth of the view volume at the near view-plane
[in]fHeightHeight of the view volume at the near view-plane
[in]fZNearZ-value of the near view-plane (always positive)
Returns:
This instance
Remarks:
    | 2*fZNear/fWidth 0                0     0         |
    | 0               2*fZNear/fHeight 0     0         |
    | 0               0                -1    -2*fZNear |
    | 0               0                -1    0         |
PLMATH_API Matrix4x4& PLMath::Matrix4x4::PerspectiveFovInfinite ( float  fFov,
float  fAspect,
float  fZNear 
)

Builds an infinite perspective projection matrix based on a field of view.

Parameters:
[in]fFovThe field of view angle in the y direction (in radian)
[in]fAspectThe aspect ratio that determines the field of view in the x-direction The aspect ratio is the ratio of x (width) to y (height) (width/height)
[in]fZNearThe distance from the viewer to the near clipping plane (always positive)
Returns:
This instance
Remarks:
    | e/fAspect 0    0     0         |
    | 0         e    0     0         |
    | 0         0    -1    -2*fZNear |
    | 0         0    -1    0         |

    where:
      float e = 1/tanf(fFov/2); // Focal length
PLMATH_API Matrix4x4& PLMath::Matrix4x4::PerspectiveOffCenter ( float  fL,
float  fR,
float  fB,
float  fT,
float  fZNear,
float  fZFar 
)

Builds a customized, perspective projection matrix.

Parameters:
[in]fLMinimum x-value of view volume
[in]fRMaximum x-value of view volume
[in]fTMaximum y-value of view volume
[in]fBMinimum y-value of view volume
[in]fZNearMinimum z-value of the view volume
[in]fZFarMaximum z-value of the view volume
Remarks:
    | 2*fZNear/(fR-fL) 0                (fL+fR)/(fR-fL)      0                           |
    | 0                2*fZNear/(fT-fB) (fT+fB)/(fT-fB)      0                           |
    | 0                0                fZFar/(fZNear-fZFar) fZNear*fZFar/(fZNear-fZFar) |
    | 0                0                -1                   0                           |
Returns:
This instance
PLMATH_API Matrix4x4& PLMath::Matrix4x4::Ortho ( float  fWidth,
float  fHeight,
float  fZNear,
float  fZFar 
)

Builds a orthogonal projection matrix.

Parameters:
[in]fWidthWidth of the view volume
[in]fHeightHeight of the view volume
[in]fZNearMinimum z-value of the view volume
[in]fZFarMaximum z-value of the view volume
Returns:
This instance
Remarks:
    | 2/fWidth 0         0                0                     |
    | 0        2/fHeight 0                0                     |
    | 0        0         1/(fZNear-fZFar) fZNear/(fZNear-fZFar) |
    | 0        0         0                1                     |
Note:
  • An orthogonal matrix is an invertible matrix for which the inverse of the matrix is equal to the transpose of the matrix
PLMATH_API Matrix4x4& PLMath::Matrix4x4::OrthoOffCenter ( float  fL,
float  fR,
float  fT,
float  fB,
float  fZNear,
float  fZFar 
)

Builds a customized, orthogonal projection matrix.

Parameters:
[in]fLMinimum x-value of view volume
[in]fRMaximum x-value of view volume
[in]fTMaximum y-value of view volume
[in]fBMinimum y-value of view volume
[in]fZNearMinimum z-value of the view volume
[in]fZFarMaximum z-value of the view volume
Returns:
This instance
Remarks:
    | 2/(fR-fL) 0         0                (fL+fR)/(fL-fR)       |
    | 0         2/(fT-fB) 0                (fT+fB)/(fB-fT)       |
    | 0         0         1/(fZNear-fZFar) fZNear/(fZNear-fZFar) |
    | 0         0         0                1                     |
Note:
  • An orthogonal matrix is an invertible matrix for which the inverse of the matrix is equal to the transpose of the matrix

Member Data Documentation

PLMATH_API const Matrix4x4 PLMath::Matrix4x4::Zero [static]

Zero matrix

PLMATH_API const Matrix4x4 PLMath::Matrix4x4::Identity [static]

Identity matrix

One dimensional array representation.

Remarks:
The entry of the matrix in row r (0 <= r <= 3) and column c (0 <= c <= 3) is stored at index i = r+4*c (0 <= i <= 15).
Indices:
      | 0  4  8  12 |
      | 1  5  9  13 |
      | 2  6  10 14 |
      | 3  7  11 15 |
union { ... }

Some direct matrix accesses.


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


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:20
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported