TAPs 0.7.7.3
TAPsPointMassDynamicWithQuaternionRotation.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsPointMassDynamicWithQuaternionRotation.cpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (08/12/2010)
00009 UPDATE          (09/21/2010)
00010 ******************************************************************************/
00011 #include "TAPsPointMassDynamicWithQuaternionRotation.hpp"
00012 // Using Inclusion Model (i.e. definitions are included in declarations)
00013 //                       (this name.cpp is included in name.hpp)
00014 // Each friend is defined directly inside its declaration.
00015 
00016 BEGIN_NAMESPACE_TAPs
00017 //=============================================================================
00018 // Constructors and Destructor
00019 //-----------------------------------------------------------------------------
00020 template <typename T>
00021 PointMassDynamicWithQuaternionRotation<T>::PointMassDynamicWithQuaternionRotation ( bool bRandomValue )
00022 {
00023     bRandomValue ? RandomValues() : DefaultValues();
00024     m_Type = TYPE_DYNAMIC_WITH_ORIENTATION;
00025 }
00026 //-----------------------------------------------------------------------------
00027 template <typename T>
00028 PointMassDynamicWithQuaternionRotation<T>::PointMassDynamicWithQuaternionRotation
00029 ( 
00030     T                   mass,
00031     T                   radius,
00032     Vector3<T> const &  position,
00033     Vector3<T> const &  velocity,
00034     Vector3<T> const &  acceleration,
00035     Vector3<T> const &  force,
00036     Quaternion<T> const &   rotation,
00037     DS::SimulationFlags const & flags
00038 )   : PointMassDynamic<T>( mass, size, position, velocity, acceleration, force, flags )
00039     , m_QuaternionRotation( rotation )
00040 {
00041     m_Type = TYPE_DYNAMIC_WITH_ORIENTATION;
00042 }
00043 //-----------------------------------------------------------------------------
00044 template <typename T>
00045 PointMassDynamicWithQuaternionRotation<T>::PointMassDynamicWithQuaternionRotation ( PointMassDynamicWithQuaternionRotation<T> const & P )
00046     : PointMassDynamic<T>( P )
00047     , m_QuaternionRotation( P.m_QuaternionRotation )
00048 {
00049     m_Type = TYPE_DYNAMIC_WITH_ORIENTATION;
00050 }
00051 //-----------------------------------------------------------------------------
00052 template <typename T>
00053 PointMassDynamicWithQuaternionRotation<T>::PointMassDynamicWithQuaternionRotation ( Vector3<T> const & location )
00054     : PointMassDynamic<T>( location )
00055 {
00056     m_Type = TYPE_DYNAMIC_WITH_ORIENTATION;
00057 }
00058 //-----------------------------------------------------------------------------
00059 template <typename T>
00060 PointMassDynamicWithQuaternionRotation<T>::PointMassDynamicWithQuaternionRotation ( T const location[3] )
00061     : PointMassDynamic<T>( location )
00062 {
00063     m_Type = TYPE_DYNAMIC_WITH_ORIENTATION;
00064 }
00065 //-----------------------------------------------------------------------------
00066 template <typename T>
00067 PointMassDynamicWithQuaternionRotation<T>::PointMassDynamicWithQuaternionRotation ( T locX, T locY, T locZ )
00068     : PointMassDynamic<T>( locX, locY, locZ )
00069 {
00070     m_Type = TYPE_DYNAMIC_WITH_ORIENTATION;
00071 }
00072 //-----------------------------------------------------------------------------
00073 // PointMassDynamicWithQuaternionRotation Destructor
00074 template <typename T>
00075 PointMassDynamicWithQuaternionRotation<T>::~PointMassDynamicWithQuaternionRotation ()
00076 {}
00077 //-----------------------------------------------------------------------------
00078 template <typename T>
00079 std::string PointMassDynamicWithQuaternionRotation<T>::StrInfo () const
00080 {
00081     std::stringstream ss;
00082     ss  << "PointMassDynamicWithQuaternionRotation<" << typeid(T).name() << "> ==> "
00083         << "\n  Mass:         " << GetMass()
00084         << "\n  Position:     " << GetPosition()
00085         << "\n  Velocity:     " << GetVelocity()
00086         << "\n  Acceleration: " << GetAcceleration()
00087         << "\n  Force:        " << GetForce()
00088         << "\n  QuaternionRotation: " << GetQuaternionRotation()
00089         << "\n  Simulation Flags:   " << GetFlags()
00090         << "\n";
00091     return ss.str();
00092 }
00093 //-----------------------------------------------------------------------------
00094 
00095 //=============================================================================
00096 // PointMassDynamicWithQuaternionRotation Assignment Operator
00097 //-----------------------------------------------------------------------------
00098 template <typename T>
00099 PointMassDynamicWithQuaternionRotation<T> const & PointMassDynamicWithQuaternionRotation<T>::operator= ( PointMassDynamicWithQuaternionRotation<T> const & P )
00100 {
00101     if ( this != &P )
00102     {
00103         *(dynamic_cast< PointMassDynamic<T> * >(this)) = *(dynamic_cast< PointMassDynamic<T> const * >(&P));
00104         m_QuaternionRotation = P.m_QuaternionRotation;
00105     }
00106     return *this;
00107 }
00108 //-----------------------------------------------------------------------------
00109 
00110 //=============================================================================
00111 // Get/Set Functions
00112 //-----------------------------------------------------------------------------
00113 template <typename T>
00114 Quaternion<T> const & PointMassDynamicWithQuaternionRotation<T>::GetQuaternionRotation () const
00115 {
00116     return m_QuaternionRotation;
00117 }
00118 
00119 template <typename T>
00120 Quaternion<T> & PointMassDynamicWithQuaternionRotation<T>::GetQuaternionRotation ()
00121 {
00122     return m_QuaternionRotation;
00123 }
00124 
00125 template <typename T>
00126 void PointMassDynamicWithQuaternionRotation<T>::SetQuaternionRotation ( Quaternion<T> const & rotation )
00127 {
00128     m_QuaternionRotation = rotation;
00129 }
00130 
00131 template <typename T>
00132 void PointMassDynamicWithQuaternionRotation<T>::SetQuaternionRotation ( T r, T i, T j, T k )
00133 {
00134     m_QuaternionRotation.SetRIJK( r, i, j, k );
00135 }
00136 //-----------------------------------------------------------------------------
00137 
00138 
00139 //=============================================================================
00140 //-----------------------------------------------------------------------------
00141 template <typename T>
00142 void PointMassDynamicWithQuaternionRotation<T>::DefaultValues ()
00143 {
00144     PointMassDynamic<T>::DefaultValues();
00145     m_QuaternionRotation.SetRIJK( 1, 0, 0, 0 );
00146 }
00147 //-----------------------------------------------------------------------------
00148 template <typename T>
00149 void PointMassDynamicWithQuaternionRotation<T>::RandomValues ()
00150 {
00151     PointMassDynamic<T>::RandomValues();
00152     // between -1.0 to 1.0
00153     m_QuaternionRotation.SetRIJK( (rand()%201-100)/100.0, (rand()%201-100)/100.0, (rand()%201-100)/100.0, (rand()%201-100)/100.0 );
00154     m_QuaternionRotation.Normalized();
00155 }
00156 //-----------------------------------------------------------------------------
00157 
00158 //=============================================================================
00159 #if defined(__gl_h_) || defined(__GL_H__)
00160 template <typename T>
00161 void PointMassDynamicWithQuaternionRotation<T>::Draw () const
00162 {
00163     glPushMatrix();
00164     glPushAttrib( GL_ALL_ATTRIB_BITS );
00165     glTranslatef( static_cast<float>(m_v3Position[0]), static_cast<float>(m_v3Position[1]), static_cast<float>(m_v3Position[2]) );
00166 
00167     //GetQuaternionRotation().TransformByOpenGLForDrawing();
00168     Matrix4x4<T> orientation = GetQuaternionRotation().GetRotationMatrix4x4();
00169     GLfloat m[16] = {
00170         static_cast<GLfloat>(orientation[ 0]), static_cast<GLfloat>(orientation[ 4]), static_cast<GLfloat>(orientation[ 8]), static_cast<GLfloat>(orientation[ 12]), 
00171         static_cast<GLfloat>(orientation[ 1]), static_cast<GLfloat>(orientation[ 5]), static_cast<GLfloat>(orientation[ 9]), static_cast<GLfloat>(orientation[ 13]), 
00172         static_cast<GLfloat>(orientation[ 2]), static_cast<GLfloat>(orientation[ 6]), static_cast<GLfloat>(orientation[10]), static_cast<GLfloat>(orientation[ 14]), 
00173         static_cast<GLfloat>(orientation[ 3]), static_cast<GLfloat>(orientation[ 7]), static_cast<GLfloat>(orientation[11]), static_cast<GLfloat>(orientation[ 15])
00174     };
00175     glMultMatrixf( m );
00176 
00177     glEnable( GL_COLOR_MATERIAL );
00178     glColor4f( 0.5, 0.5, 0.5, 0.5 );
00179     //glutSolidSphere( GetSize(), 10, 10 );
00180     glutSolidCone(
00181         GetSize(),      // GLdouble base
00182         2*GetSize(),    // GLdouble height
00183         10,             // GLint slices
00184         10              // GLint stacks
00185     );
00186     glPopAttrib();
00187     glPopMatrix();
00188 }
00189 
00190 template <typename T>
00191 void PointMassDynamicWithQuaternionRotation<T>::Draw ( T scale ) const
00192 {
00193     glPushMatrix();
00194     glPushAttrib( GL_ALL_ATTRIB_BITS );
00195     glTranslatef( static_cast<float>(GetPosition()[0]), static_cast<float>(GetPosition()[1]), static_cast<float>(GetPosition()[2]) );
00196 
00197     //GetQuaternionRotation().TransformByOpenGLForDrawing();
00198     Matrix4x4<T> orientation = GetQuaternionRotation().GetRotationMatrix4x4();
00199     GLfloat m[16] = {
00200         static_cast<GLfloat>(orientation[ 0]), static_cast<GLfloat>(orientation[ 4]), static_cast<GLfloat>(orientation[ 8]), static_cast<GLfloat>(orientation[ 12]), 
00201         static_cast<GLfloat>(orientation[ 1]), static_cast<GLfloat>(orientation[ 5]), static_cast<GLfloat>(orientation[ 9]), static_cast<GLfloat>(orientation[ 13]), 
00202         static_cast<GLfloat>(orientation[ 2]), static_cast<GLfloat>(orientation[ 6]), static_cast<GLfloat>(orientation[10]), static_cast<GLfloat>(orientation[ 14]), 
00203         static_cast<GLfloat>(orientation[ 3]), static_cast<GLfloat>(orientation[ 7]), static_cast<GLfloat>(orientation[11]), static_cast<GLfloat>(orientation[ 15])
00204     };
00205     glMultMatrixf( m );
00206 
00207     glEnable( GL_COLOR_MATERIAL );
00208     glColor4f( 0.5, 0.5, 0.5, 0.5 );
00209     //glutSolidSphere( GetSize()*scale, 10, 10 );
00210     glutSolidCone(
00211         scale*GetSize(),    // GLdouble base
00212         scale*2*GetSize(),  // GLdouble height
00213         10,                 // GLint slices
00214         10                  // GLint stacks
00215     );
00216     glPopAttrib();
00217     glPopMatrix();
00218 }
00219 #endif // #if defined(__gl_h_) || defined(__GL_H__)
00220 //=============================================================================
00221 END_NAMESPACE_TAPs
00222 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00223 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines