SIBCXfoMatd.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Softimage 3D Games & 3D Bridge team
00004 //
00005 // (c) Copyright 1999-2002 Avid Technology, Inc. . All rights reserved.
00006 //
00007 //***************************************************************************************
00008 
00009 /****************************************************************************************
00010 THIS CODE IS PUBLISHED AS A SAMPLE ONLY AND IS PROVIDED "AS IS".
00011 IN NO EVENT SHALL SOFTIMAGE, AVID TECHNOLOGY, INC. AND/OR THEIR RESPECTIVE
00012 SUPPLIERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
00013 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00014 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00015 CONNECTION WITH THE USE OR PERFORMANCE OF THIS CODE .
00016 
00017 COPYRIGHT NOTICE. Copyright © 1999-2002 Avid Technology Inc. . All rights reserved. 
00018 
00019 SOFTIMAGE is a registered trademark of Avid Technology Inc. or its subsidiaries 
00020 or divisions. Windows NT is a registered trademark of Microsoft Corp. All other
00021 trademarks contained herein are the property of their respective owners. 
00022 ****************************************************************************************/
00023 
00024 #if (_MSC_VER > 1000) || defined(SGI_COMPILER)
00025 #pragma once
00026 #endif
00027 
00028 //******************************************************************************
00029 // Defines
00030 //******************************************************************************
00031 
00032 #ifndef _XFOMAT_H_
00033 #define _XFOMAT_H_
00034 
00035 //******************************************************************************
00036 // Includes
00037 //******************************************************************************
00038 #include "SIBCMathLib.h"
00039 #include "SIBCMatrix.h"
00040 
00041 //This number must represent the number of bits flags in 
00042 //CSIBCMatrix44d::m_MaskInfo reserved for the specific usage of CSIBCXfoMatd.
00043 #define _3D_NB_BITS_RESERVED_BY_XFOMAT (unsigned char)( 3 ) 
00044 
00045 //******************************************************************************
00046 // CSIBCXfoMatd | 4x4 transformation matrix.
00047 //******************************************************************************
00048 
00050 
00066 class XSICOREEXPORT CSIBCXfoMatd : private CSIBCMatrix44d
00067 {
00068     // Public members
00069     public:
00070         //****************************************
00071         // Constructors/destructor:
00072         //****************************************
00073 
00078         CSIBCXfoMatd( void );
00079 
00091         CSIBCXfoMatd( 
00092             const CSIBCVector4Dd& in_vct0,
00093             const CSIBCVector4Dd& in_vct1,
00094             const CSIBCVector4Dd& in_vct2,
00095             const CSIBCVector4Dd& in_vct3,
00096             const bool in_bAreRows = true );
00097 
00117         CSIBCXfoMatd( 
00118             const double in_dA00, const double in_dA01, const double in_dA02, const double in_dA03, 
00119             const double in_dA10, const double in_dA11, const double in_dA12, const double in_dA13, 
00120             const double in_dA20, const double in_dA21, const double in_dA22, const double in_dA23, 
00121             const double in_dA30, const double in_dA31, const double in_dA32, const double in_dA33 );
00122 
00123         //****************************************
00124         // General access functions:
00125         //****************************************
00126 
00133         double Get( const int in_nRow, const int in_nCol ) const;
00134 
00141         const double * GetArray() const;
00142 
00143         //****************************************
00144         // Matrix element modification functions:
00145         //****************************************
00146 
00157         CSIBCXfoMatd& Set( int in_nRow, int in_nCol, const double in_dVal );
00158 
00168         CSIBCXfoMatd& Set( double in_dVal[4][4] );
00169 
00175         CSIBCXfoMatd& Set( double in_dVal[3][3] );
00176 
00185         CSIBCXfoMatd& Set( const CSIBCMatrix44d& in_mat );
00186 
00196         CSIBCXfoMatd& Set( const CSIBCMatrix33d& in_mat );
00197 
00206         CSIBCXfoMatd& Set( const CSIBCXfoMatd& in_mat );
00207 
00216         CSIBCXfoMatd& Set( const CSIBCRotMatd& in_mat );
00217 
00227         CSIBCXfoMatd& SetWithTranspose( const CSIBCRotMatd& in_mat );
00228 
00238         CSIBCXfoMatd& SetRow( const int in_nRow, const CSIBCVector4Dd& in_vct );
00239 
00251         CSIBCXfoMatd& SetRow( const int in_nRow, double in_dA0, double in_dA1, double in_dA2, double in_dA3 );
00252 
00262         CSIBCXfoMatd& SetCol( const int in_nCol, const CSIBCVector4Dd& in_vct );
00263 
00275         CSIBCXfoMatd& SetCol( const int in_nCol, double in_dA0, double in_dA1, double in_dA2, double in_dA3 );
00276 
00281         CSIBCXfoMatd& SetIdentity( void );
00282 
00283         //****************************************
00284         // Matrix comparison functions:
00285         //****************************************
00286 
00297         friend bool AreAlmostEqual( const CSIBCXfoMatd& in_mat1,
00298                                 const CSIBCXfoMatd& in_mat2,
00299                                 const double in_dEpsilon = HEXA_EPS );
00300 
00308         bool operator ==( const CSIBCMatrix44d& in_mat ) const;
00309 
00317         bool operator !=( const CSIBCMatrix44d& in_mat ) const;
00318 
00319         //****************************************
00320         // Matrix algebra functions:
00321         //****************************************
00322 
00331         CSIBCXfoMatd& Mul( const CSIBCXfoMatd& in_mat1, const CSIBCXfoMatd& in_mat2 );
00332 
00340         CSIBCXfoMatd& Mul( const CSIBCXfoMatd& in_mat );
00341 
00350         CSIBCXfoMatd& Mul( const CSIBCXfoMatd& in_xfomat, const CSIBCRotMatd& in_rotmat );
00351 
00360         CSIBCXfoMatd& Mul( const CSIBCRotMatd& in_rotmat, const CSIBCXfoMatd& in_xfomat );
00361 
00362         
00373         CSIBCXfoMatd& MulTransByReg( const CSIBCRotMatd& in_rotmat,
00374                             const CSIBCXfoMatd& in_xfomat );
00375 
00381         double GetDet( void ) const;
00382 
00388         double GetDet33( void ) const;
00389 
00395         double GetTrace( void ) const;
00396 
00402         CSIBCXfoMatd& Transpose( const CSIBCXfoMatd& in_mat );
00403 
00408         CSIBCXfoMatd& Transpose( void );
00409 
00416         bool Invert( const CSIBCXfoMatd& in_mat );
00417 
00423         bool Invert( void );
00424 
00431         CSIBCVector3Dd& GetTranslation( CSIBCVector3Dd& out_vctTrs ) const;
00432 
00439         CSIBCXfoMatd& SetTranslation( const CSIBCVector3Dd& in_vctTrs );
00440 
00447         CSIBCXfoMatd& AddTranslation( const CSIBCVector3Dd& in_vctTrs );
00448 
00456         CSIBCRotMatd& GetRotation( CSIBCRotMatd& out_matRot ) const;
00457 
00465         CSIBCRotationd& GetRotation( CSIBCRotationd& out_rot ) const;
00466 
00473         CSIBCXfoMatd& SetRotation( const CSIBCRotMatd& in_matRot );
00474 
00481         CSIBCXfoMatd& AddRotation( const CSIBCRotMatd& in_matRot );
00482 
00489         CSIBCVector3Dd& GetScaling( CSIBCVector3Dd& out_vctScl ) const;
00490 
00497         CSIBCXfoMatd& SetScaling( const CSIBCVector3Dd& in_vctScl );
00498 
00508         CSIBCXfoMatd& AddScaling( const CSIBCVector3Dd& in_vctScl, bool in_bPreScaling = true );
00509 
00518         void SetScalingAndRotation( const CSIBCVector3Dd& in_vctScl, CSIBCRotationd& in_rot );
00519 
00528         void GetScalingAndRotation( CSIBCVector3Dd& out_vctScl, CSIBCRotationd& out_rot ) const;
00529 
00536         void GetAffineDecomposition ( CSIBCRotMatd& out_sclRot, CSIBCXfoMatd& out_matSRT ) const;
00537 
00545         void GetSmartDecomposition ( CSIBCVector3D& out_Scale, CSIBCVector3D& out_Rotate, CSIBCVector3D& out_Trans ) const;
00546 
00547     // Protected members
00548     protected:
00549 
00550         // If you have to reserve other bits in CSIBCMatrix44d::m_MaskInfo for the specific usage of CSIBCMatrix44d
00551         // please update the value of _3D_NB_BITS_RESERVED_BY_XFOMAT accordingly.
00552         enum { 
00553             _3D_X_NEGATIVE              = (unsigned char)( 1 << (_3D_NB_BITS_RESERVED_BY_MAT44 + 0) ),
00554             _3D_Y_NEGATIVE              = (unsigned char)( 1 << (_3D_NB_BITS_RESERVED_BY_MAT44 + 1) ),
00555             _3D_Z_NEGATIVE              = (unsigned char)( 1 << (_3D_NB_BITS_RESERVED_BY_MAT44 + 2) ),
00556             _3D_ALLAXES_NEGATIVE_MASK   = (unsigned char)( _3D_X_NEGATIVE | _3D_Y_NEGATIVE | _3D_Z_NEGATIVE ),
00557         };
00558 
00559     // Private members
00560     private:
00561 
00562         // Please do not re-enable the following cast operator as it will cause problems for the following Scenario:
00563         // CSIBCMatrix44d l_mat;
00564         // CSIBCVector3Dd l_vct;
00565         // l_vct.Mul( l_vct, l_mat );
00566         // there are two Mul functions applicable:
00567         // 1-   CSIBCVector3Dd & CSIBCVector3Dd::Mul( const CSIBCVector3Dd &, const CSIBCMatrix44d & );
00568         // 2-   CSIBCVector3Dd & CSIBCVector3Dd::Mul( const CSIBCVector3Dd &, const CSIBCXfoMatd & );
00569         // Unfortunately, if the following operator is enabled, the second Mul function will be taken
00570         // which is not what the client wants !!!
00571         // EC.
00572         CSIBCXfoMatd( const CSIBCMatrix44d & ); // Disable this cast operator
00573         CSIBCXfoMatd( const CSIBCMatrix33d& in_mat );
00574 
00575         //Disable copy constructor and operator =
00576         CSIBCXfoMatd( const CSIBCXfoMatd& in_mat );
00577         CSIBCXfoMatd& operator =( const CSIBCXfoMatd& in_mat );
00578 
00579         //Methods to handles SignBits for the scaling factor.
00580         void SetSclSignBits( const CSIBCVector3Dd &in_vctScl ); // SetSclSignBits | Set m_MaskInfo from in_vctScl.
00581         void XORSclSignBits( const CSIBCVector3Dd &in_vctScl ); // XORSclSignBits | XOR m_MaskInfo from in_vctScl.
00582 
00583         void SetSclSignBits( const unsigned char in_SclBits );  // SetSclSignBits | Set the sign bits of m_MaskInfo to those of in_SclBits.
00584         void XORSclSignBits( const unsigned char in_Bits1, const unsigned char in_Bits2 );// XORSclSignBits | Return the XOR of in_Mask1 and in_Mask2 masked with _3D_ALLAXES_NEGATIVE_MASK.
00585         unsigned char GetSclSignBits( ) const;              // GetSclSignBits | Return the sign bits sub-part of m_MaskInfo.
00586         void ClearSclSignBits();                            // ClearSclSignBits | Clear the bit signs part of m_MaskInfo
00587         bool IsSclAxisNegative( int in_axe ) const;         // IsSclAxisNegative | Look if one scl bit is set.
00588 };
00589 typedef CSIBCXfoMatd* LP3DXFOMAT;
00590 typedef const CSIBCXfoMatd* LPC3DXFOMAT;
00591 
00592 #endif