TAPs 0.7.7.3
TAPsTransformationSupport.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsTransformationSupport.cpp
00003 ******************************************************************************/
00006 /******************************************************************************
00007 SUKITTI PUNAK   (03/03/2006)
00008 UPDATE          (09/12/2010)
00009 ******************************************************************************/
00010 #include "TAPsTransformationSupport.hpp"
00011 // Using Inclusion Model (i.e. definitions are included in declarations)
00012 //                       (this name.cpp is included in name.hpp)
00013 // Each friend is defined directly inside its declaration.
00014 
00015 BEGIN_NAMESPACE_TAPs
00016 //=============================================================================
00017 //-----------------------------------------------------------------------------
00018 // Default Constructor
00019 template <typename T>
00020 TransformationSupport<T>::TransformationSupport ( TransformationSupport<T> * pParent )
00021     //: m_pParent( pParent )
00022 {
00023     MakeIdentity();
00024 
00025     #ifdef  TAPs_DEBUG_MODE
00026     std::cout   << "TransformationSupport<" << typeid(T).name() << "> constructor\n";
00027     #endif//TAPs_DEBUG_MODE
00028 }
00029 //-----------------------------------------------------------------------------
00030 // Copy Constructor
00031 template <typename T>
00032 TransformationSupport<T>::TransformationSupport ( const TransformationSupport<T> & orig )
00033     : m_TransformationMatrix( orig.m_TransformationMatrix )
00034       //,m_pParent( orig.m_pParent )
00035 {
00036     #ifdef  TAPs_DEBUG_MODE
00037     std::cout   << "TransformationSupport<" << typeid(T).name() << "> copy constructor\n";
00038     #endif//TAPs_DEBUG_MODE
00039 }
00040 //-----------------------------------------------------------------------------
00041 // Destructor
00042 template <typename T>
00043 TransformationSupport<T>::~TransformationSupport ()
00044 {
00045     #ifdef  TAPs_DEBUG_MODE
00046     std::cout   << "TransformationSupport<" << typeid(T).name() << "> destructor\n";
00047     #endif//TAPs_DEBUG_MODE
00048 }
00049 //-----------------------------------------------------------------------------
00050 // Return this object info as a string
00051 template <typename T>
00052 std::string TransformationSupport<T>::StrInfo () const
00053 {
00054     std::ostringstream ss;
00055     ss << "TransformationSupport<" << typeid(T).name() << ">";
00056     ss << "\n  Trx Matrix: ";
00057     ss << m_TransformationMatrix;
00058     return ss.str();
00059 }
00060 //-----------------------------------------------------------------------------
00061 // Assignment Operator
00062 template <typename T>
00063 inline TAPs::TransformationSupport<T> & TAPs::TransformationSupport<T>::operator= ( 
00064     TAPs::TransformationSupport<T> const & orig )
00065 {   
00066     m_TransformationMatrix  =   orig.m_TransformationMatrix;
00067     //m_pParent             =   orig.m_pParent;
00068     return *this;
00069 }
00070 //-----------------------------------------------------------------------------
00071 // Reset Fn
00072 //template <typename T>
00073 //void TransformationSupport<T>::Reset ()
00074 //{
00075 //  m_TransformationMatrix.MakeIdentity();
00076 //}
00077 //-----------------------------------------------------------------------------
00078 //=============================================================================
00079 // Transformations
00080 //-----------------------------------------------------------------------------
00081 // PRE APPLY TRANSLATION
00082 template <typename T>
00083 void TransformationSupport<T>::PreApplyTranslation ( Vector3<T> const & C )
00084 {
00085     m_TransformationMatrix = 
00086         Matrix4x4<T>( 
00087             1, 0, 0, C[0],
00088             0, 1, 0, C[1],
00089             0, 0, 1, C[2],
00090             0, 0, 0, 1
00091         )   *   m_TransformationMatrix;
00092 }
00093 //-----------------------------------------------------------------------------
00094 // PRE APPLY TRANSLATION
00095 template <typename T>
00096 void TransformationSupport<T>::PreApplyTranslation ( T x, T y, T z )
00097 {
00098     m_TransformationMatrix = 
00099         Matrix4x4<T>( 
00100             1, 0, 0, x,
00101             0, 1, 0, y,
00102             0, 0, 1, z,
00103             0, 0, 0, 1
00104         )   *   m_TransformationMatrix;
00105 }
00106 //-----------------------------------------------------------------------------
00107 // APPLY TRANSLATION
00108 template <typename T>
00109 void TransformationSupport<T>::ApplyTranslation ( Vector3<T> const & C )
00110 {
00111     m_TransformationMatrix *= 
00112         Matrix4x4<T>( 
00113             1, 0, 0, C[0],
00114             0, 1, 0, C[1],
00115             0, 0, 1, C[2],
00116             0, 0, 0, 1
00117         );
00118 }
00119 //-----------------------------------------------------------------------------
00120 // APPLY TRANSLATION
00121 template <typename T>
00122 void TransformationSupport<T>::ApplyTranslation ( T x, T y, T z )
00123 {
00124     m_TransformationMatrix *= 
00125         Matrix4x4<T>( 
00126             1, 0, 0, x,
00127             0, 1, 0, y,
00128             0, 0, 1, z,
00129             0, 0, 0, 1
00130         );
00131 }
00132 //-----------------------------------------------------------------------------
00133 // GET TRANSLATION
00134 template <typename T>
00135 Vector3<T> TransformationSupport<T>::GetTranslation () const
00136 {
00137     return Vector3<T>( 
00138         m_TransformationMatrix[ 3], 
00139         m_TransformationMatrix[ 7], 
00140         m_TransformationMatrix[11]
00141     );
00142 }
00143 //-----------------------------------------------------------------------------
00144 // GET TRANSLATION
00145 template <typename T>
00146 void TransformationSupport<T>::GetTranslation ( Vector3<T> & C ) const
00147 {
00148     C[0] = m_TransformationMatrix[ 3];
00149     C[1] = m_TransformationMatrix[ 7];
00150     C[2] = m_TransformationMatrix[11];
00151 }
00152 //-----------------------------------------------------------------------------
00153 // GET TRANSLATION
00154 template <typename T>
00155 void TransformationSupport<T>::GetTranslation ( T & x, T & y, T & z ) const
00156 {
00157     x = m_TransformationMatrix[ 3];
00158     y = m_TransformationMatrix[ 7];
00159     z = m_TransformationMatrix[11];
00160 }
00161 //-----------------------------------------------------------------------------
00162 // SET TRANSLATION
00163 template <typename T>
00164 void TransformationSupport<T>::SetTranslation ( Vector3<T> const & C )
00165 {
00166     m_TransformationMatrix[ 3] = C[0];
00167     m_TransformationMatrix[ 7] = C[1];
00168     m_TransformationMatrix[11] = C[2];
00169 }
00170 //-----------------------------------------------------------------------------
00171 // SET TRANSLATION
00172 template <typename T>
00173 void TransformationSupport<T>::SetTranslation ( T x, T y, T z )
00174 {
00175     m_TransformationMatrix[ 3] = x;
00176     m_TransformationMatrix[ 7] = y;
00177     m_TransformationMatrix[11] = z;
00178 }
00179 //-----------------------------------------------------------------------------
00180 // RETURN TRANSLATION
00181 template <typename T>
00182 T & TransformationSupport<T>::ReturnTranslation ( int i )
00183 {
00184     assert( 0 <= i && i <= 2 );
00185     return m_TransformationMatrix[i*4 + 3];
00186 }
00187 //-----------------------------------------------------------------------------
00188 // SET ROTATION
00189 template <typename T>
00190 void TransformationSupport<T>::SetRotation ( Matrix3x3<T> const & MR )
00191 {
00192     m_TransformationMatrix[ 0] = MR[0];
00193     m_TransformationMatrix[ 1] = MR[1];
00194     m_TransformationMatrix[ 2] = MR[2];
00195     m_TransformationMatrix[ 4] = MR[3];
00196     m_TransformationMatrix[ 5] = MR[4];
00197     m_TransformationMatrix[ 6] = MR[5];
00198     m_TransformationMatrix[ 8] = MR[6];
00199     m_TransformationMatrix[ 9] = MR[7];
00200     m_TransformationMatrix[10] = MR[8];
00201 }
00202 //-----------------------------------------------------------------------------
00203 //=============================================================================
00204 //-----------------------------------------------------------------------------
00205 // PRE APPLY ROTATION
00206 template <typename T>
00207 void TransformationSupport<T>::PreApplyRotationAxisAndAngle ( 
00208         Vector3<T> const & vAxis, T tAngle )
00209 {
00210     m_TransformationMatrix = 
00211         Matrix4x4<T>( CGMath<T>::CreateRotationMatrix3x3( vAxis, tAngle ) )
00212       * m_TransformationMatrix;
00213 }
00214 //-----------------------------------------------------------------------------
00215 // PRE APPLY ROTATION
00216 template <typename T>
00217 void TransformationSupport<T>::PreApplyRotationAxisAndAngle ( 
00218         T x, T y, T z, T angle )
00219 {
00220     PreApplyRotationAxisAndAngle( Vector3<T>( x, y, z ), angle );
00221 }
00222 //-----------------------------------------------------------------------------
00223 // PRE APPLY ROTATION
00224 template <typename T>
00225 void TransformationSupport<T>::PreApplyRotationFromVectorAtoVectorB ( 
00226         Vector3<T> const & A, Vector3<T> const & B )
00227 {
00228     m_TransformationMatrix = 
00229         Matrix4x4<T>( CGMath<T>::CreateRotationMatrix3x3FromVectorAtoVectorB( A, B ) );
00230       * m_TransformationMatrix;
00231 }
00232 //-----------------------------------------------------------------------------
00233 // APPLY ROTATION
00234 template <typename T>
00235 void TransformationSupport<T>::ApplyRotationAxisAndAngle ( 
00236         Vector3<T> const & vAxis, T tAngle )
00237 {
00238     m_TransformationMatrix *= 
00239         Matrix4x4<T>( CGMath<T>::CreateRotationMatrix3x3( vAxis, tAngle ) );
00240 }
00241 //-----------------------------------------------------------------------------
00242 // APPLY ROTATION
00243 template <typename T>
00244 void TransformationSupport<T>::ApplyRotationAxisAndAngle ( 
00245         T x, T y, T z, T angle )
00246 {
00247     ApplyRotationAxisAndAngle( Vector3<T>( x, y, z ), angle );
00248 }
00249 //-----------------------------------------------------------------------------
00250 // APPLY ROTATION
00251 template <typename T>
00252 void TransformationSupport<T>::ApplyRotationFromVectorAtoVectorB ( 
00253         Vector3<T> const & A, Vector3<T> const & B )
00254 {
00255     m_TransformationMatrix *= 
00256         Matrix4x4<T>( CGMath<T>::CreateRotationMatrix3x3FromVectorAtoVectorB( A, B ) );
00257 }
00258 //-----------------------------------------------------------------------------
00259 //=============================================================================
00260 //-----------------------------------------------------------------------------
00261 // PRE APPLY SCALE
00262 template <typename T>
00263 void TransformationSupport<T>::PreApplyScale ( Vector3<T> const & vScale )
00264 {
00265     m_TransformationMatrix = Matrix4x4<T>( vScale ) * m_TransformationMatrix;
00266 }
00267 //-----------------------------------------------------------------------------
00268 // PRE APPLY SCALE
00269 template <typename T>
00270 void TransformationSupport<T>::PreApplyScale ( T x, T y, T z )
00271 {
00272     PreApplyScale( Vector3<T>( x, y, z ) );
00273 }
00274 //-----------------------------------------------------------------------------
00275 // PRE APPLY SCALE
00276 template <typename T>
00277 void TransformationSupport<T>::PreApplyUniformScale ( T s )
00278 {
00279     PreApplyScale( Vector3<T>( s, s, s ) );
00280 }
00281 //-----------------------------------------------------------------------------
00282 // APPLY SCALE
00283 template <typename T>
00284 void TransformationSupport<T>::ApplyScale ( Vector3<T> const & vScale )
00285 {
00286     m_TransformationMatrix *= Matrix4x4<T>( vScale );
00287 }
00288 //-----------------------------------------------------------------------------
00289 // APPLY SCALE
00290 template <typename T>
00291 void TransformationSupport<T>::ApplyScale ( T x, T y, T z )
00292 {
00293     ApplyScale( Vector3<T>( x, y, z ) );
00294 }
00295 //-----------------------------------------------------------------------------
00296 // APPLY SCALE
00297 template <typename T>
00298 void TransformationSupport<T>::ApplyUniformScale ( T s )
00299 {
00300     ApplyScale( Vector3<T>( s, s, s ) );
00301 }
00302 //-----------------------------------------------------------------------------
00303 //=============================================================================
00304 // Static Member Functions for Data Conversions
00305 //-----------------------------------------------------------------------------
00306 template <typename T>
00307 const float * TransformationSupport<T>::GetMatrixTransformFloat () const
00308 {   return GetMatrixTransform().GetDataFloat(); }
00309 //-----------------------------------------------------------------------------
00310 template <typename T>
00311 const double * TransformationSupport<T>::GetMatrixTransformDouble () const
00312 {   return GetMatrixTransform().GetDataDouble();    }
00313 //-----------------------------------------------------------------------------
00314 template <typename T>
00315 const long double * TransformationSupport<T>::GetMatrixTransformLongDouble () const
00316 {   return GetMatrixTransform().GetDataLongDouble();    }
00317 //-----------------------------------------------------------------------------
00318 template <typename T>
00319 const float * TransformationSupport<T>::GetTransposeMatrixTransformFloat () const
00320 {   return GetMatrixTransform().GetTransposeDataFloat();    }
00321 //-----------------------------------------------------------------------------
00322 template <typename T>
00323 const double * TransformationSupport<T>::GetTransposeMatrixTransformDouble () const
00324 {   return GetMatrixTransform().GetTransposeDataDouble();   }
00325 //-----------------------------------------------------------------------------
00326 template <typename T>
00327 const long double * TransformationSupport<T>::GetTransposeMatrixTransformLongDouble () const
00328 {   return GetMatrixTransform().GetTransposeDataLongDouble();   }
00329 //-----------------------------------------------------------------------------
00330 
00331 //=============================================================================
00332 #if defined(__gl_h_) || defined(__GL_H__)
00333 //-----------------------------------------------------------------------------
00334 template <typename T>
00335 void TransformationSupport<T>::TransformByOpenGLForDrawing () const
00336 {
00337     glMultMatrixf( GetTransposeMatrixTransformFloat() );
00338 }
00339 //-----------------------------------------------------------------------------
00340 #endif
00341 //=============================================================================
00342 END_NAMESPACE_TAPs
00343 //-----------------------------------------------------------------------------
00344 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00345 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines