xsi_matrix4f.h Source File
 
 
 
xsi_matrix4f.h
Go to the documentation of this file.
00001 //*****************************************************************************
00011 //*****************************************************************************
00012 
00013 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00014 #pragma once
00015 #endif
00016 
00017 #ifndef __XSIMATRIX4F_H__
00018 #define __XSIMATRIX4F_H__
00019 
00020 #include "sicppsdk.h"
00021 #include "xsi_math.h"
00022 
00023 namespace XSI {
00024 namespace MATH {
00025 
00026 //*****************************************************************************
00031 //*****************************************************************************
00032 class SICPPSDKDECL CMatrix4f
00033 {
00034 public:
00035 
00037         SICPPSDK_INLINE CMatrix4f();
00038 
00057         SICPPSDK_INLINE CMatrix4f(float in_f00, float in_f01, float in_f02, float in_f03,
00058                          float in_f10, float in_f11, float in_f12, float in_f13,
00059                          float in_f20, float in_f21, float in_f22, float in_f23,
00060                          float in_f30, float in_f31, float in_f32, float in_f33);
00061 
00065         SICPPSDK_INLINE CMatrix4f( const CMatrix4f& in_matrix4 );
00066 
00068         SICPPSDK_INLINE ~CMatrix4f();
00069 
00074         SICPPSDK_INLINE CMatrix4f & operator=( const CMatrix4f & in_matrix4 );
00075 
00081         SICPPSDK_INLINE CMatrix4f & operator*=(const CMatrix4f & in_matrix4);
00082 
00086         SICPPSDK_INLINE CMatrix4f&      SetIdentity();
00087 
00091         SICPPSDK_INLINE bool InvertInPlace();
00092 
00097         SICPPSDK_INLINE bool Invert(const CMatrix4f& in_matrix4);
00098 
00103         SICPPSDK_INLINE bool TransposeInverseInPlace();
00104 
00110         SICPPSDK_INLINE bool TransposeInverse(const CMatrix4f& in_matrix4);
00111 
00114         SICPPSDK_INLINE void TransposeInPlace();
00115 
00119         SICPPSDK_INLINE void Transpose(const CMatrix4f& in_matrix4);
00120 
00126         SICPPSDK_INLINE CMatrix4f& MulInPlace(const CMatrix4f& in_matrix4);
00127 
00134         SICPPSDK_INLINE CMatrix4f& Mul(const CMatrix4f& in_matrix4A, const CMatrix4f& in_matrix4B);
00135 
00154         SICPPSDK_INLINE void Get
00155         (
00156                 float& io_f00, float& io_f01, float& io_f02, float& io_f03,
00157                 float& io_f10, float& io_f11, float& io_f12, float& io_f13,
00158                 float& io_f20, float& io_f21, float& io_f22, float& io_f23,
00159                 float& io_f30, float& io_f31, float& io_f32, float& io_f33
00160         ) const;
00161 
00180         SICPPSDK_INLINE void Set(       float in_f00, float in_f01, float in_f02, float in_f03,
00181                                                                 float in_f10, float in_f11, float in_f12, float in_f13,
00182                                                                 float in_f20, float in_f21, float in_f22, float in_f23,
00183                                                                 float in_f30, float in_f31, float in_f32, float in_f33);
00184 
00188         SICPPSDK_INLINE float* Get();
00189                 
00193         SICPPSDK_INLINE void Set(const float in_vals[4][4]);
00194 
00200         SICPPSDK_INLINE float GetValue(short in_sRow,short in_sCol )const;
00201 
00207         SICPPSDK_INLINE void SetValue(short in_sRow, short in_sCol, float in_fVal );
00208 
00214         SICPPSDK_INLINE bool EpsilonEquals
00215         (
00216                 const CMatrix4f& in_matrix4,
00217                 float in_fEpsilon
00218         ) const;
00219 
00224         SICPPSDK_INLINE bool Equals(const CMatrix4f& in_matrix4) const;
00225 
00231         SICPPSDK_INLINE bool operator ==(const CMatrix4f & in_matrix4 ) const;
00232 
00238         SICPPSDK_INLINE bool operator !=(const CMatrix4f & in_matrix4 ) const;
00239 
00246         SICPPSDK_INLINE bool operator < (const CMatrix4f& in_matrix4 )const;
00247 
00252         SICPPSDK_INLINE const float* Get() const;
00253 
00254 private:
00255         float m_fMat[4][4];
00256         unsigned char m_maskInfo;
00257         
00258         SICPPSDK_INLINE bool ComputeInverse
00259         (
00260                 const float in_fMat[4][4],
00261                 float out_fInv[4][4],
00262                 const bool bTransposeResult = false
00263         );
00264 };
00265 
00266 //inline functions
00267 SICPPSDK_INLINE CMatrix4f::CMatrix4f() : m_maskInfo(0)
00268 {
00269         m_fMat[0][0] = 0.0;
00270         m_fMat[0][1] = 0.0;
00271         m_fMat[0][2] = 0.0;
00272         m_fMat[0][3] = 0.0;
00273         m_fMat[1][0] = 0.0;
00274         m_fMat[1][1] = 0.0;
00275         m_fMat[1][2] = 0.0;
00276         m_fMat[1][3] = 0.0;
00277         m_fMat[2][0] = 0.0;
00278         m_fMat[2][1] = 0.0;
00279         m_fMat[2][2] = 0.0;
00280         m_fMat[2][3] = 0.0;
00281         m_fMat[3][0] = 0.0;
00282         m_fMat[3][1] = 0.0;
00283         m_fMat[3][2] = 0.0;
00284         m_fMat[3][3] = 0.0;
00285 }
00286 
00287 SICPPSDK_INLINE CMatrix4f::CMatrix4f
00288 (
00289         float in_f00, float in_f01, float in_f02, float in_f03,
00290         float in_f10, float in_f11, float in_f12, float in_f13,
00291         float in_f20, float in_f21, float in_f22, float in_f23,
00292         float in_f30, float in_f31, float in_f32, float in_f33
00293 ) : m_maskInfo(0)
00294 {
00295         m_fMat[0][0] = in_f00;
00296         m_fMat[0][1] = in_f01;
00297         m_fMat[0][2] = in_f02;
00298         m_fMat[0][3] = in_f03;
00299         m_fMat[1][0] = in_f10;
00300         m_fMat[1][1] = in_f11;
00301         m_fMat[1][2] = in_f12;
00302         m_fMat[1][3] = in_f13;
00303         m_fMat[2][0] = in_f20;
00304         m_fMat[2][1] = in_f21;
00305         m_fMat[2][2] = in_f22;
00306         m_fMat[2][3] = in_f23;
00307         m_fMat[3][0] = in_f30;
00308         m_fMat[3][1] = in_f31;
00309         m_fMat[3][2] = in_f32;
00310         m_fMat[3][3] = in_f33;
00311 }
00312 
00313 SICPPSDK_INLINE CMatrix4f::CMatrix4f(const CMatrix4f& in_matrix4)
00314 {
00315         m_fMat[0][0] = in_matrix4.m_fMat[0][0];
00316         m_fMat[0][1] = in_matrix4.m_fMat[0][1];
00317         m_fMat[0][2] = in_matrix4.m_fMat[0][2];
00318         m_fMat[0][3] = in_matrix4.m_fMat[0][3];
00319         m_fMat[1][0] = in_matrix4.m_fMat[1][0];
00320         m_fMat[1][1] = in_matrix4.m_fMat[1][1];
00321         m_fMat[1][2] = in_matrix4.m_fMat[1][2];
00322         m_fMat[1][3] = in_matrix4.m_fMat[1][3];
00323         m_fMat[2][0] = in_matrix4.m_fMat[2][0];
00324         m_fMat[2][1] = in_matrix4.m_fMat[2][1];
00325         m_fMat[2][2] = in_matrix4.m_fMat[2][2];
00326         m_fMat[2][3] = in_matrix4.m_fMat[2][3];
00327         m_fMat[3][0] = in_matrix4.m_fMat[3][0];
00328         m_fMat[3][1] = in_matrix4.m_fMat[3][1];
00329         m_fMat[3][2] = in_matrix4.m_fMat[3][2];
00330         m_fMat[3][3] = in_matrix4.m_fMat[3][3];
00331         m_maskInfo = in_matrix4.m_maskInfo;
00332 }
00333 
00334 SICPPSDK_INLINE CMatrix4f::~CMatrix4f()
00335 {}
00336 
00337 SICPPSDK_INLINE CMatrix4f& CMatrix4f::operator=( const CMatrix4f & in_matrix4 )
00338 {
00339         m_fMat[0][0] = in_matrix4.m_fMat[0][0];
00340         m_fMat[0][1] = in_matrix4.m_fMat[0][1];
00341         m_fMat[0][2] = in_matrix4.m_fMat[0][2];
00342         m_fMat[0][3] = in_matrix4.m_fMat[0][3];
00343         m_fMat[1][0] = in_matrix4.m_fMat[1][0];
00344         m_fMat[1][1] = in_matrix4.m_fMat[1][1];
00345         m_fMat[1][2] = in_matrix4.m_fMat[1][2];
00346         m_fMat[1][3] = in_matrix4.m_fMat[1][3];
00347         m_fMat[2][0] = in_matrix4.m_fMat[2][0];
00348         m_fMat[2][1] = in_matrix4.m_fMat[2][1];
00349         m_fMat[2][2] = in_matrix4.m_fMat[2][2];
00350         m_fMat[2][3] = in_matrix4.m_fMat[2][3];
00351         m_fMat[3][0] = in_matrix4.m_fMat[3][0];
00352         m_fMat[3][1] = in_matrix4.m_fMat[3][1];
00353         m_fMat[3][2] = in_matrix4.m_fMat[3][2];
00354         m_fMat[3][3] = in_matrix4.m_fMat[3][3];
00355         m_maskInfo = in_matrix4.m_maskInfo;
00356         return *this;
00357 }
00358 
00359 SICPPSDK_INLINE CMatrix4f& CMatrix4f::operator*=(const CMatrix4f& in_matrix4)
00360 {
00361         return MulInPlace(in_matrix4);
00362 }
00363 
00364 SICPPSDK_INLINE CMatrix4f& CMatrix4f::SetIdentity()
00365 {
00366         m_fMat[0][0] = 1.0;
00367         m_fMat[0][1] = 0.0;
00368         m_fMat[0][2] = 0.0;
00369         m_fMat[0][3] = 0.0;
00370         m_fMat[1][0] = 0.0;
00371         m_fMat[1][1] = 1.0;
00372         m_fMat[1][2] = 0.0;
00373         m_fMat[1][3] = 0.0;
00374         m_fMat[2][0] = 0.0;
00375         m_fMat[2][1] = 0.0;
00376         m_fMat[2][2] = 1.0;
00377         m_fMat[2][3] = 0.0;
00378         m_fMat[3][0] = 0.0;
00379         m_fMat[3][1] = 0.0;
00380         m_fMat[3][2] = 0.0;
00381         m_fMat[3][3] = 1.0;
00382         return *this;
00383 }
00384 
00385 SICPPSDK_INLINE bool CMatrix4f::InvertInPlace()
00386 {
00387         return Invert(*this);
00388 }
00389 
00390 SICPPSDK_INLINE bool CMatrix4f::Invert(const CMatrix4f& in_matrix4)
00391 {
00392         float fInv[4][4];
00393 
00394         if (ComputeInverse(in_matrix4.m_fMat, fInv))
00395         {
00396                 Set(fInv);
00397                 return true;
00398         }
00399         else // singular matrix
00400         {
00401                 return false;
00402         }
00403 }
00404 
00405 SICPPSDK_INLINE bool CMatrix4f::TransposeInverseInPlace()
00406 {
00407         return TransposeInverse(*this);
00408 }
00409 
00410 SICPPSDK_INLINE bool CMatrix4f::TransposeInverse(const CMatrix4f& in_matrix4)
00411 {
00412         float fTransInv[4][4];
00413 
00414         if(ComputeInverse(in_matrix4.m_fMat, fTransInv, true))
00415         {
00416                 Set(fTransInv);
00417                 return true;
00418         }
00419         else // singular matrix
00420         {
00421                 return false;
00422         }
00423 }
00424 
00425 SICPPSDK_INLINE void CMatrix4f::TransposeInPlace()
00426 {
00427         Transpose(*this);
00428 }
00429 
00430 SICPPSDK_INLINE void CMatrix4f::Transpose(const CMatrix4f& in_matrix4)
00431 {
00432         float  dTempMat[4][4];
00433         for(int nR=0; nR<4; nR++)
00434                 for(int nC=0; nC<4; nC++)
00435                         dTempMat[nR][nC] = in_matrix4.m_fMat[nC][nR];
00436         Set(dTempMat);
00437 }
00438 
00439 SICPPSDK_INLINE CMatrix4f&      CMatrix4f::MulInPlace(const CMatrix4f& in_matrix4)
00440 {
00441         return Mul(*this,in_matrix4);
00442 }
00443 
00444 SICPPSDK_INLINE CMatrix4f&      CMatrix4f::Mul
00445 (
00446  const CMatrix4f& in_matrix4A,
00447  const CMatrix4f& in_matrix4B
00448 )
00449 {
00450         float  dTempMat[4][4];
00451 
00452         for(int nR=0; nR<4; nR++)
00453                 for(int nC=0; nC<4; nC++)
00454                         dTempMat[nR][nC] =
00455                                 in_matrix4A.m_fMat[nR][0] * in_matrix4B.m_fMat[0][nC] +
00456                                 in_matrix4A.m_fMat[nR][1] * in_matrix4B.m_fMat[1][nC] +
00457                                 in_matrix4A.m_fMat[nR][2] * in_matrix4B.m_fMat[2][nC] +
00458                                 in_matrix4A.m_fMat[nR][3] * in_matrix4B.m_fMat[3][nC];
00459 
00460         Set(dTempMat);
00461         return (*this);
00462 }
00463 
00464 SICPPSDK_INLINE void CMatrix4f::Get
00465 (
00466         float& io_f00, float& io_f01, float& io_f02, float& io_f03,
00467         float& io_f10, float& io_f11, float& io_f12, float& io_f13,
00468         float& io_f20, float& io_f21, float& io_f22, float& io_f23,
00469         float& io_f30, float& io_f31, float& io_f32, float& io_f33
00470 ) const
00471 {
00472 
00473         io_f00 = m_fMat[0][0];
00474         io_f01 = m_fMat[0][1];
00475         io_f02 = m_fMat[0][2];
00476         io_f03 = m_fMat[0][3];
00477         io_f10 = m_fMat[1][0];
00478         io_f11 = m_fMat[1][1];
00479         io_f12 = m_fMat[1][2];
00480         io_f13 = m_fMat[1][3];
00481         io_f20 = m_fMat[2][0];
00482         io_f21 = m_fMat[2][1];
00483         io_f22 = m_fMat[2][2];
00484         io_f23 = m_fMat[2][3];
00485         io_f30 = m_fMat[3][0];
00486         io_f31 = m_fMat[3][1];
00487         io_f32 = m_fMat[3][2];
00488         io_f33 = m_fMat[3][3];
00489 }
00490 
00491 SICPPSDK_INLINE void CMatrix4f::Set
00492 (
00493         float in_f00, float in_f01, float in_f02, float in_f03,
00494         float in_f10, float in_f11, float in_f12, float in_f13,
00495         float in_f20, float in_f21, float in_f22, float in_f23,
00496         float in_f30, float in_f31, float in_f32, float in_f33
00497 )
00498 {
00499         m_fMat[0][0] = in_f00;
00500         m_fMat[0][1] = in_f01;
00501         m_fMat[0][2] = in_f02;
00502         m_fMat[0][3] = in_f03;
00503         m_fMat[1][0] = in_f10;
00504         m_fMat[1][1] = in_f11;
00505         m_fMat[1][2] = in_f12;
00506         m_fMat[1][3] = in_f13;
00507         m_fMat[2][0] = in_f20;
00508         m_fMat[2][1] = in_f21;
00509         m_fMat[2][2] = in_f22;
00510         m_fMat[2][3] = in_f23;
00511         m_fMat[3][0] = in_f30;
00512         m_fMat[3][1] = in_f31;
00513         m_fMat[3][2] = in_f32;
00514         m_fMat[3][3] = in_f33;
00515 }
00516 
00517 SICPPSDK_INLINE void CMatrix4f::Set(const float in_matrix4[4][4])
00518 {
00519         m_fMat[0][0] = in_matrix4[0][0];
00520         m_fMat[0][1] = in_matrix4[0][1];
00521         m_fMat[0][2] = in_matrix4[0][2];
00522         m_fMat[0][3] = in_matrix4[0][3];
00523         m_fMat[1][0] = in_matrix4[1][0];
00524         m_fMat[1][1] = in_matrix4[1][1];
00525         m_fMat[1][2] = in_matrix4[1][2];
00526         m_fMat[1][3] = in_matrix4[1][3];
00527         m_fMat[2][0] = in_matrix4[2][0];
00528         m_fMat[2][1] = in_matrix4[2][1];
00529         m_fMat[2][2] = in_matrix4[2][2];
00530         m_fMat[2][3] = in_matrix4[2][3];
00531         m_fMat[3][0] = in_matrix4[3][0];
00532         m_fMat[3][1] = in_matrix4[3][1];
00533         m_fMat[3][2] = in_matrix4[3][2];
00534         m_fMat[3][3] = in_matrix4[3][3];
00535 }
00536 
00537 SICPPSDK_INLINE float* CMatrix4f::Get()
00538 {
00539         return &m_fMat[0][0];
00540 }
00541 
00542 SICPPSDK_INLINE const float* CMatrix4f::Get() const
00543 {
00544         return &m_fMat[0][0];
00545 }
00546 
00547 SICPPSDK_INLINE float CMatrix4f::GetValue(short in_sRow,short in_sCol ) const
00548 {
00549         bool l_bValidIndex =  ( in_sRow >=0 && in_sCol >= 0 &&
00550                                                         in_sRow <=3 && in_sCol <= 3);
00551         assert(l_bValidIndex);
00552 
00553         if(l_bValidIndex)
00554         {
00555                 return m_fMat[in_sRow][in_sCol];
00556         }
00557         return 0.0;
00558 }
00559 
00560 SICPPSDK_INLINE void CMatrix4f::SetValue(short in_sRow, short in_sCol, float in_fVal )
00561 {
00562         bool l_bValidIndex =  ( in_sRow >=0 && in_sCol >= 0 && in_sRow <=3 && in_sCol <= 3);
00563 
00564         assert(l_bValidIndex);
00565         if(l_bValidIndex)
00566         {
00567                 m_fMat[in_sRow][in_sCol] = in_fVal;
00568         }
00569 }
00570 
00571 SICPPSDK_INLINE bool CMatrix4f::EpsilonEquals
00572 (
00573         const CMatrix4f& in_matrix4,
00574         float in_fEpsilon
00575 ) const
00576 {
00577         return (this == &in_matrix4) ? true :
00578                 ::fabs(m_fMat[0][0] - in_matrix4.m_fMat[0][0]) < ::fabs(in_fEpsilon) &&
00579                 ::fabs(m_fMat[0][1] - in_matrix4.m_fMat[0][1]) < ::fabs(in_fEpsilon) &&
00580                 ::fabs(m_fMat[0][2] - in_matrix4.m_fMat[0][2]) < ::fabs(in_fEpsilon) &&
00581                 ::fabs(m_fMat[0][3] - in_matrix4.m_fMat[0][3]) < ::fabs(in_fEpsilon) &&
00582                 ::fabs(m_fMat[1][0] - in_matrix4.m_fMat[1][0]) < ::fabs(in_fEpsilon) &&
00583                 ::fabs(m_fMat[1][1] - in_matrix4.m_fMat[1][1]) < ::fabs(in_fEpsilon) &&
00584                 ::fabs(m_fMat[1][2] - in_matrix4.m_fMat[1][2]) < ::fabs(in_fEpsilon) &&
00585                 ::fabs(m_fMat[1][3] - in_matrix4.m_fMat[1][3]) < ::fabs(in_fEpsilon) &&
00586                 ::fabs(m_fMat[2][0] - in_matrix4.m_fMat[2][0]) < ::fabs(in_fEpsilon) &&
00587                 ::fabs(m_fMat[2][1] - in_matrix4.m_fMat[2][1]) < ::fabs(in_fEpsilon) &&
00588                 ::fabs(m_fMat[2][2] - in_matrix4.m_fMat[2][2]) < ::fabs(in_fEpsilon) &&
00589                 ::fabs(m_fMat[2][3] - in_matrix4.m_fMat[2][3]) < ::fabs(in_fEpsilon) &&
00590                 ::fabs(m_fMat[3][0] - in_matrix4.m_fMat[3][0]) < ::fabs(in_fEpsilon) &&
00591                 ::fabs(m_fMat[3][1] - in_matrix4.m_fMat[3][1]) < ::fabs(in_fEpsilon) &&
00592                 ::fabs(m_fMat[3][2] - in_matrix4.m_fMat[3][2]) < ::fabs(in_fEpsilon) &&
00593                 ::fabs(m_fMat[3][3] - in_matrix4.m_fMat[3][3]) < ::fabs(in_fEpsilon);
00594 }
00595 
00596 SICPPSDK_INLINE bool CMatrix4f::Equals(const CMatrix4f& in_matrix4) const
00597 {
00598         return (this == &in_matrix4) ? true :
00599                 m_fMat[0][0] == in_matrix4.m_fMat[0][0] &&
00600                 m_fMat[0][1] == in_matrix4.m_fMat[0][1] &&
00601                 m_fMat[0][2] == in_matrix4.m_fMat[0][2] &&
00602                 m_fMat[0][3] == in_matrix4.m_fMat[0][3] &&
00603                 m_fMat[1][0] == in_matrix4.m_fMat[1][0] &&
00604                 m_fMat[1][1] == in_matrix4.m_fMat[1][1] &&
00605                 m_fMat[1][2] == in_matrix4.m_fMat[1][2] &&
00606                 m_fMat[1][3] == in_matrix4.m_fMat[1][3] &&
00607                 m_fMat[2][0] == in_matrix4.m_fMat[2][0] &&
00608                 m_fMat[2][1] == in_matrix4.m_fMat[2][1] &&
00609                 m_fMat[2][2] == in_matrix4.m_fMat[2][2] &&
00610                 m_fMat[2][3] == in_matrix4.m_fMat[2][3] &&
00611                 m_fMat[3][0] == in_matrix4.m_fMat[3][0] &&
00612                 m_fMat[3][1] == in_matrix4.m_fMat[3][1] &&
00613                 m_fMat[3][2] == in_matrix4.m_fMat[3][2] &&
00614                 m_fMat[3][3] == in_matrix4.m_fMat[3][3];
00615 }
00616 
00617 SICPPSDK_INLINE bool CMatrix4f::operator ==(const CMatrix4f & in_matrix4 ) const
00618 {
00619         return Equals( in_matrix4 );
00620 }
00621 
00622 SICPPSDK_INLINE bool CMatrix4f::operator !=(const CMatrix4f & in_matrix4 ) const
00623 {
00624         return ! Equals( in_matrix4 );
00625 }
00626 
00627 SICPPSDK_INLINE bool CMatrix4f::operator < (const CMatrix4f& in_matrix4 )const
00628 {
00629         if ( m_fMat[0][0] != in_matrix4.m_fMat[0][0] ) return m_fMat[0][0] < in_matrix4.m_fMat[0][0];
00630         if ( m_fMat[0][1] != in_matrix4.m_fMat[0][1] ) return m_fMat[0][1] < in_matrix4.m_fMat[0][1];
00631         if ( m_fMat[0][2] != in_matrix4.m_fMat[0][2] ) return m_fMat[0][2] < in_matrix4.m_fMat[0][2];
00632         if ( m_fMat[0][3] != in_matrix4.m_fMat[0][3] ) return m_fMat[0][3] < in_matrix4.m_fMat[0][3];
00633         if ( m_fMat[1][0] != in_matrix4.m_fMat[1][0] ) return m_fMat[1][0] < in_matrix4.m_fMat[1][0];
00634         if ( m_fMat[1][1] != in_matrix4.m_fMat[1][1] ) return m_fMat[1][1] < in_matrix4.m_fMat[1][1];
00635         if ( m_fMat[1][2] != in_matrix4.m_fMat[1][2] ) return m_fMat[1][2] < in_matrix4.m_fMat[1][2];
00636         if ( m_fMat[1][3] != in_matrix4.m_fMat[1][3] ) return m_fMat[1][3] < in_matrix4.m_fMat[1][3];
00637         if ( m_fMat[2][0] != in_matrix4.m_fMat[2][0] ) return m_fMat[2][0] < in_matrix4.m_fMat[2][0];
00638         if ( m_fMat[2][1] != in_matrix4.m_fMat[2][1] ) return m_fMat[2][1] < in_matrix4.m_fMat[2][1];
00639         if ( m_fMat[2][2] != in_matrix4.m_fMat[2][2] ) return m_fMat[2][2] < in_matrix4.m_fMat[2][2];
00640         if ( m_fMat[2][3] != in_matrix4.m_fMat[2][3] ) return m_fMat[2][3] < in_matrix4.m_fMat[2][3];
00641         if ( m_fMat[3][0] != in_matrix4.m_fMat[3][0] ) return m_fMat[3][0] < in_matrix4.m_fMat[3][0];
00642         if ( m_fMat[3][1] != in_matrix4.m_fMat[3][1] ) return m_fMat[3][1] < in_matrix4.m_fMat[3][1];
00643         if ( m_fMat[3][2] != in_matrix4.m_fMat[3][2] ) return m_fMat[3][2] < in_matrix4.m_fMat[3][2];
00644         if ( m_fMat[3][3] != in_matrix4.m_fMat[3][3] ) return m_fMat[3][3] < in_matrix4.m_fMat[3][3];
00645         return false;
00646 }
00647 
00648 SICPPSDK_INLINE bool CMatrix4f::ComputeInverse
00649 (
00650         const float in_fMat[4][4],
00651         float out_fInv[4][4],
00652         const bool bTransposeResult
00653 )
00654 {
00655         int             i, j, k;
00656         float   fSys[4][8];
00657         float   fTemp;
00658 
00659         // Initialize fSys matrix:
00660         for(i=0; i<4; i++)
00661         {
00662                 for(j=0; j<4; j++)
00663                 {
00664                         fSys[i][j] = in_fMat[i][j];
00665                         fSys[i][j+4] = (float) (i==j);
00666                 }
00667         }
00668         // Compute inverse:
00669         for(j=0; j<4; j++)
00670         {
00671                 if(fabs(fSys[j][j]) < MicroEPS)
00672                 {
00673                         for(i=j + 1; (i<4) && (fabs(fSys[i][j]) < MicroEPS ); i++)
00674                         {};
00675                         if(i==4)
00676                         {
00677                                 return(false);
00678                         }
00679                         else
00680                         {
00681                                 for(k=0; k<8; k++)
00682                                 {
00683                                         fTemp = fSys[i][k];
00684                                         fSys[i][k] = fSys[j][k];
00685                                         fSys[j][k] = fTemp;
00686                                 }
00687                         }
00688                 }
00689                 fTemp = 1.0f / fSys[j][j];
00690                 for(i=0; i<8; i++)
00691                 {
00692                         fSys[j][i] *= fTemp;
00693                 }
00694                 for(i=0; i<4; i++)
00695                 {
00696                         if(i != j)
00697                         {
00698                                 fTemp = - fSys[i][j];
00699                                 for(k=0; k<8; k++)
00700                                 {
00701                                         fSys[i][k] += fSys[j][k] * fTemp;
00702                                 }
00703                         }
00704                 }
00705         }
00706 
00707         // Copy result from fSys to out_fInv:
00708         if(bTransposeResult)
00709         {
00710                 for(i=0; i<4; i++)
00711                 {
00712                         for(j=0; j<4; j++)
00713                         {
00714                                 out_fInv[j][i] = fSys[i][j + 4];
00715                         }
00716                 }
00717         }
00718         else
00719         {
00720                 for(i=0; i<4; i++)
00721                 {
00722                         for(j=0; j<4; j++)
00723                         {
00724                                 out_fInv[i][j] = fSys[i][j + 4];
00725                         }
00726                 }
00727         }
00728         return(true);
00729 }
00730 
00731 };
00732 };
00733 
00734 #endif // __XSIMATRIX4_H__