00001 #pragma once
00002
00003 #include "common.h"
00004 #include <math.h>
00005 #include "Vector.h"
00006 #include "Quaternion.h"
00013
00014 class Matrix
00015 {
00016 public:
00017
00018 Matrix()
00019 {
00020 m_vfElements.m_vfElements16[0]=m_vfElements.m_vfElements16[5]=m_vfElements.m_vfElements16[10]=m_vfElements.m_vfElements16[15]=1.0f;
00021 m_vfElements.m_vfElements16[1]=m_vfElements.m_vfElements16[2]=m_vfElements.m_vfElements16[3]=m_vfElements.m_vfElements16[4]=m_vfElements.m_vfElements16[6]=m_vfElements.m_vfElements16[7]=m_vfElements.m_vfElements16[8]=m_vfElements.m_vfElements16[9]=m_vfElements.m_vfElements16[11]=m_vfElements.m_vfElements16[12]=m_vfElements.m_vfElements16[13]=m_vfElements.m_vfElements16[14]=0.0f;
00022 };
00023
00024 Matrix( const float & fElement0, const float & fElement4, const float & fElement8, const float & fElement12,
00025 const float & fElement1, const float & fElement5, const float & fElement9, const float & fElement13,
00026 const float & fElement2, const float & fElement6, const float & fElement10, const float & fElement14,
00027 const float & fElement3, const float & fElement7, const float & fElement11, const float & fElement15)
00028 {
00029 m_vfElements.m_vfElements16[0]=fElement0; m_vfElements.m_vfElements16[4]=fElement4; m_vfElements.m_vfElements16[8]=fElement8; m_vfElements.m_vfElements16[12]=fElement12;
00030 m_vfElements.m_vfElements16[1]=fElement1; m_vfElements.m_vfElements16[5]=fElement5; m_vfElements.m_vfElements16[9]=fElement9; m_vfElements.m_vfElements16[13]=fElement13;
00031 m_vfElements.m_vfElements16[2]=fElement2; m_vfElements.m_vfElements16[6]=fElement6; m_vfElements.m_vfElements16[10]=fElement10; m_vfElements.m_vfElements16[14]=fElement14;
00032 m_vfElements.m_vfElements16[3]=fElement3; m_vfElements.m_vfElements16[7]=fElement7; m_vfElements.m_vfElements16[11]=fElement11; m_vfElements.m_vfElements16[15]=fElement15;
00033 };
00034
00035 Matrix(const Vector & vecOne, const Vector & vecTwo, const Vector & vecThree, const Vector & vecFour = Vector(0.0f,0.0f,0.0f))
00036 {
00037
00038 m_vfElements.m_vfElements16[0]=vecOne.GetX(); m_vfElements.m_vfElements16[4]=vecOne.GetY(); m_vfElements.m_vfElements16[8]=vecOne.GetZ(); m_vfElements.m_vfElements16[12]=0.0f;
00039 m_vfElements.m_vfElements16[1]=vecTwo.GetX(); m_vfElements.m_vfElements16[5]=vecTwo.GetY(); m_vfElements.m_vfElements16[9]=vecTwo.GetZ(); m_vfElements.m_vfElements16[13]=0.0f;
00040 m_vfElements.m_vfElements16[2]=vecThree.GetX(); m_vfElements.m_vfElements16[6]=vecThree.GetY(); m_vfElements.m_vfElements16[10]=vecThree.GetZ(); m_vfElements.m_vfElements16[14]=0.0f;
00041 m_vfElements.m_vfElements16[3]=0.0f; m_vfElements.m_vfElements16[7]=0.0f; m_vfElements.m_vfElements16[11]=0.0f; m_vfElements.m_vfElements16[15]=1.0f;
00042 };
00043
00044 Matrix(const float *pElements)
00045 {
00046 memcpy((void*)m_vfElements.m_vfElements16, (void *)pElements, 16*sizeof(float));
00047 };
00048
00049 Matrix(const float vfElements[4][4])
00050 {
00051 memcpy((void*)m_vfElements.m_vfElements16, (void *)vfElements, 16*sizeof(float));
00052 };
00053
00054 Matrix(const Quaternion & quaRotation)
00055 {
00056 m_vfElements.m_vfElements16[0]=m_vfElements.m_vfElements16[5]=m_vfElements.m_vfElements16[10]=m_vfElements.m_vfElements16[15]=1.0f;
00057 m_vfElements.m_vfElements16[1]=m_vfElements.m_vfElements16[2]=m_vfElements.m_vfElements16[3]=m_vfElements.m_vfElements16[4]=m_vfElements.m_vfElements16[6]=m_vfElements.m_vfElements16[7]=m_vfElements.m_vfElements16[8]=m_vfElements.m_vfElements16[9]=m_vfElements.m_vfElements16[11]=m_vfElements.m_vfElements16[12]=m_vfElements.m_vfElements16[13]=m_vfElements.m_vfElements16[14]=0.0f;
00058 rotate(quaRotation);
00059 };
00060
00061 ~Matrix()
00062 {
00063 };
00064
00065 void Set(const float *pElements)
00066 {
00067 memcpy((void*)m_vfElements.m_vfElements16, (void *)pElements, 16*sizeof(float));
00068 };
00069
00070 void clearMatrix()
00071 {
00072 m_vfElements.m_vfElements16[0]=m_vfElements.m_vfElements16[5]=m_vfElements.m_vfElements16[10]=m_vfElements.m_vfElements16[15]=1.0f;
00073 m_vfElements.m_vfElements16[1]=m_vfElements.m_vfElements16[2]=m_vfElements.m_vfElements16[3]=m_vfElements.m_vfElements16[4]=m_vfElements.m_vfElements16[6]=m_vfElements.m_vfElements16[7]=m_vfElements.m_vfElements16[8]=m_vfElements.m_vfElements16[9]=m_vfElements.m_vfElements16[11]=m_vfElements.m_vfElements16[12]=m_vfElements.m_vfElements16[13]=m_vfElements.m_vfElements16[14]=0.0f;
00074 };
00075
00076 const float * Get() const
00077 {
00078 return (float *) m_vfElements.m_vfElements16;
00079 }
00080
00081 void CopyToArray(float* array4x4)
00082 {
00083 for(int i = 0; i < 16; ++i)
00084 array4x4[i] = m_vfElements.m_vfElements16[i];
00085 };
00086
00087 void Set(const unsigned int i, const unsigned int j, const float & fValue)
00088 {
00089 m_vfElements.m_vfElements44[i][j] = fValue;
00090 };
00091
00092 const float & Get(const unsigned int i, const unsigned int j) const
00093 {
00094 return m_vfElements.m_vfElements44[i][j];
00095 };
00096
00097 const float & Get(const unsigned int i) const
00098 {
00099 return m_vfElements.m_vfElements16[i];
00100 };
00101
00102 void SetRow(const unsigned int i, const float vfValues[4])
00103 {
00104 m_vfElements.m_vfElements16[ i+0] = vfValues[0];
00105 m_vfElements.m_vfElements16[ i+4] = vfValues[1];
00106 m_vfElements.m_vfElements16[ i+8] = vfValues[2];
00107 m_vfElements.m_vfElements16[i+12] = vfValues[3];
00108 };
00109
00110 void SetColumn(const unsigned int i, const float vfValues[4])
00111 {
00112 m_vfElements.m_vfElements16[i*4+0] = vfValues[0];
00113 m_vfElements.m_vfElements16[i*4+1] = vfValues[1];
00114 m_vfElements.m_vfElements16[i*4+2] = vfValues[2];
00115 m_vfElements.m_vfElements16[i*4+3] = vfValues[3];
00116 };
00117
00118 void SetRow(const unsigned int i, const Vector & vecVector)
00119 {
00120 m_vfElements.m_vfElements16[ i+0] = vecVector.GetX();
00121 m_vfElements.m_vfElements16[ i+4] = vecVector.GetY();
00122 m_vfElements.m_vfElements16[ i+8] = vecVector.GetZ();
00123 };
00124
00125 void SetColumn(const unsigned int i, const Vector & vecVector)
00126 {
00127 m_vfElements.m_vfElements16[i*4+0] = vecVector.GetX();
00128 m_vfElements.m_vfElements16[i*4+1] = vecVector.GetY();
00129 m_vfElements.m_vfElements16[i*4+2] = vecVector.GetZ();
00130 };
00131
00132 float & operator()(const unsigned int i, const unsigned int j)
00133 {
00134 return m_vfElements.m_vfElements44[i][j];
00135 };
00136
00137 const float & operator()(const unsigned int i, const unsigned int j) const
00138 {
00139 return m_vfElements.m_vfElements44[i][j];
00140 };
00141
00142 void SetTranslation(const Vector & vecTranslation)
00143 {
00144 m_vfElements.m_vfElements16[12] = vecTranslation.GetX();
00145 m_vfElements.m_vfElements16[13] = vecTranslation.GetY();
00146 m_vfElements.m_vfElements16[14] = vecTranslation.GetZ();
00147 m_vfElements.m_vfElements16[15] = 1.0f;
00148 };
00149
00150 const Vector GetTranslation() const
00151 {
00152 return Vector(m_vfElements.m_vfElements16[12],m_vfElements.m_vfElements16[13],m_vfElements.m_vfElements16[14]);
00153 };
00154
00155 const Quaternion GetRotation() const
00156 {
00157 const float fTrace = m_vfElements.m_vfElements16[0] + m_vfElements.m_vfElements16[5] + m_vfElements.m_vfElements16[10] + 1.0f;
00158
00159 if (fTrace > 0.0f)
00160 {
00161 const float fS = 0.5f / sqrt(fTrace);
00162 const float fW = 0.25f / fS;
00163 const float fX = ( m_vfElements.m_vfElements16[6] - m_vfElements.m_vfElements16[9] ) * fS;
00164 const float fY = ( m_vfElements.m_vfElements16[8] - m_vfElements.m_vfElements16[2] ) * fS;
00165 const float fZ = ( m_vfElements.m_vfElements16[1] - m_vfElements.m_vfElements16[4] ) * fS;
00166 return Quaternion(Vector(fX,fY,fZ).GetNormalized(),fW);
00167 }
00168 else
00169 {
00170 const float fMaximum = std::max(m_vfElements.m_vfElements44[0][0],std::max(m_vfElements.m_vfElements44[1][1],m_vfElements.m_vfElements44[2][2]));
00171
00172 if (fMaximum == m_vfElements.m_vfElements44[0][0])
00173 {
00174 const float fS = sqrtf( 1.0f + m_vfElements.m_vfElements16[0] - m_vfElements.m_vfElements16[5] - m_vfElements.m_vfElements16[10] ) * 2.0f;
00175 const float fX = 0.5f / fS;
00176 const float fY = (m_vfElements.m_vfElements16[4] + m_vfElements.m_vfElements16[1] ) / fS;
00177 const float fZ = (m_vfElements.m_vfElements16[8] + m_vfElements.m_vfElements16[2] ) / fS;
00178 const float fW = (m_vfElements.m_vfElements16[9] + m_vfElements.m_vfElements16[6] ) / fS;
00179 return Quaternion(Vector(fX,fY,fZ).GetNormalized(),fW);
00180 }
00181 else if (fMaximum == m_vfElements.m_vfElements44[1][1])
00182 {
00183 const float fS = sqrtf( 1.0f + m_vfElements.m_vfElements16[5] - m_vfElements.m_vfElements16[0] - m_vfElements.m_vfElements16[10] ) * 2.0f;
00184 const float fX = (m_vfElements.m_vfElements16[4] + m_vfElements.m_vfElements16[1] ) / fS;
00185 const float fY = 0.5f / fS;
00186 const float fZ = (m_vfElements.m_vfElements16[9] + m_vfElements.m_vfElements16[6] ) / fS;
00187 const float fW = (m_vfElements.m_vfElements16[8] + m_vfElements.m_vfElements16[2] ) / fS;
00188 return Quaternion(Vector(fX,fY,fZ).GetNormalized(),fW);
00189 }
00190 else
00191 {
00192 const float fS = sqrtf( 1.0f + m_vfElements.m_vfElements16[10] - m_vfElements.m_vfElements16[0] - m_vfElements.m_vfElements16[5] ) * 2.0f;
00193 const float fX = (m_vfElements.m_vfElements16[8] + m_vfElements.m_vfElements16[2] ) / fS;
00194 const float fY = (m_vfElements.m_vfElements16[9] + m_vfElements.m_vfElements16[6] ) / fS;
00195 const float fZ = 0.5f / fS;
00196 const float fW = (m_vfElements.m_vfElements16[4] + m_vfElements.m_vfElements16[1] ) / fS;
00197 return Quaternion(Vector(fX,fY,fZ).GetNormalized(),fW);
00198 }
00199 }
00200 };
00201
00202 const Matrix GetTranslated(const Vector & vecTranslation) const
00203 {
00204 return (*this) * Matrix(1.0f,0.0f,0.0f,vecTranslation.GetX(), 0.0f,1.0f,0.0f,vecTranslation.GetY(), 0.0f,0.0f,1.0f,vecTranslation.GetZ(), 0.0f, 0.0f,0.0f,1.0f);
00205 };
00206
00207 void translate(const Vector &vecTranslation)
00208 {
00209 *this = GetTranslated(vecTranslation);
00210 };
00211
00212 const Matrix GetScaled(const Vector &vecScale) const
00213 {
00214 return (*this) * Matrix( vecScale.GetX(),0.0f,0.0f,0.0f, 0.0f,vecScale.GetY(),0.0f,0.0f, 0.0f,0.0f,vecScale.GetZ(),0.0f, 0.0f,0.0f,0.0f,1.0f);
00215 };
00216
00217 void scale(const Vector &vecScale)
00218 {
00219 *this = GetScaled(vecScale);
00220 };
00221
00222 const Matrix GetRotated(const Quaternion & quaRotation) const
00223 {
00224 const float fXX = quaRotation.GetVector().GetX() * quaRotation.GetVector().GetX();
00225 const float fXY = quaRotation.GetVector().GetX() * quaRotation.GetVector().GetY();
00226 const float fXZ = quaRotation.GetVector().GetX() * quaRotation.GetVector().GetZ();
00227 const float fXW = quaRotation.GetVector().GetX() * quaRotation.GetScalar();
00228 const float fYY = quaRotation.GetVector().GetY() * quaRotation.GetVector().GetY();
00229 const float fYZ = quaRotation.GetVector().GetY() * quaRotation.GetVector().GetZ();
00230 const float fYW = quaRotation.GetVector().GetY() * quaRotation.GetScalar();
00231 const float fZZ = quaRotation.GetVector().GetZ() * quaRotation.GetVector().GetZ();
00232 const float fZW = quaRotation.GetVector().GetZ() * quaRotation.GetScalar();
00233
00234 return (*this) * Matrix(1.0f - 2.0f * (fYY + fZZ), 2.0f * (fXY - fZW), 2.0f * (fXZ + fYW), 0.0f, 2.0f * (fXY + fZW), 1.0f - 2.0f * (fXX + fZZ), 2.0f * (fYZ - fXW), 0.0f, 2.0f * (fXZ - fYW), 2.0f * (fYZ + fXW), 1.0f - 2.0f * (fXX + fYY), 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);
00235 };
00236
00237 void rotate(const Quaternion & quaRotation)
00238 {
00239 *this = GetRotated(quaRotation);
00240 };
00241
00242 const Matrix GetInverse() const
00243 {
00244 const float fTmp1 = m_vfElements.m_vfElements44[2][2]*m_vfElements.m_vfElements44[3][3];
00245 const float fTmp2 = m_vfElements.m_vfElements44[0][1]*fTmp1;
00246 const float fTmp4 = m_vfElements.m_vfElements44[2][3]*m_vfElements.m_vfElements44[3][2];
00247 const float fTmp5 = m_vfElements.m_vfElements44[0][1]*fTmp4;
00248 const float fTmp6 = m_vfElements.m_vfElements44[0][2]*m_vfElements.m_vfElements44[3][3];
00249 const float fTmp7 = m_vfElements.m_vfElements44[2][1]*fTmp6;
00250 const float fTmp8 = m_vfElements.m_vfElements44[0][3]*m_vfElements.m_vfElements44[3][2];
00251 const float fTmp9 = m_vfElements.m_vfElements44[2][1]*fTmp8;
00252 const float fTmp11 = m_vfElements.m_vfElements44[0][2]*m_vfElements.m_vfElements44[2][3];
00253 const float fTmp12 = m_vfElements.m_vfElements44[3][1]*fTmp11;
00254 const float fTmp14 = m_vfElements.m_vfElements44[0][3]*m_vfElements.m_vfElements44[2][2];
00255 const float fTmp15 = m_vfElements.m_vfElements44[3][1]*fTmp14;
00256 const float fTmp17 = m_vfElements.m_vfElements44[1][1]*fTmp1;
00257 const float fTmp19 = m_vfElements.m_vfElements44[1][1]*fTmp4;
00258 const float fTmp22 = m_vfElements.m_vfElements44[1][2]*m_vfElements.m_vfElements44[3][3];
00259 const float fTmp23 = m_vfElements.m_vfElements44[2][1]*fTmp22;
00260 const float fTmp26 = m_vfElements.m_vfElements44[1][3]*m_vfElements.m_vfElements44[3][2];
00261 const float fTmp27 = m_vfElements.m_vfElements44[2][1]*fTmp26;
00262 const float fTmp29 = m_vfElements.m_vfElements44[1][2]*m_vfElements.m_vfElements44[2][3];
00263 const float fTmp30 = m_vfElements.m_vfElements44[3][1]*fTmp29;
00264 const float fTmp32 = m_vfElements.m_vfElements44[1][3]*m_vfElements.m_vfElements44[2][2];
00265 const float fTmp33 = m_vfElements.m_vfElements44[3][1]*fTmp32;
00266 const float fTmp48 = m_vfElements.m_vfElements44[0][1]*fTmp22;
00267 const float fTmp50 = m_vfElements.m_vfElements44[0][1]*fTmp26;
00268 const float fTmp53 = m_vfElements.m_vfElements44[1][1]*fTmp6;
00269 const float fTmp56 = m_vfElements.m_vfElements44[1][1]*fTmp8;
00270 const float fTmp58 = m_vfElements.m_vfElements44[0][2]*m_vfElements.m_vfElements44[1][3];
00271 const float fTmp59 = m_vfElements.m_vfElements44[3][1]*fTmp58;
00272 const float fTmp61 = m_vfElements.m_vfElements44[0][3]*m_vfElements.m_vfElements44[1][2];
00273 const float fTmp62 = m_vfElements.m_vfElements44[3][1]*fTmp61;
00274 const float fTmp66 = m_vfElements.m_vfElements44[0][1]*fTmp29;
00275 const float fTmp69 = m_vfElements.m_vfElements44[0][1]*fTmp32;
00276 const float fTmp71 = m_vfElements.m_vfElements44[1][1]*fTmp11;
00277 const float fTmp73 = m_vfElements.m_vfElements44[1][1]*fTmp14;
00278 const float fTmp76 = m_vfElements.m_vfElements44[2][1]*fTmp58;
00279 const float fTmp79 = m_vfElements.m_vfElements44[2][1]*fTmp61;
00280 const float fTmp84 = 1.0f/(m_vfElements.m_vfElements44[0][0]*fTmp17-m_vfElements.m_vfElements44[0][0]*fTmp19-m_vfElements.m_vfElements44[0][0]*fTmp23+m_vfElements.m_vfElements44[0][0]*fTmp27+m_vfElements.m_vfElements44[0][0]*fTmp30-m_vfElements.m_vfElements44[0][0]*fTmp33-m_vfElements.m_vfElements44[1][0]*fTmp2+m_vfElements.m_vfElements44[1][0]*fTmp5+m_vfElements.m_vfElements44[1][0]*fTmp7-m_vfElements.m_vfElements44[1][0]*fTmp9-m_vfElements.m_vfElements44[1][0]*fTmp12+m_vfElements.m_vfElements44[1][0]*fTmp15+m_vfElements.m_vfElements44[2][0]*fTmp48-m_vfElements.m_vfElements44[2][0]*fTmp50-m_vfElements.m_vfElements44[2][0]*fTmp53+m_vfElements.m_vfElements44[2][0]*fTmp56+m_vfElements.m_vfElements44[2][0]*fTmp59-m_vfElements.m_vfElements44[2][0]*fTmp62-m_vfElements.m_vfElements44[3][0]*fTmp66+m_vfElements.m_vfElements44[3][0]*fTmp69+m_vfElements.m_vfElements44[3][0]*fTmp71-m_vfElements.m_vfElements44[3][0]*fTmp73-m_vfElements.m_vfElements44[3][0]*fTmp76+m_vfElements.m_vfElements44[3][0]*fTmp79);
00281 const float fTmp116 = m_vfElements.m_vfElements44[2][1]*m_vfElements.m_vfElements44[3][2];
00282 const float fTmp118 = m_vfElements.m_vfElements44[2][2]*m_vfElements.m_vfElements44[3][1];
00283 const float fTmp121 = m_vfElements.m_vfElements44[0][1]*m_vfElements.m_vfElements44[3][2];
00284 const float fTmp124 = m_vfElements.m_vfElements44[0][2]*m_vfElements.m_vfElements44[3][1];
00285 const float fTmp126 = m_vfElements.m_vfElements44[0][1]*m_vfElements.m_vfElements44[2][2];
00286 const float fTmp128 = m_vfElements.m_vfElements44[0][2]*m_vfElements.m_vfElements44[2][1];
00287 const float fTmp133 = m_vfElements.m_vfElements44[2][1]*m_vfElements.m_vfElements44[3][3];
00288 const float fTmp135 = m_vfElements.m_vfElements44[2][3]*m_vfElements.m_vfElements44[3][1];
00289 const float fTmp138 = m_vfElements.m_vfElements44[0][1]*m_vfElements.m_vfElements44[3][3];
00290 const float fTmp141 = m_vfElements.m_vfElements44[0][3]*m_vfElements.m_vfElements44[3][1];
00291 const float fTmp143 = m_vfElements.m_vfElements44[0][1]*m_vfElements.m_vfElements44[2][3];
00292 const float fTmp145 = m_vfElements.m_vfElements44[0][3]*m_vfElements.m_vfElements44[2][1];
00293 const float fTmp151 = m_vfElements.m_vfElements44[1][1]*m_vfElements.m_vfElements44[2][2];
00294 const float fTmp153 = m_vfElements.m_vfElements44[1][2]*m_vfElements.m_vfElements44[2][1];
00295 const float fTmp159 = m_vfElements.m_vfElements44[0][1]*m_vfElements.m_vfElements44[1][2];
00296 const float fTmp161 = m_vfElements.m_vfElements44[0][2]*m_vfElements.m_vfElements44[1][1];
00297 const float fTmp166 = m_vfElements.m_vfElements44[1][1]*m_vfElements.m_vfElements44[3][3];
00298 const float fTmp168 = m_vfElements.m_vfElements44[1][3]*m_vfElements.m_vfElements44[3][1];
00299 const float fTmp174 = m_vfElements.m_vfElements44[0][1]*m_vfElements.m_vfElements44[1][3];
00300 const float fTmp176 = m_vfElements.m_vfElements44[0][3]*m_vfElements.m_vfElements44[1][1];
00301 const float fTmp187 = m_vfElements.m_vfElements44[1][1]*m_vfElements.m_vfElements44[2][3];
00302 const float fTmp189 = m_vfElements.m_vfElements44[1][3]*m_vfElements.m_vfElements44[2][1];
00303 const float fTmp212 = m_vfElements.m_vfElements44[1][1]*m_vfElements.m_vfElements44[3][2];
00304 const float fTmp214 = m_vfElements.m_vfElements44[1][2]*m_vfElements.m_vfElements44[3][1];
00305
00306 Matrix matNew;
00307 matNew.m_vfElements.m_vfElements44[0][1] = (-fTmp2+fTmp5+fTmp7-fTmp9-fTmp12+fTmp15)*fTmp84;
00308 matNew.m_vfElements.m_vfElements44[0][2] = -(-fTmp48+fTmp50+fTmp53-fTmp56-fTmp59+fTmp62)*fTmp84;
00309 matNew.m_vfElements.m_vfElements44[1][2] = -(m_vfElements.m_vfElements44[0][0]*fTmp22-m_vfElements.m_vfElements44[0][0]*fTmp26-m_vfElements.m_vfElements44[1][0]*fTmp6+m_vfElements.m_vfElements44[1][0]*fTmp8+m_vfElements.m_vfElements44[3][0]*fTmp58-m_vfElements.m_vfElements44[3][0]*fTmp61)*fTmp84;
00310 matNew.m_vfElements.m_vfElements44[1][3] = -(-m_vfElements.m_vfElements44[0][0]*fTmp29+m_vfElements.m_vfElements44[0][0]*fTmp32+m_vfElements.m_vfElements44[1][0]*fTmp11-m_vfElements.m_vfElements44[1][0]*fTmp14-m_vfElements.m_vfElements44[2][0]*fTmp58+m_vfElements.m_vfElements44[2][0]*fTmp61)*fTmp84;
00311 matNew.m_vfElements.m_vfElements44[3][1] = (m_vfElements.m_vfElements44[0][0]*fTmp116-m_vfElements.m_vfElements44[0][0]*fTmp118-m_vfElements.m_vfElements44[2][0]*fTmp121+m_vfElements.m_vfElements44[2][0]*fTmp124+m_vfElements.m_vfElements44[3][0]*fTmp126-m_vfElements.m_vfElements44[3][0]*fTmp128)*fTmp84;
00312 matNew.m_vfElements.m_vfElements44[2][1] = -(m_vfElements.m_vfElements44[0][0]*fTmp133-m_vfElements.m_vfElements44[0][0]*fTmp135-m_vfElements.m_vfElements44[2][0]*fTmp138+m_vfElements.m_vfElements44[2][0]*fTmp141+m_vfElements.m_vfElements44[3][0]*fTmp143-m_vfElements.m_vfElements44[3][0]*fTmp145)*fTmp84;
00313 matNew.m_vfElements.m_vfElements44[3][3] = (m_vfElements.m_vfElements44[0][0]*fTmp151-m_vfElements.m_vfElements44[0][0]*fTmp153-m_vfElements.m_vfElements44[1][0]*fTmp126+m_vfElements.m_vfElements44[1][0]*fTmp128+m_vfElements.m_vfElements44[2][0]*fTmp159-m_vfElements.m_vfElements44[2][0]*fTmp161)*fTmp84;
00314 matNew.m_vfElements.m_vfElements44[2][2] = (m_vfElements.m_vfElements44[0][0]*fTmp166-m_vfElements.m_vfElements44[0][0]*fTmp168-m_vfElements.m_vfElements44[1][0]*fTmp138+m_vfElements.m_vfElements44[1][0]*fTmp141+m_vfElements.m_vfElements44[3][0]*fTmp174-m_vfElements.m_vfElements44[3][0]*fTmp176)*fTmp84;
00315 matNew.m_vfElements.m_vfElements44[2][0] = (m_vfElements.m_vfElements44[1][0]*fTmp133-m_vfElements.m_vfElements44[1][0]*fTmp135-m_vfElements.m_vfElements44[2][0]*fTmp166+m_vfElements.m_vfElements44[2][0]*fTmp168+m_vfElements.m_vfElements44[3][0]*fTmp187-m_vfElements.m_vfElements44[3][0]*fTmp189)*fTmp84;
00316 matNew.m_vfElements.m_vfElements44[1][0] = -(m_vfElements.m_vfElements44[1][0]*fTmp1-m_vfElements.m_vfElements44[1][0]*fTmp4-m_vfElements.m_vfElements44[2][0]*fTmp22+m_vfElements.m_vfElements44[2][0]*fTmp26+m_vfElements.m_vfElements44[3][0]*fTmp29-m_vfElements.m_vfElements44[3][0]*fTmp32)*fTmp84;
00317 matNew.m_vfElements.m_vfElements44[0][3] = -(fTmp66-fTmp69-fTmp71+fTmp73+fTmp76-fTmp79)*fTmp84;
00318 matNew.m_vfElements.m_vfElements44[3][2] = -(m_vfElements.m_vfElements44[0][0]*fTmp212-m_vfElements.m_vfElements44[0][0]*fTmp214-m_vfElements.m_vfElements44[1][0]*fTmp121+m_vfElements.m_vfElements44[1][0]*fTmp124+m_vfElements.m_vfElements44[3][0]*fTmp159-m_vfElements.m_vfElements44[3][0]*fTmp161)*fTmp84;
00319 matNew.m_vfElements.m_vfElements44[0][0] = (fTmp17-fTmp19-fTmp23+fTmp27+fTmp30-fTmp33)*fTmp84;
00320 matNew.m_vfElements.m_vfElements44[2][3] = -(m_vfElements.m_vfElements44[0][0]*fTmp187-m_vfElements.m_vfElements44[0][0]*fTmp189-m_vfElements.m_vfElements44[1][0]*fTmp143+m_vfElements.m_vfElements44[1][0]*fTmp145+m_vfElements.m_vfElements44[2][0]*fTmp174-m_vfElements.m_vfElements44[2][0]*fTmp176)*fTmp84;
00321 matNew.m_vfElements.m_vfElements44[3][0] = -(m_vfElements.m_vfElements44[1][0]*fTmp116-m_vfElements.m_vfElements44[1][0]*fTmp118-m_vfElements.m_vfElements44[2][0]*fTmp212+m_vfElements.m_vfElements44[2][0]*fTmp214+m_vfElements.m_vfElements44[3][0]*fTmp151-m_vfElements.m_vfElements44[3][0]*fTmp153)*fTmp84;
00322 matNew.m_vfElements.m_vfElements44[1][1] = (m_vfElements.m_vfElements44[0][0]*fTmp1-m_vfElements.m_vfElements44[0][0]*fTmp4-m_vfElements.m_vfElements44[2][0]*fTmp6+m_vfElements.m_vfElements44[2][0]*fTmp8+m_vfElements.m_vfElements44[3][0]*fTmp11-m_vfElements.m_vfElements44[3][0]*fTmp14)*fTmp84;
00323
00324 return matNew;
00325 };
00326
00327 void invert()
00328 {
00329 (*this) = GetInverse();
00330 }
00331
00332 const Matrix GetTransposed() const
00333 {
00334 return Matrix(
00335 m_vfElements.m_vfElements16[0],m_vfElements.m_vfElements16[1],m_vfElements.m_vfElements16[2],m_vfElements.m_vfElements16[3],
00336 m_vfElements.m_vfElements16[4],m_vfElements.m_vfElements16[5],m_vfElements.m_vfElements16[6],m_vfElements.m_vfElements16[7],
00337 m_vfElements.m_vfElements16[8],m_vfElements.m_vfElements16[9],m_vfElements.m_vfElements16[10],m_vfElements.m_vfElements16[11],
00338 m_vfElements.m_vfElements16[12],m_vfElements.m_vfElements16[13],m_vfElements.m_vfElements16[14],m_vfElements.m_vfElements16[15]);
00339 };
00340
00341 void transpose()
00342 {
00343 (*this) = GetTransposed();
00344 };
00345
00346 const Vector GetRotated(const Vector & vecOther) const
00347 {
00348 return Vector(
00349 (m_vfElements.m_vfElements16[0]*vecOther.GetX() + m_vfElements.m_vfElements16[4]*vecOther.GetY() + m_vfElements.m_vfElements16[8]*vecOther.GetZ()),
00350 (m_vfElements.m_vfElements16[1]*vecOther.GetX() + m_vfElements.m_vfElements16[5]*vecOther.GetY() + m_vfElements.m_vfElements16[9]*vecOther.GetZ()),
00351 (m_vfElements.m_vfElements16[2]*vecOther.GetX() + m_vfElements.m_vfElements16[6]*vecOther.GetY() + m_vfElements.m_vfElements16[10]*vecOther.GetZ()));
00352 };
00353
00354 const bool operator==(const Matrix & matOther) const
00355 {
00356 for (unsigned int i=0;i < 16; i++)
00357 {
00358 if (m_vfElements.m_vfElements16[i] != matOther.m_vfElements.m_vfElements16[i])
00359 return false;
00360 }
00361
00362 return true;
00363 };
00364
00365 const bool operator!=(const Matrix & matOther) const
00366 {
00367 return !(*this == matOther);
00368 };
00369
00370 const Matrix operator*(const Matrix & matOther) const
00371 {
00372 return Matrix(
00373 m_vfElements.m_vfElements16[0]*matOther.m_vfElements.m_vfElements16[0] + m_vfElements.m_vfElements16[4]*matOther.m_vfElements.m_vfElements16[1] + m_vfElements.m_vfElements16[8]*matOther.m_vfElements.m_vfElements16[2] + m_vfElements.m_vfElements16[12]*matOther.m_vfElements.m_vfElements16[3],
00374 m_vfElements.m_vfElements16[0]*matOther.m_vfElements.m_vfElements16[4] + m_vfElements.m_vfElements16[4]*matOther.m_vfElements.m_vfElements16[5] + m_vfElements.m_vfElements16[8]*matOther.m_vfElements.m_vfElements16[6] + m_vfElements.m_vfElements16[12]*matOther.m_vfElements.m_vfElements16[7],
00375 m_vfElements.m_vfElements16[0]*matOther.m_vfElements.m_vfElements16[8] + m_vfElements.m_vfElements16[4]*matOther.m_vfElements.m_vfElements16[9] + m_vfElements.m_vfElements16[8]*matOther.m_vfElements.m_vfElements16[10] + m_vfElements.m_vfElements16[12]*matOther.m_vfElements.m_vfElements16[11],
00376 m_vfElements.m_vfElements16[0]*matOther.m_vfElements.m_vfElements16[12] + m_vfElements.m_vfElements16[4]*matOther.m_vfElements.m_vfElements16[13] + m_vfElements.m_vfElements16[8]*matOther.m_vfElements.m_vfElements16[14] + m_vfElements.m_vfElements16[12]*matOther.m_vfElements.m_vfElements16[15],
00377
00378 m_vfElements.m_vfElements16[1]*matOther.m_vfElements.m_vfElements16[0] + m_vfElements.m_vfElements16[5]*matOther.m_vfElements.m_vfElements16[1] + m_vfElements.m_vfElements16[9]*matOther.m_vfElements.m_vfElements16[2] + m_vfElements.m_vfElements16[13]*matOther.m_vfElements.m_vfElements16[3],
00379 m_vfElements.m_vfElements16[1]*matOther.m_vfElements.m_vfElements16[4] + m_vfElements.m_vfElements16[5]*matOther.m_vfElements.m_vfElements16[5] + m_vfElements.m_vfElements16[9]*matOther.m_vfElements.m_vfElements16[6] + m_vfElements.m_vfElements16[13]*matOther.m_vfElements.m_vfElements16[7],
00380 m_vfElements.m_vfElements16[1]*matOther.m_vfElements.m_vfElements16[8] + m_vfElements.m_vfElements16[5]*matOther.m_vfElements.m_vfElements16[9] + m_vfElements.m_vfElements16[9]*matOther.m_vfElements.m_vfElements16[10] + m_vfElements.m_vfElements16[13]*matOther.m_vfElements.m_vfElements16[11],
00381 m_vfElements.m_vfElements16[1]*matOther.m_vfElements.m_vfElements16[12] + m_vfElements.m_vfElements16[5]*matOther.m_vfElements.m_vfElements16[13] + m_vfElements.m_vfElements16[9]*matOther.m_vfElements.m_vfElements16[14] + m_vfElements.m_vfElements16[13]*matOther.m_vfElements.m_vfElements16[15],
00382
00383 m_vfElements.m_vfElements16[2]*matOther.m_vfElements.m_vfElements16[0] + m_vfElements.m_vfElements16[6]*matOther.m_vfElements.m_vfElements16[1] + m_vfElements.m_vfElements16[10]*matOther.m_vfElements.m_vfElements16[2] + m_vfElements.m_vfElements16[14]*matOther.m_vfElements.m_vfElements16[3],
00384 m_vfElements.m_vfElements16[2]*matOther.m_vfElements.m_vfElements16[4] + m_vfElements.m_vfElements16[6]*matOther.m_vfElements.m_vfElements16[5] + m_vfElements.m_vfElements16[10]*matOther.m_vfElements.m_vfElements16[6] + m_vfElements.m_vfElements16[14]*matOther.m_vfElements.m_vfElements16[7],
00385 m_vfElements.m_vfElements16[2]*matOther.m_vfElements.m_vfElements16[8] + m_vfElements.m_vfElements16[6]*matOther.m_vfElements.m_vfElements16[9] + m_vfElements.m_vfElements16[10]*matOther.m_vfElements.m_vfElements16[10] + m_vfElements.m_vfElements16[14]*matOther.m_vfElements.m_vfElements16[11],
00386 m_vfElements.m_vfElements16[2]*matOther.m_vfElements.m_vfElements16[12] + m_vfElements.m_vfElements16[6]*matOther.m_vfElements.m_vfElements16[13] + m_vfElements.m_vfElements16[10]*matOther.m_vfElements.m_vfElements16[14] + m_vfElements.m_vfElements16[14]*matOther.m_vfElements.m_vfElements16[15],
00387
00388 m_vfElements.m_vfElements16[3]*matOther.m_vfElements.m_vfElements16[0] + m_vfElements.m_vfElements16[7]*matOther.m_vfElements.m_vfElements16[1] + m_vfElements.m_vfElements16[11]*matOther.m_vfElements.m_vfElements16[2] + m_vfElements.m_vfElements16[15]*matOther.m_vfElements.m_vfElements16[3],
00389 m_vfElements.m_vfElements16[3]*matOther.m_vfElements.m_vfElements16[4] + m_vfElements.m_vfElements16[7]*matOther.m_vfElements.m_vfElements16[5] + m_vfElements.m_vfElements16[11]*matOther.m_vfElements.m_vfElements16[6] + m_vfElements.m_vfElements16[15]*matOther.m_vfElements.m_vfElements16[7],
00390 m_vfElements.m_vfElements16[3]*matOther.m_vfElements.m_vfElements16[8] + m_vfElements.m_vfElements16[7]*matOther.m_vfElements.m_vfElements16[9] + m_vfElements.m_vfElements16[11]*matOther.m_vfElements.m_vfElements16[10] + m_vfElements.m_vfElements16[15]*matOther.m_vfElements.m_vfElements16[11],
00391 m_vfElements.m_vfElements16[3]*matOther.m_vfElements.m_vfElements16[12] + m_vfElements.m_vfElements16[7]*matOther.m_vfElements.m_vfElements16[13] + m_vfElements.m_vfElements16[11]*matOther.m_vfElements.m_vfElements16[14] + m_vfElements.m_vfElements16[15]*matOther.m_vfElements.m_vfElements16[15] );
00392 };
00393
00394 const Matrix & operator*=(const Matrix & matOther)
00395 {
00396 *this = (*this) * matOther;
00397 return *this;
00398 };
00399
00400 const Vector operator* (const Vector &vecOther) const
00401 {
00402 const float fW = m_vfElements.m_vfElements16[3]*vecOther.GetX() + m_vfElements.m_vfElements16[7]*vecOther.GetY() + m_vfElements.m_vfElements16[11]*vecOther.GetZ() + m_vfElements.m_vfElements16[15];
00403 return Vector(
00404 (m_vfElements.m_vfElements16[0]*vecOther.GetX() + m_vfElements.m_vfElements16[4]*vecOther.GetY() + m_vfElements.m_vfElements16[8]*vecOther.GetZ() + m_vfElements.m_vfElements16[12]) / fW,
00405 (m_vfElements.m_vfElements16[1]*vecOther.GetX() + m_vfElements.m_vfElements16[5]*vecOther.GetY() + m_vfElements.m_vfElements16[9]*vecOther.GetZ() + m_vfElements.m_vfElements16[13]) / fW,
00406 (m_vfElements.m_vfElements16[2]*vecOther.GetX() + m_vfElements.m_vfElements16[6]*vecOther.GetY() + m_vfElements.m_vfElements16[10]*vecOther.GetZ() + m_vfElements.m_vfElements16[14]) / fW );
00407 };
00408
00409 private:
00410
00411 union
00412 {
00413 float m_vfElements16[16];
00414 float m_vfElements44[4][4];
00415 } m_vfElements;
00416 };
00417
00418 inline std::ostream & operator << (std::ostream & os, const Matrix & matMatrix)
00419 {
00420 os << "((" << matMatrix.Get(0,0) << ";" << matMatrix.Get(0,1) << ";" << matMatrix.Get(0,2) << ";" << matMatrix.Get(0,3) << ")" << ";"
00421 << "(" << matMatrix.Get(1,0) << ";" << matMatrix.Get(1,1) << ";" << matMatrix.Get(1,2) << ";" << matMatrix.Get(1,3) << ")" << ";"
00422 << "(" << matMatrix.Get(2,0) << ";" << matMatrix.Get(2,1) << ";" << matMatrix.Get(2,2) << ";" << matMatrix.Get(2,3) << ")" << ";"
00423 << "(" << matMatrix.Get(3,0) << ";" << matMatrix.Get(3,1) << ";" << matMatrix.Get(3,2) << ";" << matMatrix.Get(3,3) << "))";
00424 return os;
00425 }
00426
00427 inline std::istream & operator>> (std::istream & is, Matrix & matMatrix)
00428 {
00429 float f00, f01, f02, f03;
00430 float f10, f11, f12, f13;
00431 float f20, f21, f22, f23;
00432 float f30, f31, f32, f33;
00433
00434 if (is
00435 >> eat ("(")
00436 >> eat("(") >> f00 >> eat(";") >> f01 >> eat(";") >> f02 >> eat(";") >> f03 >> eat(")") >> eat(";")
00437 >> eat("(") >> f10 >> eat(";") >> f11 >> eat(";") >> f12 >> eat(";") >> f13 >> eat(")") >> eat(";")
00438 >> eat("(") >> f20 >> eat(";") >> f21 >> eat(";") >> f22 >> eat(";") >> f23 >> eat(")") >> eat(";")
00439 >> eat("(") >> f30 >> eat(";") >> f31 >> eat(";") >> f32 >> eat(";") >> f33 >> eat(")")
00440 >> eat(")"))
00441 {
00442 matMatrix.Set(0,0,f00); matMatrix.Set(0,1,f01); matMatrix.Set(0,2,f02); matMatrix.Set(0,3,f03);
00443 matMatrix.Set(1,0,f10); matMatrix.Set(1,1,f11); matMatrix.Set(1,2,f12); matMatrix.Set(1,3,f13);
00444 matMatrix.Set(2,0,f20); matMatrix.Set(2,1,f21); matMatrix.Set(2,2,f22); matMatrix.Set(2,3,f23);
00445 matMatrix.Set(3,0,f30); matMatrix.Set(3,1,f31); matMatrix.Set(3,2,f32); matMatrix.Set(3,3,f33);
00446
00447 }
00448
00449 return is;
00450 }