SIBCMatrix.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 // SIBCMatrix.h | Main header file for SIBCMatrix4x4 implementation
00008 //***************************************************************************************
00009 
00010 /****************************************************************************************
00011 THIS CODE IS PUBLISHED AS A SAMPLE ONLY AND IS PROVIDED "AS IS".
00012 IN NO EVENT SHALL SOFTIMAGE, AVID TECHNOLOGY, INC. AND/OR THEIR RESPECTIVE
00013 SUPPLIERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
00014 DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00015 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00016 CONNECTION WITH THE USE OR PERFORMANCE OF THIS CODE .
00017 
00018 COPYRIGHT NOTICE. Copyright © 1999-2002 Avid Technology Inc. . All rights reserved. 
00019 
00020 SOFTIMAGE is a registered trademark of Avid Technology Inc. or its subsidiaries 
00021 or divisions. Windows NT is a registered trademark of Microsoft Corp. All other
00022 trademarks contained herein are the property of their respective owners. 
00023 ****************************************************************************************/
00024 
00025 //***************************************************************************************
00026 // Defines
00027 //***************************************************************************************
00028 #ifndef __CSIBCMatrix_H__
00029 #define __CSIBCMatrix_H__
00030 
00031 //***************************************************************************************
00032 // Includes
00033 //***************************************************************************************
00034 #include <SIBCVector.h>
00035 
00036 #ifdef _PSX2
00037 #include <libvu0.h>
00038 #endif
00039 
00040 //***************************************************************************************
00041 // Typedefs
00042 //***************************************************************************************
00043 
00044 //***************************************************************************************
00045 // CSIBCMatrix4x4 | Matrices are stored in column major order, e.g., m_Matrix[ROW][COLUMN]
00046 //***************************************************************************************
00047 
00049 
00060 class XSICOREEXPORT CSIBCMatrix4x4
00061 {
00062     public:
00063 
00067         CSIBCMatrix4x4();
00068 
00073         CSIBCMatrix4x4( const CSIBCMatrix4x4 & i_Matrix);
00074 
00082         CSIBCMatrix4x4( SI_Float * i_pMatrix);
00083 
00084         ~CSIBCMatrix4x4();                                              // Default Destructor
00085 
00086         // Components
00087 
00096         SI_Error Set( const CSIBCMatrix4x4 & i_Matrix);
00097 
00128         SI_Error Set( const SI_Float * i_pMatrix);
00129         
00142         SI_Error Set( const SI_Byte i_bIndex, SI_Float i_fValue);
00143 
00157         SI_Error Set(   const SI_Byte i_Column, 
00158                         const SI_Byte i_Row, 
00159                         const SI_Float i_fValue);
00160 
00170         void SetToScale( const CSIBCVector3D & i_vScale);
00171 
00181         void SetToRotation( const CSIBCVector3D & i_vEuler);
00182 
00188         void SetToRotation( const SI_Float angl, const CSIBCVector3D &axis );
00189 
00194         void SetToTranslation( const CSIBCVector3D & i_vTrans);
00195 
00232         void SetTransforms( const CSIBCVector3D &scale,
00233                             const CSIBCVector3D &rot,
00234                             const CSIBCVector3D &trans );
00235 
00236 
00262         void SetScaling( const CSIBCVector3D & i_vScaling); 
00263 
00298         void SetRotation( const CSIBCVector3D & i_vRot);
00299 
00311         void SetRotation( const CSIBCMatrix4x4 & i_mMatrix);
00312 
00327         void SetOrientation(    const CSIBCVector3D &x_axis,
00328                                 const CSIBCVector3D &y_axis,
00329                                 const CSIBCVector3D &z_axis );
00330 
00339         void SetTranslation( const CSIBCVector3D & i_vTrans);
00340 
00341         // Retrieve Information.
00342 
00354         SI_Error Get( SI_Float * o_pMatrix) const;
00355 
00368         SI_Error Get( CSIBCMatrix4x4 & o_mMatrix) const;
00369 
00375         SI_Float Get( const SI_Byte i_bIndex) const;
00376 
00377 
00384         SI_Float Get( const SI_Byte i_Column, const SI_Byte i_Row) const;   // Retrieves the value at an index 2d
00385         
00390         void GetScaling( CSIBCVector3D & o_vScale) const;
00391 
00396         void GetRotation( CSIBCVector3D & o_vRot) const ;                       // Gets the rotation values for euler xyz
00397 
00405         void GetOrientation(    CSIBCVector3D &x_axis, 
00406                                 CSIBCVector3D &y_axis, 
00407                                 CSIBCVector3D &z_axis ) const ;
00408         
00414         void GetTranslation( CSIBCVector3D & o_vTrans) const;
00415 
00428         void GetTransforms( CSIBCVector3D &scale,
00429                             CSIBCVector3D &rot,
00430                             CSIBCVector3D &trans );
00431 
00435         SI_Bool IsIdentity();
00436 
00437         // Operations
00438 
00446         SI_Bool GetInverse( CSIBCMatrix4x4 & o_mMatrix);
00447         
00451         CSIBCMatrix4x4& Normalize();
00452 
00457         CSIBCMatrix4x4& SetNull();
00458 
00464         CSIBCMatrix4x4& SetIdentity();
00465 
00469         CSIBCMatrix4x4& Transpose();
00470         
00479         void ColumnMajor( SI_Float * o_pMatrix);
00480 
00486         void RowMajor( SI_Float * );                                    // Copies the matrix in row major format
00487 
00498         SI_Float *Raw();
00499         
00506         SI_Matrix *GetSIMatrix() { return &m_Matrix; }
00507 
00518         void LookAt( const CSIBCVector3D &pos,
00519                      const CSIBCVector3D &target,
00520                      const CSIBCVector3D &up,
00521                      const SI_Float roll );
00522 
00523 
00537         void Ortho( const SI_Float left,
00538                     const SI_Float right,
00539                     const SI_Float top,
00540                     const SI_Float bottom,
00541                     const SI_Float nearPlane,
00542                     const SI_Float farPlane);
00543 
00556         void Perspective(   const SI_Float nearPlane,
00557                             const SI_Float farPlane,
00558                             const SI_Float fov,
00559                             const SI_Float aspect );
00560 
00573         void PerspectiveAlt(    const SI_Float nearPlane,
00574                                 const SI_Float farPlane,
00575                                 const SI_Float fov,
00576                                 const SI_Float aspect );
00577 
00589         SI_Bool AlignAxes(  CSIBCVector3D *x_vec,
00590                             CSIBCVector3D *xy_vec );
00591 
00601         SI_Bool AlignRoll(  SI_Float        in_Roll,
00602                             CSIBCVector3D   *in_pVector);
00603 
00613         CSIBCMatrix4x4 &Multiply( CSIBCMatrix4x4 & i_mMatrix);
00614 
00630         SI_Error Multiply(  CSIBCMatrix4x4 & i_mMatrix, 
00631                             CSIBCMatrix4x4 &result);
00632 
00643         CSIBCMatrix4x4 &Multiply4x3( const CSIBCMatrix4x4 & i_mMatrix);
00644 
00660         SI_Error Multiply4x3(   const CSIBCMatrix4x4 & i_mMatrix, 
00661                                 CSIBCMatrix4x4 &result) const;
00662 
00675         CSIBCVector4D Multiply( const CSIBCVector2D & i_vVector) const;
00676 
00690         CSIBCVector4D Multiply( const CSIBCVector3D & i_vVector);
00691 
00702         CSIBCVector4D Multiply( const CSIBCVector4D & i_vVector);
00703 
00717         void Multiply( CSIBCVector3D &i_vResult, const CSIBCVector3D &i_vVector );
00718 
00732         void MultiplyLeft( CSIBCVector3D & i_vResult, const CSIBCVector3D &i_vVector ) const;
00733 
00734 #ifdef _PSX2
00735 
00746         void CacheMatrix();
00747 
00761         void CacheMultiply( CSIBCVector3D & i_vResult, CSIBCVector3D & i_vVector);
00762 
00775         void CacheMultiply( CSIBCVector4D & i_vResult, const CSIBCVector4D & i_vVector);
00776 
00790         void CacheMultiplyScale( CSIBCVector3D & i_vResult, CSIBCVector3D & i_vVector, float i_fScale );
00791 
00807         void CacheMultiplyScaleAdd( CSIBCVector3D & io_vResult, CSIBCVector3D & i_vVector, float i_fScale );
00808 #endif
00809 
00810         // Operators 
00811 
00822         CSIBCMatrix4x4      operator*(CSIBCMatrix4x4 & i_mMatrix);
00823 
00824 
00837         CSIBCVector4D       operator*(CSIBCVector2D & i_vVector);
00838 
00852         CSIBCVector4D       operator*(CSIBCVector3D & i_vVector);
00853 
00865         CSIBCVector4D       operator*(CSIBCVector4D & i_vVector);
00866 
00873         CSIBCMatrix4x4&     operator = (const CSIBCMatrix4x4 & i_mMatrix);
00874 
00882         CSIBCMatrix4x4&     operator +=( const CSIBCMatrix4x4 & i_mMatrix);
00883 
00887         SI_Error Dump();
00888 
00892         SI_Error SelfTest();
00893 
00894     private:
00895 
00896 #ifdef _PSX2
00897         sceVu0FMATRIX   m_Matrix;
00898         float           *row1;
00899         float           *row2;
00900         float           *row3;
00901         float           *row4;
00902 #else
00903         SI_Matrix       m_Matrix;
00904 #endif
00905 
00906 };
00907 
00908 #endif 
00909 // CSIBCMatrix