matrix Struct Reference

4x4 matrix More...

#include <3dmath.h>

List of all members.

Public Member Functions

 matrix ()
 Constructor.
 matrix (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)
 Constructor.
 matrix (const float *m)
 Constructor.
 matrix (const matrix &m)
 Copy constructor.
matrixoperator= (const matrix &mat)
 Assignment operator.
matrix operator+ (const matrix &c) const
 Add operator.
matrixoperator+= (const matrix &c)
 Add assignment operator.
matrix operator- (const matrix &c) const
 Subtract operator.
matrixoperator-= (const matrix &c)
 Subtract assignment operator.
matrix operator* (const matrix &c) const
 Multiply operator.
matrix operator* (float f) const
 Scalar multiply operator.
matrixoperator*= (const matrix &m)
 Assignment multiply operator.
matrixoperator*= (float f)
 Assignment scalar multiply operator.
bool operator== (const matrix &m) const
 Comparison operator.
bool IsUnit () const
 Test if it is unit matrix.
vector3 ExtractTranslation () const
 Extract position from world transformation matrix.
matrix ExtractRotation () const
 Get matrix preserving rotation (and scale) but with no translation.
vector3 TransformCoord (const vector3 &v) const
 Transform 3D coordinate (assuming w = 1) with transformation matrix.
vector3 TransformNormal (const vector3 &v) const
 Transform 3D direction with transformation matrix.
matrix Inverse () const
 Get inverted matrix (homogeneous).
float Det3x3 () const
 Get 3x3 determinant.
bool InvertThisPrecise ()
matrix Transpose () const
 Get transposed matrix.
matrixTranslate (const vector3 &v)
matrixScale (const vector3 &v)
 Scale matrix.
void ToEuler (float &x, float &y, float &z) const
void ToAxisAngle (vector3 &axis, float &angle) const
wxString ToString () const
 Get string.
matrixClone () const
 Get copy of instance.

Static Public Member Functions

static matrix ScaleMat (const vector3 &v)
 Get scale matrix.
static matrix Translation (const vector3 &v)
 Get translation matrix.
static matrix RotationX (float angle)
 Get rotation matrix around the X axis.
static matrix RotationY (float angle)
 Get rotation matrix around the Y axis.
static matrix RotationZ (float angle)
 Get rotation matrix around the Z axis.
static matrix RotationYPR (float Yaw, float Pitch, float Roll)
static matrix RotationAxis (const vector3 &axis, float angle)
static matrix RotationVectors (const vector3 &vecStart, const vector3 &vecTo)
 Construct the rotation matrix that rotates 'vec1' to 'vec2'.

Public Attributes

union {
   struct {
      float   _m11
 Components.
      float   _m12
      float   _m13
      float   _m14
      float   _m21
      float   _m22
      float   _m23
      float   _m24
      float   _m31
      float   _m32
      float   _m33
      float   _m34
      float   _m41
      float   _m42
      float   _m43
      float   _m44
   } 
   float   _m [16]
 Components.
}; 

Friends

matrix operator* (float f, const matrix &m)
 Scalar multiply operator.
std::ostream & operator<< (std::ostream &os, const matrix &M)
 Output stream operator.


Detailed Description

4x4 matrix

Definition at line 422 of file 3dmath.h.


Constructor & Destructor Documentation

matrix::matrix (  )  [inline]

Constructor.

Definition at line 439 of file 3dmath.h.

00440        {
00441               memset(_m, 0, sizeof(_m));
00442               _m11 = _m22 = _m33 = _m44 = 1;
00443        }

matrix::matrix ( 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 
) [inline]

Constructor.

Definition at line 446 of file 3dmath.h.

00450        :_m11(_11), _m12(_12), _m13(_13), _m14(_14),
00451        _m21(_21), _m22(_22), _m23(_23), _m24(_24),
00452        _m31(_31), _m32(_32), _m33(_33), _m34(_34),
00453        _m41(_41), _m42(_42), _m43(_43), _m44(_44)       {}

matrix::matrix ( const float *  m  )  [inline]

Constructor.

Definition at line 456 of file 3dmath.h.

00457        {
00458               for (int i = 0; i < 16; i++)
00459                      _m[i] = m[i];
00460        }

matrix::matrix ( const matrix m  )  [inline]

Copy constructor.

Definition at line 463 of file 3dmath.h.

00464        {
00465               for (int i = 0; i < 16; i++)
00466                      _m[i] = m._m[i];
00467        }


Member Function Documentation

matrix& matrix::operator= ( const matrix mat  )  [inline]

Assignment operator.

Definition at line 470 of file 3dmath.h.

00471        {
00472               for (int i = 0; i < 16; i++)
00473                      _m[i] = mat._m[i];
00474               return *this;
00475        }

matrix matrix::operator+ ( const matrix c  )  const [inline]

Add operator.

Definition at line 478 of file 3dmath.h.

00479        {
00480               matrix ret;
00481               float * r = ret._m;
00482               const float * m1 = _m;
00483               const float * m2 = c._m;
00484               for (int i = 0; i < 16; i++)
00485                      *r++ = *m1++ + *m2++;
00486               return ret;
00487        }

matrix& matrix::operator+= ( const matrix c  )  [inline]

Add assignment operator.

Definition at line 490 of file 3dmath.h.

00491        {
00492               float * m1 = _m;
00493               const float * m2 = c._m;
00494               for (int i = 0; i < 16; i++)
00495                      *m1++ += *m2++;
00496               return *this;
00497        }

matrix matrix::operator- ( const matrix c  )  const [inline]

Subtract operator.

Definition at line 500 of file 3dmath.h.

00501        {
00502               matrix ret;
00503               float * r = ret._m;
00504               const float * m1 = _m;
00505               const float * m2 = c._m;
00506               for (int i = 0; i < 16; i++)
00507                      *r++ = *m1++ - *m2++;
00508               return ret;
00509        }

matrix& matrix::operator-= ( const matrix c  )  [inline]

Subtract assignment operator.

Definition at line 512 of file 3dmath.h.

00513        {
00514               float * m1 = _m;
00515               const float * m2 = c._m;
00516               for (int i = 0; i < 16; i++)
00517                      *m1++ -= *m2++;
00518               return *this;
00519        }

matrix matrix::operator* ( const matrix c  )  const [inline]

Multiply operator.

Definition at line 522 of file 3dmath.h.

00523        {
00524               matrix ret;
00525               ret._m11 = _m11*c._m11+_m12*c._m21+_m13*c._m31+_m14*c._m41;
00526               ret._m12 = _m11*c._m12+_m12*c._m22+_m13*c._m32+_m14*c._m42;
00527               ret._m13 = _m11*c._m13+_m12*c._m23+_m13*c._m33+_m14*c._m43;
00528               ret._m14 = _m11*c._m14+_m12*c._m24+_m13*c._m34+_m14*c._m44;
00529               ret._m21 = _m21*c._m11+_m22*c._m21+_m23*c._m31+_m24*c._m41;
00530               ret._m22 = _m21*c._m12+_m22*c._m22+_m23*c._m32+_m24*c._m42;
00531               ret._m23 = _m21*c._m13+_m22*c._m23+_m23*c._m33+_m24*c._m43;
00532               ret._m24 = _m21*c._m14+_m22*c._m24+_m23*c._m34+_m24*c._m44;
00533               ret._m31 = _m31*c._m11+_m32*c._m21+_m33*c._m31+_m34*c._m41;
00534               ret._m32 = _m31*c._m12+_m32*c._m22+_m33*c._m32+_m34*c._m42;
00535               ret._m33 = _m31*c._m13+_m32*c._m23+_m33*c._m33+_m34*c._m43;
00536               ret._m34 = _m31*c._m14+_m32*c._m24+_m33*c._m34+_m34*c._m44;
00537               ret._m41 = _m41*c._m11+_m42*c._m21+_m43*c._m31+_m44*c._m41;
00538               ret._m42 = _m41*c._m12+_m42*c._m22+_m43*c._m32+_m44*c._m42;
00539               ret._m43 = _m41*c._m13+_m42*c._m23+_m43*c._m33+_m44*c._m43;
00540               ret._m44 = _m41*c._m14+_m42*c._m24+_m43*c._m34+_m44*c._m44;
00541               return ret;
00542        }

matrix matrix::operator* ( float  f  )  const [inline]

Scalar multiply operator.

Definition at line 545 of file 3dmath.h.

00546        {
00547               return matrix(       f*_m11, f*_m12, f*_m13, f*_m14,
00548                                           f*_m21, f*_m22, f*_m23, f*_m24,
00549                                           f*_m31, f*_m32, f*_m33, f*_m34,
00550                                           f*_m41, f*_m42, f*_m43, f*_m44 );
00551        }

matrix& matrix::operator*= ( const matrix m  )  [inline]

Assignment multiply operator.

Definition at line 563 of file 3dmath.h.

00564        {
00565               operator=(*this * m);
00566               return *this;
00567        }

matrix& matrix::operator*= ( float  f  )  [inline]

Assignment scalar multiply operator.

Definition at line 570 of file 3dmath.h.

00571        {
00572               for (int i = 0; i < 16; i++)
00573                      _m[i] *= f;
00574               return *this;
00575        }

bool matrix::operator== ( const matrix m  )  const [inline]

Comparison operator.

Definition at line 578 of file 3dmath.h.

00579        {
00580               for (int i=0; i<16; i++)
00581                      if (_m[i]!=m._m[i])
00582                             return false;
00583               return true;
00584        }

bool matrix::IsUnit (  )  const [inline]

Test if it is unit matrix.

Definition at line 587 of file 3dmath.h.

00588        {
00589               for (int i=0; i<4; i++)
00590                      for (int j=0; j<4; j++)
00591                             if (_m[i*4+j]!=((i==j)?1:0))
00592                                    return false;
00593               return true;
00594        }

vector3 matrix::ExtractTranslation (  )  const [inline]

Extract position from world transformation matrix.

Definition at line 597 of file 3dmath.h.

00598        {
00599               return vector3(_m41, _m42, _m43);
00600        }

matrix matrix::ExtractRotation (  )  const [inline]

Get matrix preserving rotation (and scale) but with no translation.

Definition at line 603 of file 3dmath.h.

00604        {
00605               matrix mat(_m);
00606               mat._m41 = mat._m42 = mat._m43 = mat._m14 = mat._m24 = mat._m34 = 0;
00607               mat._m44 = 1;
00608               return mat;
00609        }

vector3 matrix::TransformCoord ( const vector3 v  )  const [inline]

Transform 3D coordinate (assuming w = 1) with transformation matrix.

Definition at line 612 of file 3dmath.h.

00613        {
00614               vector3 ret;
00615               ret.x = v.x * _m11 + v.y * _m21 + v.z * _m31 + _m41;
00616               ret.y = v.x * _m12 + v.y * _m22 + v.z * _m32 + _m42;
00617               ret.z = v.x * _m13 + v.y * _m23 + v.z * _m33 + _m43;
00618 //            float w = v.x * _m14 + v.y * _m24 + v.z * _m34 + _m44;
00619 //            if (w != 1)
00620 //                   return ret;
00621               return ret;
00622        }

vector3 matrix::TransformNormal ( const vector3 v  )  const [inline]

Transform 3D direction with transformation matrix.

Definition at line 625 of file 3dmath.h.

00626        {
00627               vector3 ret;
00628               ret.x = v.x * _m11 + v.y * _m21 + v.z * _m31;
00629               ret.y = v.x * _m12 + v.y * _m22 + v.z * _m32;
00630               ret.z = v.x * _m13 + v.y * _m23 + v.z * _m33;
00631               return ret;
00632        }

matrix matrix::Inverse (  )  const [inline]

Get inverted matrix (homogeneous).

Definition at line 635 of file 3dmath.h.

00636        {
00637               matrix ret;
00638 
00639               ret._m[0] = _m[0];
00640               ret._m[1] = _m[4];
00641               ret._m[2] = _m[8];
00642               ret._m[4] = _m[1];
00643               ret._m[5] = _m[5];
00644               ret._m[6] = _m[9];
00645               ret._m[8] = _m[2];
00646               ret._m[9] = _m[6];
00647               ret._m[10] = _m[10];
00648 
00649               ret._m[12] = ret._m[0]*-_m[12]+ret._m[4]*-_m[13]+ret._m[8]*-_m[14];
00650               ret._m[13] = ret._m[1]*-_m[12]+ret._m[5]*-_m[13]+ret._m[9]*-_m[14];
00651               ret._m[14] = ret._m[2]*-_m[12]+ret._m[6]*-_m[13]+ret._m[10]*-_m[14];
00652 
00653               ret._m[3] = 0.0f;
00654               ret._m[7] = 0.0f;
00655               ret._m[11] = 0.0f;
00656               ret._m[15] = 1.0f;
00657 
00658               return ret;
00659        }

float matrix::Det3x3 (  )  const [inline]

Get 3x3 determinant.

Definition at line 662 of file 3dmath.h.

00663        {
00664               return _m11*_m22*_m33 + _m12*_m23*_m31
00665                      + _m13*_m21*_m32 - _m13*_m22*_m31
00666                      - _m11*_m23*_m32 - _m12*_m21*_m33;
00667        }

bool matrix::InvertThisPrecise (  )  [inline]

Inverse matrix computation gauss_jacobiho method .. from N.R. in C If matrix is regular = computatation successfull = returns true In case of singular matrix returns false

Definition at line 672 of file 3dmath.h.

00673        {
00674               int indxc[4],indxr[4],ipiv[4];
00675               int i,icol,irow,j,k,l,ll,n;
00676               float big,dum,pivinv,temp;
00677               // satisfy the compiler
00678               icol = irow = 0;
00679               // the size of the matrix
00680               n = 4;
00681 
00682               for ( j = 0 ; j < n ; j++) /* zero pivots */
00683                      ipiv[j] = 0;
00684               for ( i = 0; i < n; i++)
00685               {
00686                      big = 0.0;
00687                      for (j = 0 ; j < n ; j++)
00688                             if (ipiv[j] != 1)
00689                                    for ( k = 0 ; k<n ; k++)
00690                                    {
00691                                           if (ipiv[k] == 0)
00692                                           {
00693                                                  if (fabs(_m[4*k+j]) >= big)
00694                                                  {
00695                                                         big = fabs(_m[4*k+j]);
00696                                                         irow = j;
00697                                                         icol = k;
00698                                                  }
00699                                           }
00700                                           else
00701                                                  if (ipiv[k] > 1)
00702                                                         return false; /* singular matrix */
00703                                    }
00704                                    ++(ipiv[icol]);
00705                                    if (irow != icol)
00706                                    {
00707                                           for ( l = 0 ; l<n ; l++)
00708                                           {
00709                                                  temp = _m[4*l+icol];
00710                                                  _m[4*l+icol] = _m[4*l+irow];
00711                                                  _m[4*l+irow] = temp;
00712                                           }
00713                                    }
00714                                    indxr[i] = irow;
00715                                    indxc[i] = icol;
00716                                    if (_m[4*icol+icol] == 0.0)
00717                                           return false; /* singular matrix */
00718 
00719                                    pivinv = 1.0f / _m[4*icol+icol];
00720                                    _m[4*icol+icol] = 1.0 ;
00721                                    for ( l = 0 ; l<n ; l++)
00722                                           _m[4*l+icol] = _m[4*l+icol] * pivinv ;
00723                                    for (ll = 0 ; ll < n ; ll++)
00724                                           if (ll != icol)
00725                                           {
00726                                                  dum = _m[4*icol+ll];
00727                                                  _m[4*icol+ll] = 0.0;
00728                                                  for ( l = 0 ; l<n ; l++)
00729                                                         _m[4*l+ll] = _m[4*l+ll] - _m[4*l+icol] * dum ;
00730                                           }
00731               }
00732               for ( l = n; l--; )
00733               {
00734                      if (indxr[l] != indxc[l])
00735                             for ( k = 0; k<n ; k++)
00736                             {
00737                                    temp = _m[4*indxr[l]+k];
00738                                    _m[4*indxr[l]+k] = _m[4*indxc[l]+k];
00739                                    _m[4*indxc[l]+k] = temp;
00740                             }
00741               }
00742               return true; // matrix is regular .. inversion has been succesfull
00743        }

matrix matrix::Transpose (  )  const [inline]

Get transposed matrix.

Definition at line 746 of file 3dmath.h.

00747        {
00748               matrix mat;
00749               for (int i = 0; i < 4; i++)
00750                      for (int j = 0; j < 4; j++)
00751                             mat._m[4*j+i] = _m[4*i+j];
00752               return mat;
00753        }

matrix& matrix::Translate ( const vector3 v  )  [inline]

Translation matrix TODO: check multiply order

Definition at line 757 of file 3dmath.h.

00758        {
00759               *this *= Translation(v);
00760               return *this;
00761        }

matrix& matrix::Scale ( const vector3 v  )  [inline]

Scale matrix.

Definition at line 764 of file 3dmath.h.

00765        {
00766               _m11 *= v.x;
00767               _m22 *= v.y;
00768               _m33 *= v.z;
00769               return *this;
00770        }

void matrix::ToEuler ( float &  x,
float &  y,
float &  z 
) const [inline]

Convert matrix to Euler angles It works only for pure rotation matrix!

Definition at line 776 of file 3dmath.h.

00777        {
00778               x=-atan2(_m23, _m33);
00779               y=asin(-_m13);
00780               z=-atan2(_m12, _m11);
00781        }

void matrix::ToAxisAngle ( vector3 axis,
float &  angle 
) const [inline]

Convert matrix to Axis-Angle angles, used algorithm from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm It works only for pure rotation matrix!

Definition at line 787 of file 3dmath.h.

00788        {
00789               float epsilon = 0.01f; // margin to allow for rounding errors
00790               float epsilon2 = 0.1f; // margin to distinguish between 0 and 180 degrees
00791               // optional check that input is pure rotation, 'isRotationMatrix' is defined at:
00792               // http://www.euclideanspace.com/maths/algebra/matrix/orthogonal/rotation/
00793               //assert isRotationMatrix(m) : "not valid rotation matrix" ;// for debugging
00794               if ((fabs(_m12-_m21)<EPSILON) && (fabs(_m13-_m31)<EPSILON) && (fabs(_m23-_m32)<EPSILON)) {
00795                             // singularity found
00796                             // first check for identity matrix which must have +1 for all terms
00797                             //  in leading diagonaland zero in other terms
00798                             if ((fabs(_m12+_m21) < epsilon2) && (fabs(_m13+_m31) < epsilon2) && (fabs(_m23+_m32) < epsilon2) && (fabs(_m11+_m22+_m33-3) < epsilon2)) {
00799                                           // this singularity is identity matrix so angle = 0 and arbitrary axis
00800                                           axis=vector3(0, 1, 0);
00801                                           angle=0;
00802                             }
00803                             // otherwise this singularity is angle = 180
00804                             angle = 3.14159f;
00805                             float xx = (_m11+1)/2;
00806                             float yy = (_m22+1)/2;
00807                             float zz = (_m33+1)/2;
00808                             float xy = (_m12+_m21)/4;
00809                             float xz = (_m13+_m31)/4;
00810                             float yz = (_m23+_m32)/4;
00811                             if ((xx > yy) && (xx > zz)) { // _m11 is the largest diagonal term
00812                                    if (xx< epsilon) {
00813                                           axis=vector3(0.0f, 0.7071f, 0.7071f);
00814                                    } else {
00815                                           xx=sqrt(xx);
00816                                           axis=vector3(xx, xy/xx, xz/xx);
00817                                    }
00818                             } else if (yy > zz) { // _m22 is the largest diagonal term
00819                                    if (yy< epsilon) {
00820                                           axis=vector3(0.7071f, 0.0f, 0.7071f);
00821                                    } else {
00822                                           yy=sqrt(yy);
00823                                           axis=vector3(xy/yy, yy, yz/yy);
00824                                    }      
00825                             } else { // _m33 is the largest diagonal term so base result on this
00826                                    if (zz< epsilon) {
00827                                           axis=vector3(0.7071f, 0.7071f, 0.0f);
00828                                    } else {
00829                                           zz = sqrt(zz);
00830                                           axis=vector3(xz/zz, yz/zz, zz);
00831                                    }
00832                             }
00833                             return;// return 180 deg rotation
00834               }
00835               // as we have reached here there are no singularities so we can handle normally
00836 //            float s = sqrt((_m32 - _m23)*(_m32 - _m23) + (_m13 - _m31)*(_m13 - _m31) + (_m21 - _m12)*(_m21 - _m12)); // used to normalise
00837 //            if (fabs(s) < 0.001) s=1; 
00838               // prevent divide by zero, should not happen if matrix is orthogonal and should be
00839               // caught by singularity test above, but I've left it in just in case
00840               angle = acos(( _m11 + _m22 + _m33 - 1)/2);
00841               axis=vector3(_m32 - _m23, _m13 - _m31, _m21 - _m12).Normalize();
00842        }

static matrix matrix::ScaleMat ( const vector3 v  )  [inline, static]

Get scale matrix.

Definition at line 845 of file 3dmath.h.

00846        {
00847               matrix ret;
00848               ret._m11 = v.x;
00849               ret._m22 = v.y;
00850               ret._m33 = v.z;
00851               return ret;
00852        }

static matrix matrix::Translation ( const vector3 v  )  [inline, static]

Get translation matrix.

Definition at line 855 of file 3dmath.h.

00856        {
00857               matrix mat;
00858               mat._m41 = v.x;
00859               mat._m42 = v.y;
00860               mat._m43 = v.z;
00861               return mat;
00862        }

static matrix matrix::RotationX ( float  angle  )  [inline, static]

Get rotation matrix around the X axis.

Definition at line 865 of file 3dmath.h.

00866        {
00867               matrix M;
00868               float Cosine = cos(angle);
00869               float Sine = sin(angle);
00870               M._m22 = Cosine;
00871               M._m23 = -Sine;
00872               M._m32 = Sine;
00873               M._m33 = Cosine;
00874               return M;
00875        }

static matrix matrix::RotationY ( float  angle  )  [inline, static]

Get rotation matrix around the Y axis.

Definition at line 878 of file 3dmath.h.

00879        {
00880               matrix M;
00881               float Cosine = cos(angle);
00882               float Sine = sin(angle);
00883               M._m11 = Cosine;
00884               M._m13 = -Sine;
00885               M._m31 = Sine;
00886               M._m33 = Cosine;
00887               return M;
00888        }

static matrix matrix::RotationZ ( float  angle  )  [inline, static]

Get rotation matrix around the Z axis.

Definition at line 891 of file 3dmath.h.

00892        {
00893               matrix M;
00894               float Cosine = cos(angle);
00895               float Sine = sin(angle);
00896               M._m11 = Cosine;
00897               M._m12 = -Sine;
00898               M._m21 = Sine;
00899               M._m22 = Cosine;
00900               return M;
00901        }

static matrix matrix::RotationYPR ( float  Yaw,
float  Pitch,
float  Roll 
) [inline, static]

Construct a yaw-pitch-roll rotation matrix. Rotate Yaw radians about the XY axis, rotate Pitch radians in the plane defined by the Yaw rotation, and rotate Roll radians about the axis defined by the previous two angles.

Definition at line 907 of file 3dmath.h.

00908        {
00909               matrix M;
00910               float ch = cos(Yaw);
00911               float sh = sin(Yaw);
00912               float cp = cos(Pitch);
00913               float sp = sin(Pitch);
00914               float cr = cos(Roll);
00915               float sr = sin(Roll);
00916 
00917               M._m11 = ch * cr + sh * sp * sr;
00918               M._m12 = -ch * sr + sh * sp * cr;
00919               M._m13 = sh * cp;
00920               M._m21 = sr * cp;
00921               M._m22 = cr * cp;
00922               M._m23 = -sp;
00923               M._m31 = -sh * cr - ch * sp * sr;
00924               M._m32 = sr * sh + ch * sp * cr;
00925               M._m33 = ch * cp;
00926 
00927               return M;
00928        }

static matrix matrix::RotationAxis ( const vector3 axis,
float  angle 
) [inline, static]

Construct a rotation of a given angle about a given axis. Derived from Eric Haines's SPD (Standard Procedural Database).

Definition at line 933 of file 3dmath.h.

00934        {
00935               matrix M;
00936               float cosine = cos(angle);
00937               float sine = sin(angle);
00938               float one_minus_cosine = 1 - cosine;
00939 
00940               M._m11 = axis.x * axis.x + (1.0f - axis.x * axis.x) * cosine;
00941               M._m21 = axis.x * axis.y * one_minus_cosine + axis.z * sine;
00942               M._m31 = axis.x * axis.z * one_minus_cosine - axis.y * sine;
00943               M._m41 = 0;
00944 
00945               M._m12 = axis.x * axis.y * one_minus_cosine - axis.z * sine;
00946               M._m22 = axis.y * axis.y + (1.0f - axis.y * axis.y) * cosine;
00947               M._m32 = axis.y * axis.z * one_minus_cosine + axis.x * sine;
00948               M._m42 = 0;
00949 
00950               M._m13 = axis.x * axis.z * one_minus_cosine + axis.y * sine;
00951               M._m23 = axis.y * axis.z * one_minus_cosine - axis.x * sine;
00952               M._m33 = axis.z * axis.z + (1.0f - axis.z * axis.z) * cosine;
00953               M._m43 = 0;
00954 
00955               M._m14 = 0;
00956               M._m24 = 0;
00957               M._m34 = 0;
00958               M._m44 = 1;
00959 
00960               return M;
00961        }

static matrix matrix::RotationVectors ( const vector3 vecStart,
const vector3 vecTo 
) [inline, static]

Construct the rotation matrix that rotates 'vec1' to 'vec2'.

Definition at line 965 of file 3dmath.h.

00966        {
00967               vector3 vec = vecStart.Cross(vecTo);
00968 
00969               if (vec.Length() > 1e-6f)
00970               {
00971                      // vector exist, compute angle
00972                      float angle = acos(vecStart.Dot(vecTo));
00973                      // normalize for sure
00974                      vec = vec.Normalize();
00975                      return RotationAxis(vec, angle);
00976               }
00977 
00978               // opposite or colinear vectors
00979               matrix ret;
00980               if (vecStart.Dot(vecTo) < 0.0f)
00981                      ret *= -1.0f; // opposite vectors
00982 
00983               return ret;
00984        }

wxString matrix::ToString (  )  const [inline]

Get string.

Definition at line 987 of file 3dmath.h.

00988        {
00989               wxString str;
00990               for (int i = 0; i < 4; i++)
00991               { // y
00992                      for (int j = 0; j < 4; j++)
00993                      { // x
00994                             str.Append(wxString::Format(wxT("%.2f "), _m[4*i+j]));
00995                      }
00996                      str << wxT("\n");
00997               }
00998               return str;
00999        }

matrix* matrix::Clone (  )  const [inline]

Get copy of instance.

Definition at line 1016 of file 3dmath.h.

01017        {
01018               return new matrix(*this);
01019        }


Friends And Related Function Documentation

matrix operator* ( float  f,
const matrix m 
) [friend]

Scalar multiply operator.

Definition at line 554 of file 3dmath.h.

00555        {
00556               return matrix(       f*m._m11, f*m._m12, f*m._m13, f*m._m14,
00557                                           f*m._m21, f*m._m22, f*m._m23, f*m._m24,
00558                                           f*m._m31, f*m._m32, f*m._m33, f*m._m34,
00559                                           f*m._m41, f*m._m42, f*m._m43, f*m._m44 );
00560        }

std::ostream& operator<< ( std::ostream &  os,
const matrix M 
) [friend]

Output stream operator.

Definition at line 1002 of file 3dmath.h.

01003        {
01004               for (int i = 0; i < 4; i++)
01005               { // y
01006                      for (int j = 0; j < 4; j++)
01007                      { // x
01008                             os << std::setprecision(4) << std::setw(10) << M._m[4*i+j] << " ";
01009                      }
01010                      os << '\n';
01011               }
01012               return os;
01013        }


Member Data Documentation

float matrix::_m11

Components.

Definition at line 429 of file 3dmath.h.

float matrix::_m12

Definition at line 429 of file 3dmath.h.

float matrix::_m13

Definition at line 429 of file 3dmath.h.

float matrix::_m14

Definition at line 429 of file 3dmath.h.

float matrix::_m21

Definition at line 429 of file 3dmath.h.

float matrix::_m22

Definition at line 429 of file 3dmath.h.

float matrix::_m23

Definition at line 429 of file 3dmath.h.

float matrix::_m24

Definition at line 429 of file 3dmath.h.

float matrix::_m31

Definition at line 429 of file 3dmath.h.

float matrix::_m32

Definition at line 429 of file 3dmath.h.

float matrix::_m33

Definition at line 429 of file 3dmath.h.

float matrix::_m34

Definition at line 429 of file 3dmath.h.

float matrix::_m41

Definition at line 429 of file 3dmath.h.

float matrix::_m42

Definition at line 429 of file 3dmath.h.

float matrix::_m43

Definition at line 429 of file 3dmath.h.

float matrix::_m44

Definition at line 429 of file 3dmath.h.

float matrix::_m[16]

Components.

Definition at line 435 of file 3dmath.h.

union { ... }


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

Generated on Tue Mar 10 14:41:38 2009 for VRUT by  doxygen 1.5.5