mudbox::Matrix Class Reference

#include <math.h>

List of all members.


Detailed Description

This class represents a 4x4 transformation matrix.

Public Member Functions

  Matrix (void)
  Construct a matrix without initializing its elements. The values stored in the matrix are undefined.
  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.
  Matrix (const double *pMatrix)
  Construct a matrix from an array of double values. At least 16 values should be contained in the array.
float &  operator() (int iRow, int iColumn)
  Returns a reference to a specific element in the matrix.
float  operator() (int iRow, int iColumn) const
  Returns the value of a specific element in the matrix.
  operator const float * (void) const
  Returns a pointer to the matrix data as a pointer to float values.
  operator float * (void)
  Returns a pointer to the constant matrix data as a pointer to float values.
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.
Matrix &  Transpose (void)
  Transposes the matrix and returns it.
Matrix &  Invert (void)
  Inverts the matrix and returns it.
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
  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.
Vector  ProjectedTransform (const Vector &v, float fW=1.0f) const
  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.
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.
Vector  TransformDirection (const Vector &v) const
  Transform a direction vector by the matrix.

Constructor & Destructor Documentation

mudbox::Matrix::Matrix (  void   )  [inline]
 

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

00775 {};
mudbox::Matrix::Matrix (  const Matrix &  m  )  [inline]
 
00777                               :
00778         _11(m._11), _12(m._12), _13(m._13), _14(m._14), 
00779         _21(m._21), _22(m._22), _23(m._23), _24(m._24), 
00780         _31(m._31), _32(m._32), _33(m._33), _34(m._34), 
00781         _41(m._41), _42(m._42), _43(m._43), _44(m._44) {};

mudbox::Matrix::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.

00787                                                          :
00788         _11(f11), _12(f12), _13(f13), _14(f14), 
00789         _21(f21), _22(f22), _23(f23), _24(f24), 
00790         _31(f31), _32(f32), _33(f33), _34(f34), 
00791         _41(f41), _42(f42), _43(f43), _44(f44) {};

mudbox::Matrix::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& mudbox::Matrix::operator() (  int  iRow,
int  iColumn
)  [inline]
 

Returns a reference to a specific element in the matrix.

00798     { 
00799         return m_fData[iRow*4+iColumn]; 
00800     };
float mudbox::Matrix::operator() (  int  iRow,
int  iColumn
)  const [inline]
 

Returns the value of a specific element in the matrix.

00804     { 
00805         return m_fData[iRow*4+iColumn]; 
00806     };
mudbox::Matrix::operator const float * (  void   )  const [inline]
 

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

Do not delete this pointer.

00810 { return m_fData; };
mudbox::Matrix::operator float * (  void   )  [inline]
 

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

00814 { return m_fData; };
Matrix& mudbox::Matrix::SetIdentity (  void   ) 
 

Sets this matrix to be the identity matrix.

bool mudbox::Matrix::IsIdentity (  void   )  const
 

Return true if the matrix is the identity matrix.

bool mudbox::Matrix::IsRigid (  void   )  const
 

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

Matrix& mudbox::Matrix::operator *= (  float   ) 
 

Multiplies the matrix with a scalar value.

Matrix mudbox::Matrix::operator * (  const Matrix &  m  )  const
 

Multiplies two matrices.

Matrix mudbox::Matrix::operator * (  float   )  const
 

Returns the multiplication of a matrix and a scalar.

Matrix mudbox::Matrix::operator+ (  const Matrix &   )  const
 

Returns the sum of two matrices.

Matrix& mudbox::Matrix::operator *= (  const Matrix &  m  ) 
 

Multiplies the matrix with another matrix.

bool mudbox::Matrix::operator== (  const Matrix &  m  )  const
 

Return true if the two matrices are identical.

void mudbox::Matrix::SetRow (  int  iRowIndex,
const Vector &  vValue
) 
 

Sets the values in a row of the matrix.

The last value in the row remains unchanged.

Matrix& mudbox::Matrix::Transpose (  void   ) 
 

Transposes the matrix and returns it.

Matrix& mudbox::Matrix::Invert (  void   ) 
 

Inverts the matrix and returns it.

Matrix& mudbox::Matrix::FromEuler (  const Vector &  vAngles  ) 
 

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

Vector mudbox::Matrix::ToEuler (  void   )  const
 

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

Matrix& mudbox::Matrix::FromAxisAngle (  const Vector &  vAxis,
float  fAngle
) 
 

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

Vector mudbox::Matrix::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:
v  [in] A Vector containing the x, y, z components of the point
fW  [in] The w component of the point
00870     {
00871         return Vector( 
00872             v.m_fX*_11+v.m_fY*_21+v.m_fZ*_31+fW*_41,
00873             v.m_fX*_12+v.m_fY*_22+v.m_fZ*_32+fW*_42,
00874             v.m_fX*_13+v.m_fY*_23+v.m_fZ*_33+fW*_43 );
00875     };
Vector mudbox::Matrix::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:
v  [in] A Vector containing the x, y, z components of the point
fW  [in] The w component of the point
00885     {
00886         float fRW = v.m_fX*_14+v.m_fY*_24+v.m_fZ*_34+fW*_44;
00887         return (1/fRW)*Vector( 
00888             v.m_fX*_11+v.m_fY*_21+v.m_fZ*_31+fW*_41,
00889             v.m_fX*_12+v.m_fY*_22+v.m_fZ*_32+fW*_42,
00890             v.m_fX*_13+v.m_fY*_23+v.m_fZ*_33+fW*_43 );
00891     };
Vector mudbox::Matrix::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:
v  [in] A Vector containing the x, y, z components of the point
fW  [in] The w component of the point
fRW  [out] The w component of the transformed point
00904     {
00905         fRW = v.m_fX*_14+v.m_fY*_24+v.m_fZ*_34+fW*_44;
00906         return Vector( 
00907             v.m_fX*_11+v.m_fY*_21+v.m_fZ*_31+fW*_41,
00908             v.m_fX*_12+v.m_fY*_22+v.m_fZ*_32+fW*_42,
00909             v.m_fX*_13+v.m_fY*_23+v.m_fZ*_33+fW*_43 );
00910     };
Vector mudbox::Matrix::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.

00917     {
00918         return Vector( 
00919             v.m_fX*_11+v.m_fY*_21+v.m_fZ*_31,
00920             v.m_fX*_12+v.m_fY*_22+v.m_fZ*_32,
00921             v.m_fX*_13+v.m_fY*_23+v.m_fZ*_33 );
00922     };

Member Data Documentation

float mudbox::Matrix::m_fData[16]
 
float mudbox::Matrix::_11
 
float mudbox::Matrix::_12
 
float mudbox::Matrix::_13
 
float mudbox::Matrix::_14
 
float mudbox::Matrix::_21
 
float mudbox::Matrix::_22
 
float mudbox::Matrix::_23
 
float mudbox::Matrix::_24
 
float mudbox::Matrix::_31
 
float mudbox::Matrix::_32
 
float mudbox::Matrix::_33
 
float mudbox::Matrix::_34
 
float mudbox::Matrix::_41
 
float mudbox::Matrix::_42
 
float mudbox::Matrix::_43
 
float mudbox::Matrix::_44
 

mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix
mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix mudbox::Matrix