xsi_matrix3.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 __XSIMATRIX3_H__
00018 #define __XSIMATRIX3_H__
00019 
00020 #include "sicppsdk.h"
00021 
00022 namespace XSI {
00023 namespace MATH {
00024 
00025 class CVector3;
00026 class CQuaternion;
00027 
00028 //*****************************************************************************
00050 //*****************************************************************************
00051 class SICPPSDKDECL CMatrix3
00052 {
00053 public:
00054 
00056     SICPPSDK_INLINE CMatrix3();
00057 
00069     SICPPSDK_INLINE CMatrix3(double in_d00, double in_d01, double in_d02,
00070              double in_d10, double in_d11, double in_d12,
00071              double in_d20, double in_d21, double in_d22);
00072 
00076     SICPPSDK_INLINE CMatrix3( const CMatrix3& in_matrix3);
00077 
00079     SICPPSDK_INLINE ~CMatrix3();
00080 
00084     SICPPSDK_INLINE CMatrix3  & operator=( const CMatrix3 & in_matrix3 );
00085 
00086 
00092     SICPPSDK_INLINE CMatrix3 & operator*=(const CMatrix3 & in_matrix3 );
00093 
00099     CVector3& operator[](const short& in_sIndex);
00100 
00104     SICPPSDK_INLINE CMatrix3&   SetIdentity();
00105 
00109     bool        InvertInPlace();
00110 
00115     bool        Invert(const CMatrix3& in_matrix3);
00116 
00120     bool        TransposeInverseInPlace();
00121 
00127     bool        TransposeInverse(const CMatrix3& in_matrix3);
00128 
00131     SICPPSDK_INLINE void        TransposeInPlace();
00132 
00136     SICPPSDK_INLINE void        Transpose(const CMatrix3& in_matrix3);
00137 
00143     SICPPSDK_INLINE CMatrix3&       MulInPlace(const CMatrix3& in_matrix3);
00144 
00151     SICPPSDK_INLINE CMatrix3&       Mul(const CMatrix3& in_matrix3A, const CMatrix3& in_matrix3B);
00152 
00164     SICPPSDK_INLINE void    Get(    double& io_d00, double& io_d01, double& io_d02,
00165                     double& io_d10, double& io_d11, double& io_d12,
00166                     double& io_d20, double& io_d21, double& io_d22) const;
00167 
00168 
00180     SICPPSDK_INLINE void    Set(    double in_d00, double in_d01, double in_d02,
00181                     double in_d10, double in_d11, double in_d12,
00182                     double in_d20, double in_d21, double in_d22);
00183 
00187     SICPPSDK_INLINE void    Set(const double in_dVal[3][3]);
00188 
00194     SICPPSDK_INLINE double      GetValue(short in_sRow,short in_sCol )const;
00195 
00201     SICPPSDK_INLINE void        SetValue(short in_sRow, short in_sCol, double in_dVal );
00202 
00207     CMatrix3& SetFromQuaternion( const CQuaternion& in_quaternion );
00208 
00212     CQuaternion GetQuaternion(void)const;
00213 
00219     bool EpsilonEquals
00220     (
00221         const CMatrix3& in_matrix3,
00222         double in_dEpsilon
00223     ) const;
00224 
00229     SICPPSDK_INLINE bool Equals(const CMatrix3& in_matrix3) const;
00235     SICPPSDK_INLINE bool operator ==(const CMatrix3 & in_matrix3 ) const;
00236 
00242     SICPPSDK_INLINE bool operator !=(const CMatrix3 & in_matrix3 ) const;
00243 
00244 private:
00245     double m_dMat[3][3];
00246 };
00247 
00248 //inline functions
00249 SICPPSDK_INLINE CMatrix3::CMatrix3()
00250 {
00251     m_dMat[0][0] = 0.0;
00252     m_dMat[0][1] = 0.0;
00253     m_dMat[0][2] = 0.0;
00254     m_dMat[1][0] = 0.0;
00255     m_dMat[1][1] = 0.0;
00256     m_dMat[1][2] = 0.0;
00257     m_dMat[2][0] = 0.0;
00258     m_dMat[2][1] = 0.0;
00259     m_dMat[2][2] = 0.0;
00260 }
00261 
00262 SICPPSDK_INLINE CMatrix3::CMatrix3
00263 (
00264  double in_d00, double in_d01, double in_d02,
00265  double in_d10, double in_d11, double in_d12,
00266  double in_d20, double in_d21, double in_d22
00267 )
00268 {
00269     m_dMat[0][0] = in_d00;
00270     m_dMat[0][1] = in_d01;
00271     m_dMat[0][2] = in_d02;
00272     m_dMat[1][0] = in_d10;
00273     m_dMat[1][1] = in_d11;
00274     m_dMat[1][2] = in_d12;
00275     m_dMat[2][0] = in_d20;
00276     m_dMat[2][1] = in_d21;
00277     m_dMat[2][2] = in_d22;
00278 }
00279 
00280 SICPPSDK_INLINE CMatrix3::CMatrix3(const CMatrix3& in_matrix3)
00281 {
00282     m_dMat[0][0] = in_matrix3.m_dMat[0][0];
00283     m_dMat[0][1] = in_matrix3.m_dMat[0][1];
00284     m_dMat[0][2] = in_matrix3.m_dMat[0][2];
00285     m_dMat[1][0] = in_matrix3.m_dMat[1][0];
00286     m_dMat[1][1] = in_matrix3.m_dMat[1][1];
00287     m_dMat[1][2] = in_matrix3.m_dMat[1][2];
00288     m_dMat[2][0] = in_matrix3.m_dMat[2][0];
00289     m_dMat[2][1] = in_matrix3.m_dMat[2][1];
00290     m_dMat[2][2] = in_matrix3.m_dMat[2][2];
00291 }
00292 
00293 SICPPSDK_INLINE CMatrix3::~CMatrix3() 
00294 {}
00295 
00296 SICPPSDK_INLINE CMatrix3& CMatrix3::operator=( const CMatrix3 & in_matrix3 )
00297 {
00298     Set(in_matrix3.m_dMat);
00299     return *this;
00300 }
00301 
00302 SICPPSDK_INLINE CMatrix3& CMatrix3::operator *=(const CMatrix3& in_matrix3)
00303 {
00304     return MulInPlace(in_matrix3);
00305 }
00306 
00307 SICPPSDK_INLINE CMatrix3&   CMatrix3::SetIdentity()
00308 {
00309     m_dMat[0][0] =  1.0;
00310     m_dMat[0][1] =  0.0;
00311     m_dMat[0][2] =  0.0;
00312     m_dMat[1][0] =  0.0;
00313     m_dMat[1][1] =  1.0;
00314     m_dMat[1][2] =  0.0;
00315     m_dMat[2][0] =  0.0;
00316     m_dMat[2][1] =  0.0;
00317     m_dMat[2][2] =  1.0;
00318     return *this;
00319 }
00320 
00321 SICPPSDK_INLINE void CMatrix3::TransposeInPlace()
00322 {
00323     Transpose(*this);
00324 }
00325 
00326 SICPPSDK_INLINE void CMatrix3::Transpose(const CMatrix3& in_matrix3)
00327 {
00328    double  dTempMat[3][3];
00329 
00330    for(int nR=0; nR<3; nR++)
00331       for(int nC=0; nC<3; nC++)
00332          dTempMat[nR][nC] = in_matrix3.m_dMat[nC][nR];
00333 
00334     Set(dTempMat);
00335 }
00336 
00337 SICPPSDK_INLINE CMatrix3&   CMatrix3::MulInPlace(const CMatrix3& in_matrix3)
00338 {
00339     return Mul(*this,in_matrix3);
00340 }
00341 
00342 SICPPSDK_INLINE CMatrix3&   CMatrix3::Mul
00343 (
00344  const CMatrix3& in_matrix3A, 
00345  const CMatrix3& in_matrix3B
00346 )
00347 {
00348     double  dTempMat[3][3];
00349 
00350     for(int nR=0; nR<3; nR++)
00351         for(int nC=0; nC<3; nC++)
00352             dTempMat[nR][nC] = 
00353                 in_matrix3A.m_dMat[nR][0] * in_matrix3B.m_dMat[0][nC] +
00354                 in_matrix3A.m_dMat[nR][1] * in_matrix3B.m_dMat[1][nC] +
00355                 in_matrix3A.m_dMat[nR][2] * in_matrix3B.m_dMat[2][nC];
00356 
00357     Set(dTempMat);
00358     return *this;
00359 }
00360 
00361 SICPPSDK_INLINE void CMatrix3::Get
00362 (   
00363     double& io_d00, double& io_d01, double& io_d02,
00364     double& io_d10, double& io_d11, double& io_d12,
00365     double& io_d20, double& io_d21, double& io_d22
00366 ) const
00367 {
00368     
00369     io_d00 = m_dMat[0][0];
00370     io_d01 = m_dMat[0][1];
00371     io_d02 = m_dMat[0][2];
00372     io_d10 = m_dMat[1][0];
00373     io_d11 = m_dMat[1][1];
00374     io_d12 = m_dMat[1][2];
00375     io_d20 = m_dMat[2][0];
00376     io_d21 = m_dMat[2][1];
00377     io_d22 = m_dMat[2][2];
00378 
00379 }
00380 
00381 SICPPSDK_INLINE void CMatrix3::Set
00382 (   
00383     double in_d00, double in_d01, double in_d02,
00384     double in_d10, double in_d11, double in_d12,
00385     double in_d20, double in_d21, double in_d22
00386 )
00387 {
00388     m_dMat[0][0] = in_d00;
00389     m_dMat[0][1] = in_d01;
00390     m_dMat[0][2] = in_d02;
00391     m_dMat[1][0] = in_d10;
00392     m_dMat[1][1] = in_d11;
00393     m_dMat[1][2] = in_d12;
00394     m_dMat[2][0] = in_d20;
00395     m_dMat[2][1] = in_d21;
00396     m_dMat[2][2] = in_d22;
00397 }
00398 
00399 SICPPSDK_INLINE void CMatrix3::Set(const double in_dVal[3][3])
00400 {
00401     m_dMat[0][0] = in_dVal[0][0];
00402     m_dMat[0][1] = in_dVal[0][1];
00403     m_dMat[0][2] = in_dVal[0][2];
00404     m_dMat[1][0] = in_dVal[1][0];
00405     m_dMat[1][1] = in_dVal[1][1];
00406     m_dMat[1][2] = in_dVal[1][2];
00407     m_dMat[2][0] = in_dVal[2][0];
00408     m_dMat[2][1] = in_dVal[2][1];
00409     m_dMat[2][2] = in_dVal[2][2];
00410 }
00411 
00412 SICPPSDK_INLINE double  CMatrix3::GetValue(short in_sRow,short in_sCol ) const
00413 {
00414     bool l_bValidIndex =  ( in_sRow >=0 && in_sCol >= 0 &&
00415                             in_sRow <=2 && in_sCol <= 2);
00416     assert(l_bValidIndex);
00417 
00418     if(l_bValidIndex)
00419     {
00420         return m_dMat[in_sRow][in_sCol];
00421     }
00422     return 0.0;
00423 }
00424 
00425 SICPPSDK_INLINE void CMatrix3::SetValue(short in_sRow, short in_sCol, double in_dVal )
00426 {
00427     bool l_bValidIndex =  ( in_sRow >=0 && in_sCol >= 0 &&
00428                             in_sRow <=2 && in_sCol <= 2);
00429     assert(l_bValidIndex);
00430 
00431     if(l_bValidIndex)
00432     {
00433         m_dMat[in_sRow][in_sCol] = in_dVal;
00434     }
00435 }
00436 
00437 
00438 
00439 SICPPSDK_INLINE bool CMatrix3::Equals(const CMatrix3& in_matrix3) const
00440 {
00441     return (this == &in_matrix3) ? true :
00442         m_dMat[0][0] == in_matrix3.m_dMat[0][0] &&
00443         m_dMat[0][1] == in_matrix3.m_dMat[0][1] &&
00444         m_dMat[0][2] == in_matrix3.m_dMat[0][2] &&
00445         m_dMat[1][0] == in_matrix3.m_dMat[1][0] &&
00446         m_dMat[1][1] == in_matrix3.m_dMat[1][1] &&
00447         m_dMat[1][2] == in_matrix3.m_dMat[1][2] &&
00448         m_dMat[2][0] == in_matrix3.m_dMat[2][0] &&
00449         m_dMat[2][1] == in_matrix3.m_dMat[2][1] &&
00450         m_dMat[2][2] == in_matrix3.m_dMat[2][2];
00451 }
00452 
00453 SICPPSDK_INLINE bool CMatrix3::operator ==(const CMatrix3 & in_matrix3 ) const
00454 {
00455     return Equals( in_matrix3 );
00456 }
00457 
00458 SICPPSDK_INLINE bool CMatrix3::operator !=(const CMatrix3 & in_matrix3 ) const
00459 {
00460     return ! Equals( in_matrix3 );
00461 }
00462 
00463 
00464 };
00465 };
00466 
00467 #endif // __XSIMATRIX3_H__