Matrix Class Reference

#include <math.h>

Class Description

This class represents a 4x4 transformation matrix.

Definition at line 1122 of file math.h.

Public Member Functions

 Matrix (void)
 Construct a matrix without initializing its elements. The values stored in the matrix are undefined. More...
 
 Matrix (const Matrix &m)
 
 Matrix (float f11, float f12, float f13, float f14, float f21, float f22, float f23, float f24, float f31, float f32, float f33, float f34, float f41, float f42, float f43, float f44)
 Construct the matrix by passing all the 16 values. More...
 
 Matrix (const double *pMatrix)
 Construct a matrix from an array of double values. At least 16 values should be contained in the array. More...
 
float & operator() (int iRow, int iColumn)
 Returns a reference to a specific element in the matrix. More...
 
float operator() (int iRow, int iColumn) const
 Returns the value of a specific element in the matrix. More...
 
 operator const float * (void) const
 Returns a pointer to the matrix data as a pointer to float values. More...
 
 operator float * (void)
 Returns a pointer to the constant matrix data as a pointer to float values. More...
 
MatrixSetIdentity (void)
 Sets this matrix to be the identity matrix. More...
 
bool IsIdentity (void) const
 Return true if the matrix is the identity matrix. More...
 
bool IsRigid (void) const
 Returns true if the transformation represented by the matrix is rigid (contains only translation and rotation, not scale). More...
 
Matrixoperator*= (float)
 Multiplies the matrix with a scalar value. More...
 
Matrix operator* (const Matrix &m) const
 Multiplies two matrices. More...
 
Matrix operator* (float) const
 Returns the multiplication of a matrix and a scalar. More...
 
Matrix operator+ (const Matrix &) const
 Returns the sum of two matrices. More...
 
Matrixoperator*= (const Matrix &m)
 Multiplies the matrix with another matrix. More...
 
bool operator== (const Matrix &m) const
 Return true if the two matrices are identical. More...
 
void SetRow (int iRowIndex, const Vector &vValue)
 Sets the values in a row of the matrix. More...
 
MatrixTranspose (void)
 Transposes the matrix and returns it. More...
 
MatrixInvert (bool *pOk=0)
 Inverts the matrix and returns it. More...
 
MatrixFromEuler (const Vector &vAngles)
 Creates a rotation matrix from the given euler values stored in the vector and returns it. More...
 
Vector ToEuler (void) const
 Converts a rotation matrix to euler values returns them in a vector. More...
 
MatrixFromAxisAngle (const Vector &vAxis, float fAngle)
 Calculates a rotation matrix from an axis and angle and returns it. More...
 
Vector Transform (const Vector &v, float fW=1.0f) const
 Transforms a vector by the matrix and returns the result. More...
 
Vector ProjectedTransform (const Vector &v, float fW=1.0f) const
 Transforms a point (represented by a Vector) by the matrix and returns the result. More...
 
Vector Transform (const Vector &v, float fW, float &fRW) const
 Transforms a point (represented by a Vector) by the matrix, and returns all four homogeneous coordinates. More...
 
Vector TransformDirection (const Vector &v) const
 Transform a direction vector by the matrix. More...
 

Public Attributes

union {
   float   m_fData [16]
 
   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
 
   } 
 
   double   m_fAlignDummy [8]
 
   __m128   m_vAlignDummy [4]
 
}; 
 

Constructor & Destructor Documentation

Matrix ( void  )
inline

Construct a matrix without initializing its elements. The values stored in the matrix are undefined.

Definition at line 1127 of file math.h.

1127 {};
Matrix ( const Matrix m)
inline

Definition at line 1129 of file math.h.

1129  :
1130  _11(m._11), _12(m._12), _13(m._13), _14(m._14),
1131  _21(m._21), _22(m._22), _23(m._23), _24(m._24),
1132  _31(m._31), _32(m._32), _33(m._33), _34(m._34),
1133  _41(m._41), _42(m._42), _43(m._43), _44(m._44) {};
float _24
Definition: math.h:1281
float _31
Definition: math.h:1282
float _12
Definition: math.h:1280
float _34
Definition: math.h:1282
float _21
Definition: math.h:1281
float _14
Definition: math.h:1280
float _41
Definition: math.h:1283
float _22
Definition: math.h:1281
float _23
Definition: math.h:1281
float _32
Definition: math.h:1282
float _11
Definition: math.h:1280
float _13
Definition: math.h:1280
float _42
Definition: math.h:1283
float _43
Definition: math.h:1283
float _33
Definition: math.h:1282
float _44
Definition: math.h:1283
Matrix ( float  f11,
float  f12,
float  f13,
float  f14,
float  f21,
float  f22,
float  f23,
float  f24,
float  f31,
float  f32,
float  f33,
float  f34,
float  f41,
float  f42,
float  f43,
float  f44 
)
inline

Construct the matrix by passing all the 16 values.

Definition at line 1136 of file math.h.

1139  :
1140  _11(f11), _12(f12), _13(f13), _14(f14),
1141  _21(f21), _22(f22), _23(f23), _24(f24),
1142  _31(f31), _32(f32), _33(f33), _34(f34),
1143  _41(f41), _42(f42), _43(f43), _44(f44) {};
float _24
Definition: math.h:1281
float _31
Definition: math.h:1282
float _12
Definition: math.h:1280
float _34
Definition: math.h:1282
float _21
Definition: math.h:1281
float _14
Definition: math.h:1280
float _41
Definition: math.h:1283
float _22
Definition: math.h:1281
float _23
Definition: math.h:1281
float _32
Definition: math.h:1282
float _11
Definition: math.h:1280
float _13
Definition: math.h:1280
float _42
Definition: math.h:1283
float _43
Definition: math.h:1283
float _33
Definition: math.h:1282
float _44
Definition: math.h:1283
Matrix ( const double *  pMatrix)

Construct a matrix from an array of double values. At least 16 values should be contained in the array.

Member Function Documentation

float& operator() ( int  iRow,
int  iColumn 
)
inline

Returns a reference to a specific element in the matrix.

Definition at line 1149 of file math.h.

1150  {
1151  return m_fData[iRow*4+iColumn];
1152  };
float m_fData[16]
Definition: math.h:1278
float operator() ( int  iRow,
int  iColumn 
) const
inline

Returns the value of a specific element in the matrix.

Definition at line 1155 of file math.h.

1156  {
1157  return m_fData[iRow*4+iColumn];
1158  };
float m_fData[16]
Definition: math.h:1278
operator const float * ( void  ) const
inline

Returns a pointer to the matrix data as a pointer to float values.

Do not delete this pointer.

Definition at line 1162 of file math.h.

1162 { return m_fData; };
float m_fData[16]
Definition: math.h:1278
operator float * ( void  )
inline

Returns a pointer to the constant matrix data as a pointer to float values.

Definition at line 1166 of file math.h.

1166 { return m_fData; };
float m_fData[16]
Definition: math.h:1278
Matrix& SetIdentity ( void  )

Sets this matrix to be the identity matrix.

bool IsIdentity ( void  ) const

Return true if the matrix is the identity matrix.

bool IsRigid ( void  ) const

Returns true if the transformation represented by the matrix is rigid (contains only translation and rotation, not scale).

Matrix& operator*= ( float  )

Multiplies the matrix with a scalar value.

Matrix operator* ( const Matrix m) const

Multiplies two matrices.

Matrix operator* ( float  ) const

Returns the multiplication of a matrix and a scalar.

Matrix operator+ ( const Matrix ) const

Returns the sum of two matrices.

Matrix& operator*= ( const Matrix m)

Multiplies the matrix with another matrix.

bool operator== ( const Matrix m) const

Return true if the two matrices are identical.

void SetRow ( int  iRowIndex,
const Vector vValue 
)

Sets the values in a row of the matrix.

The last value in the row remains unchanged.

Matrix& Transpose ( void  )

Transposes the matrix and returns it.

Matrix& Invert ( bool *  pOk = 0)

Inverts the matrix and returns it.

If pOk is not 0, it is set to true if the matrix inversion is successfull, otherwise it is set to false

Matrix& FromEuler ( const Vector vAngles)

Creates a rotation matrix from the given euler values stored in the vector and returns it.

Vector ToEuler ( void  ) const

Converts a rotation matrix to euler values returns them in a vector.

Matrix& FromAxisAngle ( const Vector vAxis,
float  fAngle 
)

Calculates a rotation matrix from an axis and angle and returns it.

Vector Transform ( const Vector v,
float  fW = 1.0f 
) const
inline

Transforms a vector by the matrix and returns the result.

The fourth component of the vector (if you are using homogeneous coordinates) can be passed in the fW parameter.

Parameters
[in]vA Vector containing the x, y, z components of the point
[in]fWThe w component of the point

Definition at line 1219 of file math.h.

1223  {
1224  return Vector(
1225  v.m_fX*_11+v.m_fY*_21+v.m_fZ*_31+fW*_41,
1226  v.m_fX*_12+v.m_fY*_22+v.m_fZ*_32+fW*_42,
1227  v.m_fX*_13+v.m_fY*_23+v.m_fZ*_33+fW*_43 );
1228  };
float _31
Definition: math.h:1282
float _12
Definition: math.h:1280
float _21
Definition: math.h:1281
float _41
Definition: math.h:1283
float _22
Definition: math.h:1281
const GLdouble * v
Definition: GLee.h:1174
float _23
Definition: math.h:1281
float _32
Definition: math.h:1282
float _11
Definition: math.h:1280
float _13
Definition: math.h:1280
float _42
Definition: math.h:1283
float _43
Definition: math.h:1283
float _33
Definition: math.h:1282
Vector ProjectedTransform ( const Vector v,
float  fW = 1.0f 
) const
inline

Transforms a point (represented by a Vector) by the matrix and returns the result.

This point is assumed to be represented in homogenous coordinates, with a fourth (W) value. After the transformation the result vector will be divided by the resulting W component.

Parameters
[in]vA Vector containing the x, y, z components of the point
[in]fWThe w component of the point

Definition at line 1234 of file math.h.

1238  {
1239  float fRW = v.m_fX*_14+v.m_fY*_24+v.m_fZ*_34+fW*_44;
1240  return (1/fRW)*Vector(
1241  v.m_fX*_11+v.m_fY*_21+v.m_fZ*_31+fW*_41,
1242  v.m_fX*_12+v.m_fY*_22+v.m_fZ*_32+fW*_42,
1243  v.m_fX*_13+v.m_fY*_23+v.m_fZ*_33+fW*_43 );
1244  };
float _24
Definition: math.h:1281
float _31
Definition: math.h:1282
float _12
Definition: math.h:1280
float _34
Definition: math.h:1282
float _21
Definition: math.h:1281
float _14
Definition: math.h:1280
float _41
Definition: math.h:1283
float _22
Definition: math.h:1281
const GLdouble * v
Definition: GLee.h:1174
float _23
Definition: math.h:1281
float _32
Definition: math.h:1282
float _11
Definition: math.h:1280
float _13
Definition: math.h:1280
float _42
Definition: math.h:1283
float _43
Definition: math.h:1283
float _33
Definition: math.h:1282
float _44
Definition: math.h:1283
Vector Transform ( const Vector v,
float  fW,
float &  fRW 
) const
inline

Transforms a point (represented by a Vector) by the matrix, and returns all four homogeneous coordinates.

Since Vectors only hold 3 coordinates, the W coordinate is passed in and out through parameters.

Parameters
[in]vA Vector containing the x, y, z components of the point
[in]fWThe w component of the point
[out]fRWThe w component of the transformed point

Definition at line 1252 of file math.h.

1257  {
1258  fRW = v.m_fX*_14+v.m_fY*_24+v.m_fZ*_34+fW*_44;
1259  return Vector(
1260  v.m_fX*_11+v.m_fY*_21+v.m_fZ*_31+fW*_41,
1261  v.m_fX*_12+v.m_fY*_22+v.m_fZ*_32+fW*_42,
1262  v.m_fX*_13+v.m_fY*_23+v.m_fZ*_33+fW*_43 );
1263  };
float _24
Definition: math.h:1281
float _31
Definition: math.h:1282
float _12
Definition: math.h:1280
float _34
Definition: math.h:1282
float _21
Definition: math.h:1281
float _14
Definition: math.h:1280
float _41
Definition: math.h:1283
float _22
Definition: math.h:1281
const GLdouble * v
Definition: GLee.h:1174
float _23
Definition: math.h:1281
float _32
Definition: math.h:1282
float _11
Definition: math.h:1280
float _13
Definition: math.h:1280
float _42
Definition: math.h:1283
float _43
Definition: math.h:1283
float _33
Definition: math.h:1282
float _44
Definition: math.h:1283
Vector TransformDirection ( const Vector v) const
inline

Transform a direction vector by the matrix.

Vector transformation is different than point transformation, in that it ignores the last row (translation) of the matrix during the transformation.

Definition at line 1269 of file math.h.

1270  {
1271  return Vector(
1272  v.m_fX*_11+v.m_fY*_21+v.m_fZ*_31,
1273  v.m_fX*_12+v.m_fY*_22+v.m_fZ*_32,
1274  v.m_fX*_13+v.m_fY*_23+v.m_fZ*_33 );
1275  };
float _31
Definition: math.h:1282
float _12
Definition: math.h:1280
float _21
Definition: math.h:1281
float _22
Definition: math.h:1281
const GLdouble * v
Definition: GLee.h:1174
float _23
Definition: math.h:1281
float _32
Definition: math.h:1282
float _11
Definition: math.h:1280
float _13
Definition: math.h:1280
float _33
Definition: math.h:1282

Member Data Documentation

float m_fData[16]

Definition at line 1278 of file math.h.

float _11

Definition at line 1280 of file math.h.

float _12

Definition at line 1280 of file math.h.

float _13

Definition at line 1280 of file math.h.

float _14

Definition at line 1280 of file math.h.

float _21

Definition at line 1281 of file math.h.

float _22

Definition at line 1281 of file math.h.

float _23

Definition at line 1281 of file math.h.

float _24

Definition at line 1281 of file math.h.

float _31

Definition at line 1282 of file math.h.

float _32

Definition at line 1282 of file math.h.

float _33

Definition at line 1282 of file math.h.

float _34

Definition at line 1282 of file math.h.

float _41

Definition at line 1283 of file math.h.

float _42

Definition at line 1283 of file math.h.

float _43

Definition at line 1283 of file math.h.

float _44

Definition at line 1283 of file math.h.

double m_fAlignDummy[8]

Definition at line 1285 of file math.h.

__m128 m_vAlignDummy[4]

Definition at line 1287 of file math.h.

union { ... }

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