TAPs 0.7.7.3
TAPsColMatrix4x4.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsColMatrix4x4.hpp
00003 
00004 ColMatrix4x4 class is a class for a 4-by-4 matrix in column-major order.
00005 
00006 SUKITTI PUNAK   (09/14/2004)
00007 UPDATE          (09/29/2007)
00008 ******************************************************************************/
00009 #ifndef TAPs_COL_MATRIX4X4_H
00010 #define TAPs_COL_MATRIX4X4_H
00011 
00012 #include "TAPsMath.hpp"
00013 
00014 BEGIN_NAMESPACE_TAPs
00015 //=============================================================================
00016 template <typename T>
00017 class ColMatrix4x4 {
00018 //=============================================================================
00019 private:
00020     // Matrix Elements
00021     // Matrix Elements
00022     //       --                          --
00023     //      |  e[ 0]  e[ 4]  e[ 8]  e[12]  |
00024     //      |  e[ 1]  e[ 5]  e[ 9]  e[13]  |
00025     //      |  e[ 2]  e[ 6]  e[10]  e[14]  |
00026     //      |  e[ 3]  e[ 7]  e[11]  e[15]  |
00027     //       --                          --
00028     T e[16];
00029     //-------------------------------------------------------------------------
00030     // Static Data Members for Data Conversions
00031     static float        g_f[16];
00032     static double       g_d[16];
00033     static long double  g_ld[16];
00034     //-------------------------------------------------------------------------
00035 public:
00036     //-------------------------------------------------------------------------
00037     // Output Operator <<
00038     friend std::ostream & operator<< ( std::ostream &output, ColMatrix4x4<T> const &M )
00039     {
00040         int width = 14;
00041         //output << typeid(*this).name() << "( ";
00042         output  << "ColMatrix4x4<" << typeid(T).name() << "> =\n"
00043                 << "| " << std::setw(width) << M.e[0] 
00044                         << std::setw(width) << M.e[4] 
00045                         << std::setw(width) << M.e[8] 
00046                         << std::setw(width) << M.e[12] << " |\n"
00047                 << "| " << std::setw(width) << M.e[1] 
00048                         << std::setw(width) << M.e[5] 
00049                         << std::setw(width) << M.e[9] 
00050                         << std::setw(width) << M.e[13] << " |\n"
00051                 << "| " << std::setw(width) << M.e[2] 
00052                         << std::setw(width) << M.e[6] 
00053                         << std::setw(width) << M.e[10] 
00054                         << std::setw(width) << M.e[14] << " |\n"
00055                 << "| " << std::setw(width) << M.e[3] 
00056                         << std::setw(width) << M.e[7] 
00057                         << std::setw(width) << M.e[11] 
00058                         << std::setw(width) << M.e[15] << " |\n";
00059         //output << std::endl;
00060         return output;
00061     }
00062     //-------------------------------------------------------------------------
00063     // Constructors
00064     ColMatrix4x4 ();        // default constructor (Identity Matrix)
00065     ColMatrix4x4 ( ColMatrix4x4<T> const &M );  // copy constructor
00066     ColMatrix4x4 ( T );                         // constructor
00067     ColMatrix4x4 ( T, T, T, T, T, T, T, T,
00068                 T, T, T, T, T, T, T, T );       // constructor
00069     ColMatrix4x4 ( T const af[16] );            // constructor from array
00070     ~ColMatrix4x4 ();                           // destructor
00071     //-------------------------------------------------------------------------
00072     // Member Access
00073     inline T &       operator[] ( int i );
00074     inline T const & operator[] ( int i ) const;
00075     inline T &       operator() ( int r, int c );
00076     inline T const & operator() ( int r, int c ) const;
00077     //-------------------------------------------------------------------------
00078     // Convert to one dimension array
00079     operator const T *() const;
00080     operator T *();
00081     //-------------------------------------------------------------------------
00082     // Useful Functions
00083     inline void SetAllElements ( T );                       // set all elements
00084     inline void SetAllElements ( T, T, T, T, T, T, T, T, 
00085                                  T, T, T, T, T, T, T, T );  // set all elements
00086     inline void SetAllElements ( T const af[16] );          // set all elements
00087     inline void MakeIdentity ();                    // set to identity matrix
00088     inline void MakeDiagonal ( T d );               // set to diagonal matrix
00089     inline void MakeDiagonal ( T const af[4] );     // set to diagonal matrix
00090     inline void MakeZero ();                        // set all elements to zero
00091     //-------------------------------------------------------------------------
00092     // Matrix Operations
00093     inline ColMatrix4x4<T> & Transposed ();
00094     inline ColMatrix4x4<T>   GetTranspose () const;
00095     inline ColMatrix4x4<T> & Inversed ();
00096     ColMatrix4x4<T>   GetInverse () const;
00097     inline T GetDeterminant () const;
00098     //-------------------------------------------------------------------------
00099     // Assignment Overloaded Operators
00100     ColMatrix4x4<T> & operator= ( ColMatrix4x4 const &M );
00101     //-------------------------------------------------------------------------
00102     // Unary Overloaded Operators
00103     ColMatrix4x4<T> operator- ();   // negation
00104     //-------------------------------------------------------------------------
00105     // Assign Overloaded Operators
00106     ColMatrix4x4<T> &operator+= ( ColMatrix4x4<T> const &M );   // += with matrix
00107     ColMatrix4x4<T> &operator-= ( ColMatrix4x4<T> const &M );   // -= with matrix
00108     ColMatrix4x4<T> &operator*= ( ColMatrix4x4<T> const &M );   // *= with matrix
00109     ColMatrix4x4<T> &operator*= ( T s );                        // *= with scalar
00110     ColMatrix4x4<T> &operator/= ( T s );                        // /= with scalar
00111     //-------------------------------------------------------------------------
00112     // Binary Overloaded Operators
00113     ColMatrix4x4<T> operator+ ( ColMatrix4x4<T> const &M ) const;   // matrix + matrix
00114     ColMatrix4x4<T> operator- ( ColMatrix4x4<T> const &M ) const;   // matrix - matrix
00115     ColMatrix4x4<T> operator* ( ColMatrix4x4<T> const &M ) const;   // matrix * matrix
00116     ColMatrix4x4<T> operator* ( T s ) const;                    // matrix * scalar
00117     friend inline ColMatrix4x4<T> operator* ( T s, ColMatrix4x4<T> const &M )   // scalar * matrix
00118     {   return M * s;   }
00119     ColMatrix4x4<T> operator/ ( T s ) const;                    // matrix / scalar
00120     inline void MultLeft ( ColMatrix4x4<T> const &M );  // this matrix = matrix M * this matrix
00121     inline void MultRight ( ColMatrix4x4<T> const &M ); // this matrix = this matrix * matrix M
00122     //-------------------------------------------------------------------------
00123     // Static Member Functions for Data Conversions
00124     const float *           GetDataFloat () const;
00125     const double *          GetDataDouble () const;
00126     const long double *     GetDataLongDouble () const;
00127     const float *           GetTransposeDataFloat () const;
00128     const double *          GetTransposeDataDouble () const;
00129     const long double *     GetTransposeDataLongDouble () const;
00130 }; // END CLASS ColMatrix4x4
00131 //=============================================================================
00132 //-----------------------------------------------------------------------------
00133 // Define ColMatrix4x4s
00134 typedef ColMatrix4x4<int>           ColMatrix4x4i;
00135 typedef ColMatrix4x4<float>         ColMatrix4x4f;
00136 typedef ColMatrix4x4<double>        ColMatrix4x4d;
00137 typedef ColMatrix4x4<long double>   ColMatrix4x4ld;
00138 //=============================================================================
00139 END_NAMESPACE_TAPs
00140 //-----------------------------------------------------------------------------
00141 // Include definition if TAPs_USE_EXPORT is not defined
00142 //#if !defined( TAPs_USE_EXPORT )
00143     #include "TAPsColMatrix4x4.cpp"
00144 //#endif
00145 //-----------------------------------------------------------------------------
00146 #endif
00147 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00148 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines