SIBCMatrix.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Crosswalk team
00004 //
00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.  
00006 // Use of this software is subject to the terms of the Autodesk license agreement 
00007 // provided at the time of installation or download, or which otherwise accompanies 
00008 // this software in either electronic or hard copy form.
00009 //
00010 //***************************************************************************************
00011 
00012 //***************************************************************************************
00013 // Defines
00014 //***************************************************************************************
00015 #ifndef __CSIBCMatrix_H__
00016 #define __CSIBCMatrix_H__
00017 
00018 //***************************************************************************************
00019 // Includes
00020 //***************************************************************************************
00021 #include <SIBCVector.h>
00022 
00023 #ifdef _PSX2
00024 #include <libvu0.h>
00025 #endif
00026 
00027 //***************************************************************************************
00028 // Typedefs
00029 //***************************************************************************************
00030 
00031 //***************************************************************************************
00032 // CSIBCMatrix4x4 | Matrices are stored in column major order, e.g., m_Matrix[ROW][COLUMN]
00033 //***************************************************************************************
00034 
00036 
00047 class XSICOREEXPORT CSIBCMatrix4x4
00048 {
00049     public:
00050 
00054         CSIBCMatrix4x4();
00055 
00060         CSIBCMatrix4x4( const CSIBCMatrix4x4 & i_Matrix);
00061 
00069         CSIBCMatrix4x4( SI_Float * i_pMatrix);
00070 
00071         ~CSIBCMatrix4x4();                                              // Default Destructor
00072 
00073         // Components
00074 
00083         SI_Error Set( const CSIBCMatrix4x4 & i_Matrix);
00084 
00115         SI_Error Set( const SI_Float * i_pMatrix);
00116         
00129         SI_Error Set( const SI_Byte i_bIndex, SI_Float i_fValue);
00130 
00144         SI_Error Set(   const SI_Byte i_Column, 
00145                         const SI_Byte i_Row, 
00146                         const SI_Float i_fValue);
00147 
00157         void SetToScale( const CSIBCVector3D & i_vScale);
00158 
00168         void SetToRotation( const CSIBCVector3D & i_vEuler);
00169 
00175         void SetToRotation( const SI_Float angl, const CSIBCVector3D &axis );
00176 
00181         void SetToTranslation( const CSIBCVector3D & i_vTrans);
00182 
00219         void SetTransforms( const CSIBCVector3D &scale,
00220                             const CSIBCVector3D &rot,
00221                             const CSIBCVector3D &trans );
00222 
00223 
00249         void SetScaling( const CSIBCVector3D & i_vScaling); 
00250 
00285         void SetRotation( const CSIBCVector3D & i_vRot);
00286 
00298         void SetRotation( const CSIBCMatrix4x4 & i_mMatrix);
00299 
00314         void SetOrientation(    const CSIBCVector3D &x_axis,
00315                                 const CSIBCVector3D &y_axis,
00316                                 const CSIBCVector3D &z_axis );
00317 
00326         void SetTranslation( const CSIBCVector3D & i_vTrans);
00327 
00328         // Retrieve Information.
00329 
00341         SI_Error Get( SI_Float * o_pMatrix) const;
00342 
00355         SI_Error Get( CSIBCMatrix4x4 & o_mMatrix) const;
00356 
00362         SI_Float Get( const SI_Byte i_bIndex) const;
00363 
00364 
00371         SI_Float Get( const SI_Byte i_Column, const SI_Byte i_Row) const;   // Retrieves the value at an index 2d
00372         
00377         void GetScaling( CSIBCVector3D & o_vScale) const;
00378 
00383         void GetRotation( CSIBCVector3D & o_vRot) const ;                       // Gets the rotation values for euler xyz
00384 
00392         void GetOrientation(    CSIBCVector3D &x_axis, 
00393                                 CSIBCVector3D &y_axis, 
00394                                 CSIBCVector3D &z_axis ) const ;
00395         
00401         void GetTranslation( CSIBCVector3D & o_vTrans) const;
00402 
00415         void GetTransforms( CSIBCVector3D &scale,
00416                             CSIBCVector3D &rot,
00417                             CSIBCVector3D &trans );
00418 
00422         SI_Bool IsIdentity();
00423 
00424         // Operations
00425 
00433         SI_Bool GetInverse( CSIBCMatrix4x4 & o_mMatrix);
00434         
00438         CSIBCMatrix4x4& Normalize();
00439 
00444         CSIBCMatrix4x4& SetNull();
00445 
00451         CSIBCMatrix4x4& SetIdentity();
00452 
00456         CSIBCMatrix4x4& Transpose();
00457         
00466         void ColumnMajor( SI_Float * o_pMatrix);
00467 
00473         void RowMajor( SI_Float * );                                    // Copies the matrix in row major format
00474 
00485         SI_Float *Raw();
00486         
00493         SI_Matrix *GetSIMatrix() { return &m_Matrix; }
00494 
00505         void LookAt( const CSIBCVector3D &pos,
00506                      const CSIBCVector3D &target,
00507                      const CSIBCVector3D &up,
00508                      const SI_Float roll );
00509 
00510 
00524         void Ortho( const SI_Float left,
00525                     const SI_Float right,
00526                     const SI_Float top,
00527                     const SI_Float bottom,
00528                     const SI_Float nearPlane,
00529                     const SI_Float farPlane);
00530 
00543         void Perspective(   const SI_Float nearPlane,
00544                             const SI_Float farPlane,
00545                             const SI_Float fov,
00546                             const SI_Float aspect );
00547 
00560         void PerspectiveAlt(    const SI_Float nearPlane,
00561                                 const SI_Float farPlane,
00562                                 const SI_Float fov,
00563                                 const SI_Float aspect );
00564 
00576         SI_Bool AlignAxes(  CSIBCVector3D *x_vec,
00577                             CSIBCVector3D *xy_vec );
00578 
00588         SI_Bool AlignRoll(  SI_Float        in_Roll,
00589                             CSIBCVector3D   *in_pVector);
00590 
00600         CSIBCMatrix4x4 &Multiply( CSIBCMatrix4x4 & i_mMatrix);
00601 
00617         SI_Error Multiply(  CSIBCMatrix4x4 & i_mMatrix, 
00618                             CSIBCMatrix4x4 &result);
00619 
00630         CSIBCMatrix4x4 &Multiply4x3( const CSIBCMatrix4x4 & i_mMatrix);
00631 
00647         SI_Error Multiply4x3(   const CSIBCMatrix4x4 & i_mMatrix, 
00648                                 CSIBCMatrix4x4 &result) const;
00649 
00662         CSIBCVector4D Multiply( const CSIBCVector2D & i_vVector) const;
00663 
00677         CSIBCVector4D Multiply( const CSIBCVector3D & i_vVector);
00678 
00689         CSIBCVector4D Multiply( const CSIBCVector4D & i_vVector);
00690 
00704         void Multiply( CSIBCVector3D &i_vResult, const CSIBCVector3D &i_vVector );
00705 
00719         void MultiplyLeft( CSIBCVector3D & i_vResult, const CSIBCVector3D &i_vVector ) const;
00720 
00721 #ifdef _PSX2
00722 
00733         void CacheMatrix();
00734 
00748         void CacheMultiply( CSIBCVector3D & i_vResult, CSIBCVector3D & i_vVector);
00749 
00762         void CacheMultiply( CSIBCVector4D & i_vResult, const CSIBCVector4D & i_vVector);
00763 
00777         void CacheMultiplyScale( CSIBCVector3D & i_vResult, CSIBCVector3D & i_vVector, float i_fScale );
00778 
00794         void CacheMultiplyScaleAdd( CSIBCVector3D & io_vResult, CSIBCVector3D & i_vVector, float i_fScale );
00795 #endif
00796 
00797         // Operators 
00798 
00809         CSIBCMatrix4x4      operator*(CSIBCMatrix4x4 & i_mMatrix);
00810 
00811 
00824         CSIBCVector4D       operator*(CSIBCVector2D & i_vVector);
00825 
00839         CSIBCVector4D       operator*(CSIBCVector3D & i_vVector);
00840 
00852         CSIBCVector4D       operator*(CSIBCVector4D & i_vVector);
00853 
00860         CSIBCMatrix4x4&     operator = (const CSIBCMatrix4x4 & i_mMatrix);
00861 
00869         CSIBCMatrix4x4&     operator +=( const CSIBCMatrix4x4 & i_mMatrix);
00870 
00874         SI_Error Dump();
00875 
00879         SI_Error SelfTest();
00880 
00881     private:
00882 
00883 #ifdef _PSX2
00884         sceVu0FMATRIX   m_Matrix;
00885         float           *row1;
00886         float           *row2;
00887         float           *row3;
00888         float           *row4;
00889 #else
00890         SI_Matrix       m_Matrix;
00891 #endif
00892 
00893 };
00894 
00895 #endif 
00896 // CSIBCMatrix