![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsForces.cpp 00003 ******************************************************************************/ 00007 /****************************************************************************** 00008 SUKITTI PUNAK (04/07/2010) 00009 UPDATE (05/01/2010) 00010 ******************************************************************************/ 00011 #include "TAPsForces.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 00019 00020 //============================================================================= 00021 // PointForce 00022 //----------------------------------------------------------------------------- 00023 template <typename T> 00024 PointForce<T>::PointForce () 00025 : m_ID( -1 ) 00026 {} 00027 //----------------------------------------------------------------------------- 00028 template <typename T> 00029 PointForce<T>::PointForce ( T x, T y, T z, T fx, T fy, T fz, int id ) 00030 : m_Pos( x, y, z ), m_Force( fx, fy, fz ), m_ID( id ) 00031 { 00032 } 00033 //----------------------------------------------------------------------------- 00034 template <typename T> 00035 PointForce<T>::PointForce ( Vector3<T> const & position, Vector3<T> const & force, int id ) 00036 : m_Pos( position ), m_Force( force ), m_ID( id ) 00037 {} 00038 //----------------------------------------------------------------------------- 00039 template <typename T> 00040 PointForce<T>::PointForce ( PointForce const & orig ) 00041 : m_Pos( orig.m_Pos ), m_Force( orig.m_Force ), m_ID( orig.m_ID ) 00042 {} 00043 //----------------------------------------------------------------------------- 00044 template <typename T> 00045 PointForce<T>::~PointForce () 00046 {} 00047 //----------------------------------------------------------------------------- 00048 template <typename T> 00049 std::string PointForce<T>::StrInfo () const 00050 { 00051 std::ostringstream ss; 00052 ss << "PointForce<" << typeid(T).name() << "> with ID " << m_ID 00053 << " has force (" << m_Force[0] << "," << m_Force[1] << "," << m_Force[2] 00054 << ") is applied at position (" << m_Pos[0] << "," << m_Pos[1] << "," << m_Pos[2] 00055 << ")."; 00056 return ss.str(); 00057 } 00058 //----------------------------------------------------------------------------- 00059 template <typename T> 00060 PointForce<T> & PointForce<T>::operator= ( PointForce<T> const &orig ) 00061 { 00062 m_Pos = orig.m_Pos; 00063 m_Force = orig.m_Force; 00064 return *this; 00065 } 00066 //----------------------------------------------------------------------------- 00067 #if defined(__gl_h_) || defined(__GL_H__) 00068 template <typename T> 00069 void PointForce<T>::Draw () const 00070 { 00071 //glPushMatrix(); 00072 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00073 glLineWidth( 1 ); 00074 glDisable( GL_LIGHTING ); 00075 glBegin( GL_LINES ); 00076 glColor3f( 0, 1, 0 ); 00077 glVertex3f( static_cast<GLfloat>(m_Pos[0]), static_cast<GLfloat>(m_Pos[1]), static_cast<GLfloat>(m_Pos[2]) ); 00078 glColor3f( 1, 0, 0 ); 00079 glVertex3f( static_cast<GLfloat>(m_Force[0]), static_cast<GLfloat>(m_Force[1]), static_cast<GLfloat>(m_Force[2]) ); 00080 glEnd(); 00081 glPopAttrib(); 00082 //glPopMatrix(); 00083 } 00084 #endif 00085 //----------------------------------------------------------------------------- 00086 // PointForce 00087 //============================================================================= 00088 00089 00090 00091 //============================================================================= 00092 // ForceLists 00093 //----------------------------------------------------------------------------- 00094 template <typename T> 00095 void ForceLists<T>::ClearAllPointForces () 00096 { 00097 PointForces.clear(); 00098 } 00099 //----------------------------------------------------------------------------- 00100 template <typename T> 00101 void ForceLists<T>::ClearAllCDForces () 00102 { 00103 CDForces.clear(); 00104 } 00105 //----------------------------------------------------------------------------- 00106 template <typename T> 00107 void ForceLists<T>::ClearAllConnectionForces () 00108 { 00109 ConnectionForces.clear(); 00110 } 00111 //----------------------------------------------------------------------------- 00112 template <typename T> 00113 void ForceLists<T>::ClearAllForces () 00114 { 00115 ClearAllPointForces(); 00116 ClearAllCDForces(); 00117 ClearAllConnectionForces(); 00118 } 00119 //----------------------------------------------------------------------------- 00120 #if defined(__gl_h_) || defined(__GL_H__) 00121 //--------------------------------------------------------------- 00122 template <typename T> 00123 void ForceLists<T>::Draw () const 00124 { 00125 DrawPointForces(); 00126 DrawCDForces(); 00127 DrawConnectionForces(); 00128 } 00129 //--------------------------------------------------------------- 00130 template <typename T> 00131 void ForceLists<T>::DrawPointForces () const 00132 { 00133 TypeDef_PointForces::const_iterator it = PointForces.begin(); 00134 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00135 glLineWidth( 1 ); 00136 glDisable( GL_LIGHTING ); 00137 glBegin( GL_LINES ); 00138 while ( it != PointForces.end() ) { 00139 glColor3f( 0, 1, 0 ); 00140 glVertex3f( it->RefToPosition()[0], it->RefToPosition()[1], it->RefToPosition()[2] ); 00141 glColor3f( 1, 0, 0 ); 00142 glVertex3f( it->RefToForce()[0], it->RefToForce()[1], it->RefToForce()[2] ); 00143 ++it; 00144 } 00145 glEnd(); 00146 glPopAttrib(); 00147 } 00148 //--------------------------------------------------------------- 00149 template <typename T> 00150 void ForceLists<T>::DrawCDForces () const 00151 { 00152 TypeDef_PointForces::const_iterator it = CDForces.begin(); 00153 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00154 glLineWidth( 1 ); 00155 glDisable( GL_LIGHTING ); 00156 glBegin( GL_LINES ); 00157 while ( it != CDForces.end() ) { 00158 glColor3f( 0, 1, 0 ); 00159 glVertex3f( it->RefToPosition()[0], it->RefToPosition()[1], it->RefToPosition()[2] ); 00160 glColor3f( 1, 0, 0 ); 00161 glVertex3f( it->RefToForce()[0], it->RefToForce()[1], it->RefToForce()[2] ); 00162 ++it; 00163 } 00164 glEnd(); 00165 glPopAttrib(); 00166 } 00167 //--------------------------------------------------------------- 00168 template <typename T> 00169 void ForceLists<T>::DrawConnectionForces () const 00170 { 00171 TypeDef_PointForces::const_iterator it = ConnectionForces.begin(); 00172 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00173 glLineWidth( 1 ); 00174 glDisable( GL_LIGHTING ); 00175 glBegin( GL_LINES ); 00176 while ( it != ConnectionForces.end() ) { 00177 glColor3f( 0, 1, 0 ); 00178 glVertex3f( it->RefToPosition()[0], it->RefToPosition()[1], it->RefToPosition()[2] ); 00179 glColor3f( 1, 0, 0 ); 00180 glVertex3f( it->RefToForce()[0], it->RefToForce()[1], it->RefToForce()[2] ); 00181 ++it; 00182 } 00183 glEnd(); 00184 glPopAttrib(); 00185 } 00186 #endif 00187 //----------------------------------------------------------------------------- 00188 // ForceLists 00189 //============================================================================= 00190 00191 00192 00193 00194 //============================================================================= 00195 // ForceListsPtr 00196 //----------------------------------------------------------------------------- 00197 template <typename T> 00198 void ForceListsPtr<T>::ClearAllPointForces () 00199 { 00200 PointForces.clear(); 00201 } 00202 //----------------------------------------------------------------------------- 00203 template <typename T> 00204 void ForceListsPtr<T>::ClearAllCDForces () 00205 { 00206 CDForces.clear(); 00207 } 00208 //----------------------------------------------------------------------------- 00209 template <typename T> 00210 void ForceListsPtr<T>::ClearAllConnectionForces () 00211 { 00212 ConnectionForces.clear(); 00213 } 00214 //----------------------------------------------------------------------------- 00215 template <typename T> 00216 void ForceListsPtr<T>::ClearAllForces () 00217 { 00218 ClearAllPointForces(); 00219 ClearAllCDForces(); 00220 ClearAllConnectionForces(); 00221 } 00222 //----------------------------------------------------------------------------- 00223 #if defined(__gl_h_) || defined(__GL_H__) 00224 //--------------------------------------------------------------- 00225 template <typename T> 00226 void ForceListsPtr<T>::Draw () const 00227 { 00228 DrawPointForces(); 00229 DrawCDForces(); 00230 DrawConnectionForces(); 00231 } 00232 //--------------------------------------------------------------- 00233 template <typename T> 00234 void ForceListsPtr<T>::DrawPointForces () const 00235 { 00236 TypeDef_PointForces::const_iterator it = PointForces.begin(); 00237 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00238 glLineWidth( 1 ); 00239 glDisable( GL_LIGHTING ); 00240 glBegin( GL_LINES ); 00241 while ( it != PointForces.end() ) { 00242 glColor3f( 0, 1, 0 ); 00243 glVertex3fv( (**it).RefToPosition().GetDataFloat() ); 00244 glColor3f( 1, 0, 0 ); 00245 glVertex3fv( ( (**it).RefToForce() + (**it).RefToPosition() ).GetDataFloat() ); 00246 ++it; 00247 } 00248 glEnd(); 00249 glPopAttrib(); 00250 } 00251 //--------------------------------------------------------------- 00252 template <typename T> 00253 void ForceListsPtr<T>::DrawCDForces () const 00254 { 00255 TypeDef_PointForces::const_iterator it = CDForces.begin(); 00256 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00257 glLineWidth( 1 ); 00258 glDisable( GL_LIGHTING ); 00259 glBegin( GL_LINES ); 00260 while ( it != CDForces.end() ) { 00261 glColor3f( 0, 1, 0 ); 00262 glVertex3fv( (**it).RefToPosition().GetDataFloat() ); 00263 glColor3f( 1, 0, 0 ); 00264 glVertex3fv( ( (**it).RefToForce() + (**it).RefToPosition() ).GetDataFloat() ); 00265 ++it; 00266 } 00267 glEnd(); 00268 glPopAttrib(); 00269 } 00270 //--------------------------------------------------------------- 00271 template <typename T> 00272 void ForceListsPtr<T>::DrawConnectionForces () const 00273 { 00274 TypeDef_PointForces::const_iterator it = ConnectionForces.begin(); 00275 glPushAttrib( GL_ALL_ATTRIB_BITS ); 00276 glLineWidth( 1 ); 00277 glDisable( GL_LIGHTING ); 00278 glBegin( GL_LINES ); 00279 while ( it != ConnectionForces.end() ) { 00280 glColor3f( 0, 1, 0 ); 00281 glVertex3fv( (**it).RefToPosition().GetDataFloat() ); 00282 glColor3f( 1, 0, 0 ); 00283 glVertex3fv( ( (**it).RefToForce() + (**it).RefToPosition() ).GetDataFloat() ); 00284 ++it; 00285 } 00286 glEnd(); 00287 glPopAttrib(); 00288 } 00289 #endif 00290 //----------------------------------------------------------------------------- 00291 // ForceListsPtr 00292 //============================================================================= 00293 00294 00295 00296 00297 //============================================================================= 00298 END_NAMESPACE_TAPs 00299 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00300 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----