xsi_matrix4.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 __XSIMATRIX4_H__
00018 #define __XSIMATRIX4_H__
00019
00020 #include "sicppsdk.h"
00021
00022 namespace XSI {
00023 namespace MATH {
00024
00025
00026 //*****************************************************************************
00058 //*****************************************************************************
00059 class SICPPSDKDECL CMatrix4
00060 {
00061 public:
00062
00064     SICPPSDK_INLINE CMatrix4();
00065
00084     SICPPSDK_INLINE CMatrix4(double in_d00, double in_d01, double in_d02, double in_d03,
00085              double in_d10, double in_d11, double in_d12, double in_d13,
00086              double in_d20, double in_d21, double in_d22, double in_d23,
00087              double in_d30, double in_d31, double in_d32, double in_d33);
00088
00092     SICPPSDK_INLINE CMatrix4( const CMatrix4& in_matrix4);
00093
00095     SICPPSDK_INLINE ~CMatrix4();
00096
00101     SICPPSDK_INLINE CMatrix4  & operator=( const CMatrix4 & in_matrix4 );
00102
00109     SICPPSDK_INLINE CMatrix4 & operator*=(const CMatrix4 & in_matrix4);
00110
00114     SICPPSDK_INLINE CMatrix4&   SetIdentity();
00115
00119     bool        InvertInPlace();
00120
00125     bool        Invert(const CMatrix4& in_matrix4);
00126
00131     bool        TransposeInverseInPlace();
00132
00138     bool        TransposeInverse(const CMatrix4& in_matrix4);
00139
00142     void        TransposeInPlace();
00143
00147     SICPPSDK_INLINE void        Transpose(const CMatrix4& in_matrix4);
00148
00154     SICPPSDK_INLINE CMatrix4&       MulInPlace(const CMatrix4& in_matrix4);
00155
00162     SICPPSDK_INLINE CMatrix4&       Mul(const CMatrix4& in_matrix4A, const CMatrix4& in_matrix4B);
00163
00182     SICPPSDK_INLINE void Get
00183     (
00184         double& io_d00, double& io_d01, double& io_d02, double& io_d03,
00185         double& io_d10, double& io_d11, double& io_d12, double& io_d13,
00186         double& io_d20, double& io_d21, double& io_d22, double& io_d23,
00187         double& io_d30, double& io_d31, double& io_d32, double& io_d33
00188     ) const;
00189
00190
00209     SICPPSDK_INLINE void    Set(double in_d00, double in_d01, double in_d02, double in_d03,
00210                 double in_d10, double in_d11, double in_d12, double in_d13,
00211                 double in_d20, double in_d21, double in_d22, double in_d23,
00212                 double in_d30, double in_d31, double in_d32, double in_d33);
00213
00217     SICPPSDK_INLINE void Set(const double in_vals[4][4]);
00218
00224     SICPPSDK_INLINE double      GetValue(short in_sRow,short in_sCol )const;
00225
00231     SICPPSDK_INLINE void        SetValue(short in_sRow, short in_sCol, double in_dVal );
00232
00238     bool EpsilonEquals
00239     (
00240         const CMatrix4& in_matrix4,
00241         double in_dEpsilon
00242     ) const;
00243
00248     SICPPSDK_INLINE bool Equals(const CMatrix4& in_matrix4) const;
00249
00255     SICPPSDK_INLINE bool operator ==(const CMatrix4 & in_matrix4 ) const;
00256
00262     SICPPSDK_INLINE bool operator !=(const CMatrix4 & in_matrix4 ) const;
00263 private:
00264     double m_dMat[4][4];
00265 };
00266
00267 //inline functions
00268 SICPPSDK_INLINE CMatrix4::CMatrix4()
00269 {
00270     m_dMat[0][0] = 0.0;
00271     m_dMat[0][1] = 0.0;
00272     m_dMat[0][2] = 0.0;
00273     m_dMat[0][3] = 0.0;
00274     m_dMat[1][0] = 0.0;
00275     m_dMat[1][1] = 0.0;
00276     m_dMat[1][2] = 0.0;
00277     m_dMat[1][3] = 0.0;
00278     m_dMat[2][0] = 0.0;
00279     m_dMat[2][1] = 0.0;
00280     m_dMat[2][2] = 0.0;
00281     m_dMat[2][3] = 0.0;
00282     m_dMat[3][0] = 0.0;
00283     m_dMat[3][1] = 0.0;
00284     m_dMat[3][2] = 0.0;
00285     m_dMat[3][3] = 0.0;
00286 }
00287
00288 SICPPSDK_INLINE CMatrix4::CMatrix4
00289 (double in_d00, double in_d01, double in_d02, double in_d03,
00290  double in_d10, double in_d11, double in_d12, double in_d13,
00291  double in_d20, double in_d21, double in_d22, double in_d23,
00292  double in_d30, double in_d31, double in_d32, double in_d33
00293 )
00294 {
00295     m_dMat[0][0] = in_d00;
00296     m_dMat[0][1] = in_d01;
00297     m_dMat[0][2] = in_d02;
00298     m_dMat[0][3] = in_d03;
00299     m_dMat[1][0] = in_d10;
00300     m_dMat[1][1] = in_d11;
00301     m_dMat[1][2] = in_d12;
00302     m_dMat[1][3] = in_d13;
00303     m_dMat[2][0] = in_d20;
00304     m_dMat[2][1] = in_d21;
00305     m_dMat[2][2] = in_d22;
00306     m_dMat[2][3] = in_d23;
00307     m_dMat[3][0] = in_d30;
00308     m_dMat[3][1] = in_d31;
00309     m_dMat[3][2] = in_d32;
00310     m_dMat[3][3] = in_d33;
00311 }
00312
00313 SICPPSDK_INLINE CMatrix4::CMatrix4(const CMatrix4& in_matrix4)
00314 {
00315     m_dMat[0][0] = in_matrix4.m_dMat[0][0];
00316     m_dMat[0][1] = in_matrix4.m_dMat[0][1];
00317     m_dMat[0][2] = in_matrix4.m_dMat[0][2];
00318     m_dMat[0][3] = in_matrix4.m_dMat[0][3];
00319     m_dMat[1][0] = in_matrix4.m_dMat[1][0];
00320     m_dMat[1][1] = in_matrix4.m_dMat[1][1];
00321     m_dMat[1][2] = in_matrix4.m_dMat[1][2];
00322     m_dMat[1][3] = in_matrix4.m_dMat[1][3];
00323     m_dMat[2][0] = in_matrix4.m_dMat[2][0];
00324     m_dMat[2][1] = in_matrix4.m_dMat[2][1];
00325     m_dMat[2][2] = in_matrix4.m_dMat[2][2];
00326     m_dMat[2][3] = in_matrix4.m_dMat[2][3];
00327     m_dMat[3][0] = in_matrix4.m_dMat[3][0];
00328     m_dMat[3][1] = in_matrix4.m_dMat[3][1];
00329     m_dMat[3][2] = in_matrix4.m_dMat[3][2];
00330     m_dMat[3][3] = in_matrix4.m_dMat[3][3];
00331 }
00332
00333 SICPPSDK_INLINE CMatrix4::~CMatrix4()
00334 {}
00335
00336 SICPPSDK_INLINE CMatrix4& CMatrix4::operator=( const CMatrix4 & in_matrix4 )
00337 {
00338     m_dMat[0][0] = in_matrix4.m_dMat[0][0];
00339     m_dMat[0][1] = in_matrix4.m_dMat[0][1];
00340     m_dMat[0][2] = in_matrix4.m_dMat[0][2];
00341     m_dMat[0][3] = in_matrix4.m_dMat[0][3];
00342     m_dMat[1][0] = in_matrix4.m_dMat[1][0];
00343     m_dMat[1][1] = in_matrix4.m_dMat[1][1];
00344     m_dMat[1][2] = in_matrix4.m_dMat[1][2];
00345     m_dMat[1][3] = in_matrix4.m_dMat[1][3];
00346     m_dMat[2][0] = in_matrix4.m_dMat[2][0];
00347     m_dMat[2][1] = in_matrix4.m_dMat[2][1];
00348     m_dMat[2][2] = in_matrix4.m_dMat[2][2];
00349     m_dMat[2][3] = in_matrix4.m_dMat[2][3];
00350     m_dMat[3][0] = in_matrix4.m_dMat[3][0];
00351     m_dMat[3][1] = in_matrix4.m_dMat[3][1];
00352     m_dMat[3][2] = in_matrix4.m_dMat[3][2];
00353     m_dMat[3][3] = in_matrix4.m_dMat[3][3];
00354     return *this;
00355 }
00356
00357 SICPPSDK_INLINE CMatrix4& CMatrix4::operator*=(const CMatrix4& in_matrix4)
00358 {
00359     return MulInPlace(in_matrix4);
00360 }
00361
00362 SICPPSDK_INLINE CMatrix4&   CMatrix4::SetIdentity()
00363 {
00364     m_dMat[0][0] = 1.0;
00365     m_dMat[0][1] = 0.0;
00366     m_dMat[0][2] = 0.0;
00367     m_dMat[0][3] = 0.0;
00368     m_dMat[1][0] = 0.0;
00369     m_dMat[1][1] = 1.0;
00370     m_dMat[1][2] = 0.0;
00371     m_dMat[1][3] = 0.0;
00372     m_dMat[2][0] = 0.0;
00373     m_dMat[2][1] = 0.0;
00374     m_dMat[2][2] = 1.0;
00375     m_dMat[2][3] = 0.0;
00376     m_dMat[3][0] = 0.0;
00377     m_dMat[3][1] = 0.0;
00378     m_dMat[3][2] = 0.0;
00379     m_dMat[3][3] = 1.0;
00380     return *this;
00381 }
00382
00383 SICPPSDK_INLINE void CMatrix4::TransposeInPlace()
00384 {
00385     Transpose(*this);
00386 }
00387
00388 SICPPSDK_INLINE void CMatrix4::Transpose(const CMatrix4& in_matrix4)
00389 {
00390     double  dTempMat[4][4];
00391     for(int nR=0; nR<4; nR++)
00392         for(int nC=0; nC<4; nC++)
00393             dTempMat[nR][nC] = in_matrix4.m_dMat[nC][nR];
00394     Set(dTempMat);
00395 }
00396
00397 SICPPSDK_INLINE CMatrix4&   CMatrix4::MulInPlace(const CMatrix4& in_matrix4)
00398 {
00399     return Mul(*this,in_matrix4);
00400 }
00401
00402 SICPPSDK_INLINE CMatrix4&   CMatrix4::Mul
00403 (
00404  const CMatrix4& in_matrix4A,
00405  const CMatrix4& in_matrix4B
00406 )
00407 {
00408     double  dTempMat[4][4];
00409
00410     for(int nR=0; nR<4; nR++)
00411         for(int nC=0; nC<4; nC++)
00412             dTempMat[nR][nC] =
00413                 in_matrix4A.m_dMat[nR][0] * in_matrix4B.m_dMat[0][nC] +
00414                 in_matrix4A.m_dMat[nR][1] * in_matrix4B.m_dMat[1][nC] +
00415                 in_matrix4A.m_dMat[nR][2] * in_matrix4B.m_dMat[2][nC] +
00416                 in_matrix4A.m_dMat[nR][3] * in_matrix4B.m_dMat[3][nC];
00417
00418     Set(dTempMat);
00419     return (*this);
00420 }
00421
00422 SICPPSDK_INLINE void CMatrix4::Get
00423 (
00424     double& io_d00, double& io_d01, double& io_d02, double& io_d03,
00425     double& io_d10, double& io_d11, double& io_d12, double& io_d13,
00426     double& io_d20, double& io_d21, double& io_d22, double& io_d23,
00427     double& io_d30, double& io_d31, double& io_d32, double& io_d33
00428 ) const
00429 {
00430
00431     io_d00 = m_dMat[0][0];
00432     io_d01 = m_dMat[0][1];
00433     io_d02 = m_dMat[0][2];
00434     io_d03 = m_dMat[0][3];
00435     io_d10 = m_dMat[1][0];
00436     io_d11 = m_dMat[1][1];
00437     io_d12 = m_dMat[1][2];
00438     io_d13 = m_dMat[1][3];
00439     io_d20 = m_dMat[2][0];
00440     io_d21 = m_dMat[2][1];
00441     io_d22 = m_dMat[2][2];
00442     io_d23 = m_dMat[2][3];
00443     io_d30 = m_dMat[3][0];
00444     io_d31 = m_dMat[3][1];
00445     io_d32 = m_dMat[3][2];
00446     io_d33 = m_dMat[3][3];
00447 }
00448
00449 SICPPSDK_INLINE void CMatrix4::Set
00450 (
00451     double in_d00, double in_d01, double in_d02, double in_d03,
00452     double in_d10, double in_d11, double in_d12, double in_d13,
00453     double in_d20, double in_d21, double in_d22, double in_d23,
00454     double in_d30, double in_d31, double in_d32, double in_d33
00455 )
00456 {
00457     m_dMat[0][0] = in_d00;
00458     m_dMat[0][1] = in_d01;
00459     m_dMat[0][2] = in_d02;
00460     m_dMat[0][3] = in_d03;
00461     m_dMat[1][0] = in_d10;
00462     m_dMat[1][1] = in_d11;
00463     m_dMat[1][2] = in_d12;
00464     m_dMat[1][3] = in_d13;
00465     m_dMat[2][0] = in_d20;
00466     m_dMat[2][1] = in_d21;
00467     m_dMat[2][2] = in_d22;
00468     m_dMat[2][3] = in_d23;
00469     m_dMat[3][0] = in_d30;
00470     m_dMat[3][1] = in_d31;
00471     m_dMat[3][2] = in_d32;
00472     m_dMat[3][3] = in_d33;
00473 }
00474
00475 SICPPSDK_INLINE void CMatrix4::Set(const double in_matrix4[4][4])
00476 {
00477     m_dMat[0][0] = in_matrix4[0][0];
00478     m_dMat[0][1] = in_matrix4[0][1];
00479     m_dMat[0][2] = in_matrix4[0][2];
00480     m_dMat[0][3] = in_matrix4[0][3];
00481     m_dMat[1][0] = in_matrix4[1][0];
00482     m_dMat[1][1] = in_matrix4[1][1];
00483     m_dMat[1][2] = in_matrix4[1][2];
00484     m_dMat[1][3] = in_matrix4[1][3];
00485     m_dMat[2][0] = in_matrix4[2][0];
00486     m_dMat[2][1] = in_matrix4[2][1];
00487     m_dMat[2][2] = in_matrix4[2][2];
00488     m_dMat[2][3] = in_matrix4[2][3];
00489     m_dMat[3][0] = in_matrix4[3][0];
00490     m_dMat[3][1] = in_matrix4[3][1];
00491     m_dMat[3][2] = in_matrix4[3][2];
00492     m_dMat[3][3] = in_matrix4[3][3];
00493 }
00494
00495
00496 SICPPSDK_INLINE double  CMatrix4::GetValue(short in_sRow,short in_sCol ) const
00497 {
00498     bool l_bValidIndex =  ( in_sRow >=0 && in_sCol >= 0 &&
00499                             in_sRow <=3 && in_sCol <= 3);
00500     assert(l_bValidIndex);
00501
00502     if(l_bValidIndex)
00503     {
00504         return m_dMat[in_sRow][in_sCol];
00505     }
00506     return 0.0;
00507
00508 }
00509
00510 SICPPSDK_INLINE void CMatrix4::SetValue(short in_sRow, short in_sCol, double in_dVal )
00511 {
00512     bool l_bValidIndex =  ( in_sRow >=0 && in_sCol >= 0 &&
00513                             in_sRow <=3 && in_sCol <= 3);
00514
00515     assert(l_bValidIndex);
00516     if(l_bValidIndex)
00517     {
00518         m_dMat[in_sRow][in_sCol] = in_dVal;
00519     }
00520 }
00521
00522 SICPPSDK_INLINE bool CMatrix4::Equals(const CMatrix4& in_matrix4) const
00523 {
00524     return (this == &in_matrix4) ? true :
00525         m_dMat[0][0] == in_matrix4.m_dMat[0][0] &&
00526         m_dMat[0][1] == in_matrix4.m_dMat[0][1] &&
00527         m_dMat[0][2] == in_matrix4.m_dMat[0][2] &&
00528         m_dMat[0][3] == in_matrix4.m_dMat[0][3] &&
00529         m_dMat[1][0] == in_matrix4.m_dMat[1][0] &&
00530         m_dMat[1][1] == in_matrix4.m_dMat[1][1] &&
00531         m_dMat[1][2] == in_matrix4.m_dMat[1][2] &&
00532         m_dMat[1][3] == in_matrix4.m_dMat[1][3] &&
00533         m_dMat[2][0] == in_matrix4.m_dMat[2][0] &&
00534         m_dMat[2][1] == in_matrix4.m_dMat[2][1] &&
00535         m_dMat[2][2] == in_matrix4.m_dMat[2][2] &&
00536         m_dMat[2][3] == in_matrix4.m_dMat[2][3] &&
00537         m_dMat[3][0] == in_matrix4.m_dMat[3][0] &&
00538         m_dMat[3][1] == in_matrix4.m_dMat[3][1] &&
00539         m_dMat[3][2] == in_matrix4.m_dMat[3][2] &&
00540         m_dMat[3][3] == in_matrix4.m_dMat[3][3];
00541 }
00542
00543 SICPPSDK_INLINE bool CMatrix4::operator ==(const CMatrix4 & in_matrix4 ) const
00544 {
00545     return Equals( in_matrix4 );
00546 }
00547
00548 SICPPSDK_INLINE bool CMatrix4::operator !=(const CMatrix4 & in_matrix4 ) const
00549 {
00550     return ! Equals( in_matrix4 );
00551 }
00552
00553
00554
00555 };
00556 };
00557
00558 #endif // __XSIMATRIX4_H__
```