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