![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsMatrix4x4.hpp 00003 00004 Matrix4x4 class is a class for 4-by-4 matrices. 00005 00006 SUKITTI PUNAK (09/14/2004) 00007 UPDATE (05/06/2010) 00008 ******************************************************************************/ 00009 #ifndef TAPs_MATRIX4X4_H 00010 #define TAPs_MATRIX4X4_H 00011 00012 #include "TAPsMath.hpp" 00013 00014 00015 BEGIN_NAMESPACE_TAPs 00016 //============================================================================= 00017 // Class Forward 00018 template <typename T> class Vector3; 00019 template <typename T> class Vector4; 00020 template <typename T> class Matrix3x3; 00021 //============================================================================= 00022 template <typename T> 00023 class Matrix4x4 { 00024 //============================================================================= 00025 private: 00026 // Matrix Elements 00027 // Matrix Elements 00028 // -- -- 00029 // | e[ 0] e[ 1] e[ 2] e[ 3] | 00030 // | e[ 4] e[ 5] e[ 6] e[ 7] | 00031 // | e[ 8] e[ 9] e[10] e[11] | 00032 // | e[12] e[13] e[14] e[15] | 00033 // -- -- 00034 T e[16]; 00035 //------------------------------------------------------------------------- 00036 // Static Data Members for Data Conversions 00037 static float g_f[16]; 00038 static double g_d[16]; 00039 static long double g_ld[16]; 00040 //------------------------------------------------------------------------- 00041 public: 00042 //------------------------------------------------------------------------- 00043 // Output Operator << 00044 friend std::ostream & operator<< ( std::ostream &output, Matrix4x4<T> const &M ) 00045 { 00046 int width = 14; 00047 //output << typeid(*this).name() << "( "; 00048 output << "Matrix4x4<" << typeid(T).name() << "> =\n" 00049 << "| " << std::setw(width) << M.e[0] 00050 << std::setw(width) << M.e[1] 00051 << std::setw(width) << M.e[2] 00052 << std::setw(width) << M.e[3] << " |\n" 00053 << "| " << std::setw(width) << M.e[4] 00054 << std::setw(width) << M.e[5] 00055 << std::setw(width) << M.e[6] 00056 << std::setw(width) << M.e[7] << " |\n" 00057 << "| " << std::setw(width) << M.e[8] 00058 << std::setw(width) << M.e[9] 00059 << std::setw(width) << M.e[10] 00060 << std::setw(width) << M.e[11] << " |\n" 00061 << "| " << std::setw(width) << M.e[12] 00062 << std::setw(width) << M.e[13] 00063 << std::setw(width) << M.e[14] 00064 << std::setw(width) << M.e[15] << " |\n"; 00065 //output << std::endl; 00066 return output; 00067 } 00068 //------------------------------------------------------------------------- 00069 // Constructors 00070 Matrix4x4 (); // default constructor (Identity Matrix) 00071 Matrix4x4 ( Matrix4x4<T> const &M ); // copy constructor 00072 Matrix4x4 ( T ); // constructor 00073 Matrix4x4 ( T, T, T, T, T, T, T, T, 00074 T, T, T, T, T, T, T, T ); // constructor 00075 Matrix4x4 ( T const af[16] ); // constructor from array 00076 Matrix4x4 ( Matrix3x3<T> const & M ); // constructor from Matrix3x3 00077 Matrix4x4 ( Vector3<T> const & V ); // constructor from Vector3 00078 Matrix4x4 ( Vector4<T> const & V ); // constructor from Vector4 00079 ~Matrix4x4 (); // destructor 00080 //------------------------------------------------------------------------- 00081 // Member Access 00082 inline T & operator[] ( int i ); 00083 inline T const & operator[] ( int i ) const; 00084 inline T & operator() ( int r, int c ); 00085 inline T const & operator() ( int r, int c ) const; 00086 //------------------------------------------------------------------------- 00087 // Convert to one dimension array 00088 operator const T *() const; 00089 operator T *(); 00090 //------------------------------------------------------------------------- 00091 // Useful Functions 00092 inline void SetAllElements ( T ); // set all elements 00093 inline void SetAllElements ( T, T, T, T, T, T, T, T, 00094 T, T, T, T, T, T, T, T ); // set all elements 00095 inline void SetAllElements ( T const af[16] ); // set all elements 00096 inline void MakeIdentity (); // set to identity matrix 00097 inline void MakeDiagonal ( T d ); // set to diagonal matrix 00098 inline void MakeDiagonal ( T const af[4] ); // set to diagonal matrix 00099 inline void MakeZero (); // set all elements to zero 00100 inline bool IsIdentity () const; // Is it an identity matrix? 00101 inline bool IsSymmetric () const // Is it a symmetric matrix? 00102 { return e[1]==e[4] && e[2]==e[ 8] && e[ 3]==e[12] 00103 && e[6]==e[9] && e[7]==e[13] && e[11]==e[14]; } 00104 inline bool IsSquare () const // Is it a square matrix? 00105 { return true;} 00106 //------------------------------------------------------------------------- 00107 // Matrix Operations 00108 inline Matrix4x4<T> & Transposed (); 00109 inline Matrix4x4<T> GetTranspose () const; 00110 inline Matrix4x4<T> & Inversed (); 00111 Matrix4x4<T> GetInverse () const; 00112 inline T GetDeterminant () const; 00113 //------------------------------------------------------------------------- 00114 // Assignment Overloaded Operators 00115 Matrix4x4<T> & operator= ( Matrix4x4 const &M ); 00116 //------------------------------------------------------------------------- 00117 // Unary Overloaded Operators 00118 Matrix4x4<T> operator- (); // negation 00119 //------------------------------------------------------------------------- 00120 // Assign Overloaded Operators 00121 Matrix4x4<T> &operator+= ( Matrix4x4<T> const &M ); // += with matrix 00122 Matrix4x4<T> &operator-= ( Matrix4x4<T> const &M ); // -= with matrix 00123 Matrix4x4<T> &operator*= ( Matrix4x4<T> const &M ); // *= with matrix 00124 Matrix4x4<T> &operator*= ( T s ); // *= with scalar 00125 Matrix4x4<T> &operator/= ( T s ); // /= with scalar 00126 //------------------------------------------------------------------------- 00127 // Binary Overloaded Operators 00128 Matrix4x4<T> operator+ ( Matrix4x4<T> const &M ) const; // matrix + matrix 00129 Matrix4x4<T> operator- ( Matrix4x4<T> const &M ) const; // matrix - matrix 00130 Matrix4x4<T> operator* ( Matrix4x4<T> const &M ) const; // matrix * matrix 00131 Matrix4x4<T> operator* ( T s ) const; // matrix * scalar 00132 friend inline Matrix4x4<T> operator* ( T s, Matrix4x4<T> const &M ) // scalar * matrix 00133 { return M * s; } 00134 Matrix4x4<T> operator/ ( T s ) const; // matrix / scalar 00135 inline void MultLeft ( Matrix4x4<T> const &M ); // this matrix = matrix M * this matrix 00136 inline void MultRight ( Matrix4x4<T> const &M ); // this matrix = this matrix * matrix M 00137 //------------------------------------------------------------------------- 00139 Vector4<T> operator* ( Vector4<T> const &V4 ) const; 00140 Vector3<T> operator* ( Vector3<T> const &V3 ) const; 00141 //------------------------------------------------------------------------- 00142 // Graphics Operation(s) 00143 static Matrix4x4<T> CreateRotation ( Vector3<T> const &V, T const angle ); 00144 //------------------------------------------------------------------------- 00145 // Conversion(s) 00146 inline Matrix3x3<T> GetMatrix3x3 () const; 00147 //------------------------------------------------------------------------- 00148 // Static Member Functions for Data Conversions 00149 const float * GetDataFloat () const; 00150 const double * GetDataDouble () const; 00151 const long double * GetDataLongDouble () const; 00152 const float * GetTransposeDataFloat () const; 00153 const double * GetTransposeDataDouble () const; 00154 const long double * GetTransposeDataLongDouble () const; 00155 //------------------------------------------------------------------------- 00156 }; // END CLASS Matrix4x4 00157 //============================================================================= 00158 //----------------------------------------------------------------------------- 00159 // Define Matrix4x4s 00160 typedef Matrix4x4<int> Matrix4x4i; 00161 typedef Matrix4x4<float> Matrix4x4f; 00162 typedef Matrix4x4<double> Matrix4x4d; 00163 typedef Matrix4x4<long double> Matrix4x4ld; 00164 //============================================================================= 00165 END_NAMESPACE_TAPs 00166 //----------------------------------------------------------------------------- 00167 // Include definition if TAPs_USE_EXPORT is not defined 00168 //#if !defined( TAPs_USE_EXPORT ) 00169 #include "TAPsMatrix4x4.cpp" 00170 //#endif 00171 //----------------------------------------------------------------------------- 00172 #endif 00173 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00174 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8