![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsRigidBodyDynamics.hpp 00003 ******************************************************************************/ 00043 /****************************************************************************** 00044 SUKITTI PUNAK (03/25/2010) 00045 UPDATE (10/04/2010) 00046 ******************************************************************************/ 00047 #ifndef TAPs_RIGID_BODY_DYNAMICS_HPP 00048 #define TAPs_RIGID_BODY_DYNAMICS_HPP 00049 00050 #include "TAPsRigidBodyBase.hpp" 00051 #include "../../Support/TAPsPhysicsSupport.hpp" 00052 #include "../../Support/TAPsInteractionPointGroup.hpp" 00053 00054 #include "../../OpenGLModel/TAPsHalfEdgeModel.hpp" 00055 #include "../../Interface/TAPsInterfaceAdvanceSimulation.hpp" 00056 00057 #include "../../CG/TAPsCGAlgo.hpp" 00058 00059 BEGIN_NAMESPACE_TAPs 00060 //============================================================================= 00061 template <typename T> 00062 class RigidBodyDynamics : public /*virtual*/ RigidBodyBase<T> 00063 , public /*virtual*/ PhysicsSupport<T> 00064 , public /*virtual*/ InterfaceAdvanceSimulation<T> 00065 { 00066 //============================================================================= 00067 public: 00068 // Member Functions ------------------------------------------------------- 00070 friend std::ostream & operator<< ( std::ostream &output, RigidBodyDynamics<T> const &obj ) 00071 { 00072 output << obj.StrInfo(); 00073 return output; 00074 } 00075 //------------------------------------------------------------------------- 00077 RigidBodyDynamics (); 00078 00080 RigidBodyDynamics ( Vector3<T> const & Centroid, Quaternion<T> const & Orientation ); 00081 00083 //RigidBodyDynamics ( RigidBodyDynamics<T> const &orig ); 00084 00086 virtual ~RigidBodyDynamics (); 00087 00088 //------------------------------------------------------------------------- 00090 virtual std::string StrInfo () const; 00091 //------------------------------------------------------------------------- 00093 //inline RigidBodyDynamics<T> & operator= ( RigidBodyDynamics<T> const &orig ); 00094 00096 //PhysicsSupport<T> const & RefToPhysicsSupport () const { return m_PhysicsSupport; } 00098 //PhysicsSupport<T> & RefToPhysicsSupport() { return m_PhysicsSupport; } 00099 00101 InteractionPointGroup<T> const & RefToInteractionPointGroup () const { return m_IPGroup; } 00103 InteractionPointGroup<T> & RefToInteractionPointGroup () { return m_IPGroup; } 00104 00106 inline std::vector< Vector3<T> > GetAllInteractionPointPositionsInWorldSpace () const; 00107 00108 //------------------------------------------------------------------------- 00109 00120 bool CreateInteractionPointGroupBasedOnBVHTree ( 00121 int level = 0 00122 ); 00123 00124 //------------------------------------------------------------------------- 00125 00129 bool CalAndSetVolumeAndCentroid_BasedOnTetrahedra (); 00130 00134 bool CalAndSetVolumeAndCentroid_BasedOnInteractionPointGroup (); 00135 00137 void ClearAllForcesAndTorques (); 00138 00139 //------------------------------------------------------------------------- 00140 // Override the member functions from PhysicsSupport 00141 00143 inline virtual Vector3<T> const & GetCenterOfMass () const; 00145 inline virtual void SetCenterOfMass ( Vector3<T> const & COM ); 00147 inline virtual void SetCenterOfMass ( T x, T y, T z ); 00149 inline virtual void AdjustCenterOfMass ( Vector3<T> const & COM ); 00151 inline virtual void AdjustCenterOfMass ( T x, T y, T z ); 00152 00154 inline virtual void LockPosition () { m_bPositionLocked = true; } 00156 inline virtual void UnlockPosition () { m_bPositionLocked = false; } 00158 inline bool IsPositionLocked () const { return m_bPositionLocked; } 00159 00160 private: // Get and set functions for center of mass property from PhysicsSupport are not used. 00162 virtual Vector3<T> const & GetPhyPropCenterOfMass () const { return mPhyProp_vCenterOfMass; } 00164 virtual void SetPhyPropCenterOfMass ( Vector3<T> const & COM ) { mPhyProp_vCenterOfMass = COM; } 00166 virtual void SetPhyPropCenterOfMass ( T x, T y, T z ) { mPhyProp_vCenterOfMass.SetXYZ(x,y,z); } 00167 00168 private: // orientation property from PhysicsSupport is not used. 00170 virtual Quaternion<T> const & GetPhyPropOrientation () const { return mPhyProp_qOrientation; } 00172 virtual void SetPhyPropOrientation ( Quaternion<T> const & orientation ) { mPhyProp_qOrientation = orientation; } 00174 virtual void SetPhyPropOrientation ( T r, T i, T j, T k ) { mPhyProp_qOrientation.SetRIJK(r,i,j,k); } 00175 00176 public: 00177 00178 //------------------------------------------------------------------------- 00179 // Override the member functions from AdvanceSimulationInterface 00180 00182 virtual void AdvanceSimulation ( T timeStep ); 00183 00185 virtual void AdvanceSimulation ( T tCurrent, T tNext ); 00186 00188 virtual void AdvanceSimulation ( Simulation::SimClock<T> & simClock ); 00189 00190 //------------------------------------------------------------------------- 00191 // Override the member functions from RigidBodyBase 00192 00197 virtual void SetBVOfType ( Enum::CD type ); 00198 00199 // Data Members ----------------------------------------------------------- 00200 //============================================================================= 00201 protected: 00202 // Member Functions ------------------------------------------------------- 00204 inline void StepSimulation ( T dt ); 00205 // Data Members ----------------------------------------------------------- 00206 //PhysicsSupport<T> m_PhysicsSupport; //!< Physics support 00207 InteractionPointGroup<T> m_IPGroup; 00208 bool m_bPositionLocked; 00209 //============================================================================= 00210 private: 00211 // Member Functions ------------------------------------------------------- 00213 bool CreateInteractionPointGroupBasedOnBVHTree_Recursive ( 00214 BVHNode<T> ** node, 00215 int numOfNodes, 00216 int currentLevel, 00217 int finalLevel 00218 ); 00219 // Data Members ----------------------------------------------------------- 00220 //============================================================================= 00221 00222 00223 #if defined(__gl_h_) || defined(__GL_H__) 00224 public: 00226 virtual void Draw () const; 00227 00229 virtual void DrawCenterOfMass () const; 00230 00232 virtual void DrawInteractionPointGroup () const; 00233 00235 virtual void DrawForDebugging () const; 00236 00237 #endif 00238 00239 00240 //============================================================================= 00241 }; // END CLASS RigidBodyDynamics 00242 //============================================================================= 00243 //----------------------------------------------------------------------------- 00245 typedef RigidBodyDynamics<int> RigidBodyDynamicsi; 00246 typedef RigidBodyDynamics<float> RigidBodyDynamicsf; 00247 typedef RigidBodyDynamics<double> RigidBodyDynamicsd; 00248 //============================================================================= 00249 END_NAMESPACE_TAPs 00250 //----------------------------------------------------------------------------- 00252 #include "TAPsRigidBodyDynamics.cpp" 00253 00255 // Include definition if TAPs_USE_EXPORT is not defined 00256 //#if !defined( TAPs_USE_EXPORT ) 00257 // #include "TAPsRigidBodyDynamics.cpp" 00258 //#endif 00259 //----------------------------------------------------------------------------- 00260 #endif 00261 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00262 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----