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