My Project
Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
ParaEngine::Matrix4 Class Reference

Class encapsulating a standard 4x4 homogeneous matrix. More...

#include <ParaMatrix4.h>

Public Member Functions

 Matrix4 ()
 Default constructor. More...
 
 Matrix4 (float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
 
 Matrix4 (const Matrix3 &m3x3)
 Creates a standard 4x4 transformation matrix with a zero translation part from a rotation/scaling 3x3 matrix.
 
 Matrix4 (const DeviceMatrix &mat)
 
 Matrix4 (const QMatrix &mat2DAffine)
 convert from 2d affine matrix. More...
 
 Matrix4 (const Quaternion &rot)
 Creates a standard 4x4 transformation matrix with a zero translation part from a rotation/scaling Quaternion.
 
void identity ()
 make this identity
 
float * operator[] (size_t iRow)
 
const float *const operator[] (size_t iRow) const
 
Matrix4 operator* (const Matrix4 &m2) const
 Matrix4 concatenation using '*'.
 
Matrix4 Multiply4x3 (const Matrix4 &m2) const
 we will assume both matrix are row-major affine matrix. More...
 
void operator*= (const Matrix4 &m2)
 
Vector3 operator* (const Vector3 &v) const
 Vector transformation using '*'. More...
 
Vector4 operator* (const Vector4 &v) const
 
Plane operator* (const Plane &p) const
 
Matrix4 operator+ (const Matrix4 &m2) const
 Matrix4 addition.
 
Matrix4operator+= (const Matrix4 &m2)
 
Matrix4 operator- (const Matrix4 &m2) const
 Matrix4 subtraction.
 
Matrix4operator-= (const Matrix4 &m2)
 
bool operator== (const Matrix4 &m2) const
 Tests 2 matrices for equality.
 
bool operator!= (const Matrix4 &m2) const
 Tests 2 matrices for inequality.
 
void operator= (const Matrix3 &mat3)
 Assignment from 3x3 matrix.
 
Matrix4 transpose (void) const
 
void offsetTrans (const Vector3 &v)
 
void setTrans (const Vector3 &v)
 Sets the translation transformation part of the matrix.
 
Vector3 getTrans () const
 Extracts the translation transformation part of the matrix.
 
void makeTrans (const Vector3 &v)
 Builds a translation matrix.
 
void makeTrans (float tx, float ty, float tz)
 
void setScale (const Vector3 &v)
 Sets the scale part of the matrix.
 
void makeScale (float s_x, float s_y, float s_z)
 Gets a scale matrix - variation for not using a vector.
 
void makeScale (const Vector3 &v)
 
void extract3x3Matrix (Matrix3 &m3x3) const
 Extracts the rotation / scaling part of the Matrix4 as a 3x3 matrix. More...
 
bool hasScale () const
 Determines if this matrix involves a scaling. More...
 
bool hasNegativeScale () const
 Determines if this matrix involves a negative scaling. More...
 
Quaternion extractQuaternion () const
 Extracts the rotation / scaling part as a quaternion from the Matrix4.
 
Matrix4 operator* (float scalar) const
 
Matrix4 adjoint () const
 
float determinant () const
 
Matrix4 inverse () const
 
void invert ()
 
Matrix4 InvertPRMatrix () const
 Inverts a PR matrix. More...
 
void makeTransform (const Vector3 &position, const Vector3 &scale, const Quaternion &orientation)
 Building a Matrix4 from orientation / scale / position. More...
 
void makeRot (const Quaternion &orientation, const Vector3 &origin)
 make rotation matrix
 
void makeInverseTransform (const Vector3 &position, const Vector3 &scale, const Quaternion &orientation)
 Building an inverse Matrix4 from orientation / scale / position. More...
 
bool isAffine (void) const
 Check whether or not the matrix is affine row-major matrix. More...
 
bool isAffineColumnMajor (void) const
 
Vector3 transformAffine (const Vector3 &v) const
 Column vector: 3-D Vector transformation specially for affine matrix. More...
 
Vector4 transformAffine (const Vector4 &v) const
 Column vector: 4-D Vector transformation specially for affine matrix. More...
 
void RemoveScaling (float Tolerance=SMALL_NUMBER)
 
Matrix4 GetMatrixWithoutScale (float Tolerance=SMALL_NUMBER) const
 
Vector3 ExtractScaling (float Tolerance=SMALL_NUMBER)
 Remove any scaling from this matrix (ie magnitude of each row is 1) and return the 3D scale vector that was initially present. More...
 
Vector3 GetScaleVector (float Tolerance=SMALL_NUMBER) const
 return a 3D scale vector calculated from this matrix (where each component is the magnitude of a row vector). More...
 
float GetScaleByAxis (int axis, float Tolerance=SMALL_NUMBER) const
 
Matrix4 RemoveTranslation () const
 
DeviceMatrix_ptr GetPointer ()
 
const DeviceMatrix_ptr GetConstPointer () const
 

Public Attributes

union {
   struct {
      float   _11
 
      float   _12
 
      float   _13
 
      float   _14
 
      float   _21
 
      float   _22
 
      float   _23
 
      float   _24
 
      float   _31
 
      float   _32
 
      float   _33
 
      float   _34
 
      float   _41
 
      float   _42
 
      float   _43
 
      float   _44
 
   } 
 
   float   m [4][4]
 
   float   _m [16]
 
}; 
 The matrix entries, indexed by [row][col].
 

Static Public Attributes

static const Matrix4 ZERO
 
static const Matrix4 IDENTITY
 
static const Matrix4 CLIPSPACE2DTOIMAGESPACE
 Useful little matrix which takes 2D clipspace {-1, 1} to {0,1} and inverts the Y. More...
 

Friends

std::ostream & operator<< (std::ostream &o, const Matrix4 &m)
 Function for writing to a stream.
 

Detailed Description

Class encapsulating a standard 4x4 homogeneous matrix.

Remarks
ParaEngine uses row vectors when applying matrix multiplications, This means a vector is represented as a single row, 4-column matrix. This has the effect that the transformations implemented by the matrices happens left-to-right e.g. if vector V is to be transformed by M1 then M2 then M3, the calculation would be V * M1 * M2 * M3 . The order that matrices are concatenated is vital since matrix multiplication is not commutative, i.e. you can get a different result if you concatenate in the wrong order. But it is fine to use this class in a column-major math, the math are the same.
ParaEngine deals with the differences between D3D and OpenGL etc. internally when operating through different render systems.
matrix is indexed first by row and then by column.

Constructor & Destructor Documentation

§ Matrix4() [1/2]

ParaEngine::Matrix4::Matrix4 ( )
inline

Default constructor.

Note
It does NOT initialize the matrix for efficiency.

§ Matrix4() [2/2]

ParaEngine::Matrix4::Matrix4 ( const QMatrix mat2DAffine)

convert from 2d affine matrix.

Member Function Documentation

§ extract3x3Matrix()

void ParaEngine::Matrix4::extract3x3Matrix ( Matrix3 m3x3) const
inline

Extracts the rotation / scaling part of the Matrix4 as a 3x3 matrix.

Parameters
m3x3Destination Matrix3

§ ExtractScaling()

ParaEngine::Vector3 ParaEngine::Matrix4::ExtractScaling ( float  Tolerance = SMALL_NUMBER)

Remove any scaling from this matrix (ie magnitude of each row is 1) and return the 3D scale vector that was initially present.

§ GetScaleByAxis()

float ParaEngine::Matrix4::GetScaleByAxis ( int  axis,
float  Tolerance = SMALL_NUMBER 
) const
Parameters
axis0,1,2 for x,y,z

§ GetScaleVector()

ParaEngine::Vector3 ParaEngine::Matrix4::GetScaleVector ( float  Tolerance = SMALL_NUMBER) const

return a 3D scale vector calculated from this matrix (where each component is the magnitude of a row vector).

§ hasNegativeScale()

bool ParaEngine::Matrix4::hasNegativeScale ( ) const
inline

Determines if this matrix involves a negative scaling.

§ hasScale()

bool ParaEngine::Matrix4::hasScale ( ) const

Determines if this matrix involves a scaling.

§ InvertPRMatrix()

Matrix4 ParaEngine::Matrix4::InvertPRMatrix ( ) const

Inverts a PR matrix.

(which only contains a rotation and a translation) This is faster and less subject to FPU errors than the generic inversion code.

Parameters
dest[out] destination matrix

§ isAffine()

bool ParaEngine::Matrix4::isAffine ( void  ) const
inline

Check whether or not the matrix is affine row-major matrix.

Remarks
An affine matrix is a 4x4 matrix with column 3 equal to (0, 0, 0, 1), e.g. no projective coefficients.

§ makeInverseTransform()

void ParaEngine::Matrix4::makeInverseTransform ( const Vector3 position,
const Vector3 scale,
const Quaternion orientation 
)

Building an inverse Matrix4 from orientation / scale / position.

Remarks
As makeTransform except it build the inverse given the same data as makeTransform, so performing -translation, -rotate, 1/scale in that order.

§ makeTransform()

void ParaEngine::Matrix4::makeTransform ( const Vector3 position,
const Vector3 scale,
const Quaternion orientation 
)

Building a Matrix4 from orientation / scale / position.

Remarks
Transform is performed in the order scale, rotate, translation, i.e. translation is independent of orientation axes, scale does not affect size of translation, rotation and scaling are always centered on the origin.

§ Multiply4x3()

ParaEngine::Matrix4 ParaEngine::Matrix4::Multiply4x3 ( const Matrix4 m2) const

we will assume both matrix are row-major affine matrix.

column 3 is (0,0,0,1)

§ operator*()

Vector3 ParaEngine::Matrix4::operator* ( const Vector3 v) const
inline

Vector transformation using '*'.

Remarks
Transforms the given 3-D vector by the matrix, projecting the result back into w = 1.
Note
This means that the initial w is considered to be 1.0, and then all the tree elements of the resulting 3-D vector are divided by the resulting w.

§ transformAffine() [1/2]

Vector3 ParaEngine::Matrix4::transformAffine ( const Vector3 v) const
inline

Column vector: 3-D Vector transformation specially for affine matrix.

Remarks
Transforms the given 3-D vector by the matrix, projecting the result back into w = 1.
Note
The matrix must be an affine matrix.
See also
Matrix4::isAffine.

§ transformAffine() [2/2]

Vector4 ParaEngine::Matrix4::transformAffine ( const Vector4 v) const
inline

Column vector: 4-D Vector transformation specially for affine matrix.

Note
The matrix must be an affine matrix.
See also
Matrix4::isAffine.

Member Data Documentation

§ CLIPSPACE2DTOIMAGESPACE

const Matrix4 ParaEngine::Matrix4::CLIPSPACE2DTOIMAGESPACE
static

Useful little matrix which takes 2D clipspace {-1, 1} to {0,1} and inverts the Y.


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