![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsQuaternion.hpp 00003 00004 Quaternion class (hpp file). 00005 00006 SUKITTI PUNAK (07/12/2009) 00007 UPDATE (11/01/2010) 00008 ******************************************************************************/ 00009 #ifndef TAPs_QUATERNION_HPP 00010 #define TAPs_QUATERNION_HPP 00011 00012 #include "TAPsVector3.hpp" 00013 #include "TAPsMatrix3x3.hpp" 00014 #include "TAPsMatrix4x4.hpp" 00015 00046 BEGIN_NAMESPACE_TAPs 00047 //============================================================================= 00048 template <typename T> 00049 class Quaternion { 00050 //============================================================================= 00051 public: 00052 // Member Functions ------------------------------------------------------- 00054 friend std::ostream & operator<< ( std::ostream &output, Quaternion<T> const &obj ) 00055 { 00056 output << obj.StrInfo(); 00057 return output; 00058 } 00059 //------------------------------------------------------------------------- 00060 00062 00066 Quaternion (); 00067 00069 Quaternion ( T r, T i, T j, T k ); 00070 00072 Quaternion ( T q[4] ); 00073 00075 Quaternion ( Vector3<T> const & P ); 00076 00078 Quaternion ( Quaternion<T> const &Q ); 00079 00081 //Quaternion ( Matrix3x3<T> const & R3x3 ); 00082 00084 //Quaternion ( Matrix4x4<T> const & R4x4 ); 00085 00087 ~Quaternion (); 00088 00089 //------------------------------------------------------------------------- 00091 virtual std::string StrInfo () const; 00092 00093 //------------------------------------------------------------------------- 00094 // Operators and Operations 00095 00097 //inline T & operator[] ( int i ); 00099 //inline T const & operator[] ( int i ) const; 00100 00102 inline Quaternion<T> operator! (); 00104 inline void Conjugated (); 00106 inline Quaternion<T> GetConjugate () const; 00107 00108 // Assignment Operator 00109 inline Quaternion<T> & operator= ( Quaternion<T> const &Q ); 00110 00112 inline Quaternion<T> operator+ ( Quaternion<T> const &Q ) const; 00114 inline Quaternion<T> & operator+= ( Quaternion<T> const &Q ); 00115 00117 inline Quaternion<T> operator- ( Quaternion<T> const &Q ) const; 00119 inline Quaternion<T> & operator-= ( Quaternion<T> const &Q ); 00120 00122 inline Quaternion<T> operator* ( Quaternion<T> const &Q ) const; 00124 inline Quaternion<T> operator* ( Vector3<T> const &V ) const; 00126 inline Quaternion<T> & operator*= ( Quaternion<T> const &Q ); 00127 00129 inline T InnerProduct ( Quaternion<T> const &Q ) const; 00130 00132 inline Quaternion<T> operator* ( T a ) const; 00134 inline Quaternion<T> & operator*= ( T a ); 00135 00137 inline T GetNormSquare () const; 00139 inline T GetNorm () const; 00141 inline Quaternion<T> & Normalized (); 00142 00144 inline Quaternion<T> GetInverse () const; 00146 inline void Inversed (); 00147 00148 //------------------------------------------------------------------------- 00149 // Conversions 00150 00152 inline Matrix3x3<T> GetRotationMatrix3x3 () const; 00153 00155 inline Matrix4x4<T> GetRotationMatrix4x4 () const; 00156 00161 void SetByRotationMatrix3x3 ( Matrix3x3<T> const & R3x3 ); 00162 00167 //void SetFromRotationMatrix3x3 ( Matrix3x3<T> const & R3x3 ); 00168 00170 //void SetFromRotationMatrix4x4 ( Matrix4x4<T> const & R4x4 ); 00171 00177 inline Matrix4x4<T> GetQuaternionMatrix () const; 00178 00184 inline Matrix4x4<T> GetQuaternionConjugateMatrix () const; 00185 00186 //------------------------------------------------------------------------- 00187 00191 inline void SetByRotationAxisAndAngle ( Vector3<T> const & rotAxis, T angle ); 00196 inline void SetByRotationAxisAndAngle ( T rotAxis_x, T rotAxis_y, T rotAxis_z, T angle ); 00197 00199 inline void GetRotationAxisAndAngle ( Vector3<T> & rotAxis, T & angle ); 00201 inline void GetRotationAxisAndAngle ( T& rotAxis_x, T& rotAxis_y, T& rotAxis_z, T& angle ); 00202 00203 00205 inline void RotatePt ( Vector3<T> & P ) const; 00207 inline void RotatePt ( T & P_x, T & P_y, T & P_z ) const; 00208 00210 inline Vector3<T> CalRotatedPtOfPt ( Vector3<T> const & P ) const; 00212 inline Vector3<T> CalRotatedPtOfPt ( T P_x, T P_y, T P_z ) const; 00213 00214 //------------------------------------------------------------------------- 00215 // Get/Set Functions 00216 00218 T GetR () const { return m_r; } 00220 void SetR ( T r ) { m_r = r; } 00221 00223 T GetI () const { return m_i; } 00225 void SetI ( T i ) { m_i = i; } 00226 00228 T GetJ () const { return m_j; } 00230 void SetJ ( T j ) { m_j = j; } 00231 00233 T GetK () const { return m_k; } 00235 void SetK ( T k ) { m_k = k; } 00236 00238 void SetIJK ( T i, T j, T k ) { m_i=i; m_j=j; m_k=k; } 00240 void GetIJK ( T &i, T &j, T &k ) const { i=m_i; j=m_j; k=m_k; } 00241 00243 void SetIJK ( T a[3] ) { m_i=a[0]; m_j=a[1]; m_k=a[2]; } 00245 void GetIJK ( T a[3] ) const { a[0]=m_i; a[1]=m_j; a[2]=m_k; } 00246 00248 void SetIJK ( Vector3<T> const & v ) { m_i=v[0]; m_j=v[1]; m_k=v[2]; } 00250 void GetIJK ( Vector3<T> & v ) const { v.SetXYZ( m_i, m_j, m_k ); } 00251 00253 void SetRIJK ( T a[4] ) { m_r=a[0]; m_i=a[1]; m_j=a[2]; m_k=a[3]; } 00255 void GetRIJK ( T a[4] ) const { a[0]=m_r; a[1]=m_i; a[2]=m_j; a[3]=m_k; } 00257 void SetRIJK ( T r, T i, T j, T k ) { m_r=r; m_i=i; m_j=j; m_k=k; } 00259 void GetRIJK ( T &r, T &i, T &j, T &k ) const { r=m_r; i=m_i; j=m_j; k=m_k; } 00260 //------------------------------------------------------------------------- 00261 // Data Members ----------------------------------------------------------- 00262 //============================================================================= 00263 protected: 00264 // Member Functions ------------------------------------------------------- 00265 // Data Members ----------------------------------------------------------- 00266 T m_r, m_i, m_j, m_k; 00267 //============================================================================= 00268 private: 00269 // Member Functions ------------------------------------------------------- 00270 // Data Members ----------------------------------------------------------- 00271 //============================================================================= 00272 00273 #if defined(__gl_h_) || defined(__GL_H__) 00274 public: 00275 // Transfrom by OpenGL for Drawing by OpenGL 00276 virtual void TransformByOpenGLForDrawing () const; 00277 #endif 00278 00279 //============================================================================= 00280 }; // END CLASS Quaternion 00281 //============================================================================= 00282 00284 template <typename T> 00285 inline Quaternion<T> operator* ( T a, Quaternion<T> const &Q ) { return Q*a; } 00286 00287 //----------------------------------------------------------------------------- 00288 //============================================================================= 00289 END_NAMESPACE_TAPs 00290 //----------------------------------------------------------------------------- 00291 #include "TAPsQuaternion.cpp" 00292 //----------------------------------------------------------------------------- 00293 #endif 00294 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00295 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----