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