![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsPhysicsSupport.hpp 00003 ******************************************************************************/ 00009 /****************************************************************************** 00010 SUKITTI PUNAK (04/25/2005) 00011 UPDATE (12/03/2010) 00012 ******************************************************************************/ 00013 #ifndef TAPs_PHYSICS_SUPPORT_HPP 00014 #define TAPs_PHYSICS_SUPPORT_HPP 00015 00016 #include "../Core/TAPsLib.hpp" 00017 //#include "../Math/TAPsListOfODESolvers.hpp" // For ODE Solvers 00018 00019 BEGIN_NAMESPACE_TAPs 00020 //============================================================================= 00021 template <typename T> 00022 class PhysicsSupport { 00023 00024 // Friend Function 00025 friend std::ostream & operator<< ( std::ostream &output, PhysicsSupport<T> const &P ) 00026 { 00027 return output << P.StrInfo(); 00028 } 00029 00030 // Member Functions ----------------------------------------------------------- 00031 public: 00032 00034 PhysicsSupport (); 00035 00037 PhysicsSupport ( const PhysicsSupport<T> & orig ); 00038 00040 virtual ~PhysicsSupport (); 00041 00043 virtual std::string StrInfo () const; 00044 00046 inline PhysicsSupport<T> & operator= ( PhysicsSupport<T> const & orig ); 00047 00048 //========================================================================= 00049 // Get/Set Fns for (Dynamics) Physical Properties 00050 //------------------------------------------------------------------------- 00051 00053 virtual T GetPhyPropElasticity () const { return mPhyProp_tElasticity; } 00055 virtual void SetPhyPropElasticity ( T elasticValue ) { mPhyProp_tElasticity = elasticValue; } 00056 00058 virtual T GetPhyPropMass () const { return mPhyProp_tMass; } 00060 virtual void SetPhyPropMass ( T massValue ) { mPhyProp_tMass = massValue; } 00061 00063 virtual T GetPhyPropVolume () const { return mPhyProp_tVolume; } 00065 virtual void SetPhyPropVolume ( T volumeValue ) { mPhyProp_tVolume = volumeValue; } 00066 00068 virtual Vector3<T> const & GetPhyPropCenterOfMass () const { return mPhyProp_vCenterOfMass; } 00070 virtual void SetPhyPropCenterOfMass ( Vector3<T> const & COM ) { mPhyProp_vCenterOfMass = COM; } 00072 virtual void SetPhyPropCenterOfMass ( T x, T y, T z ) { mPhyProp_vCenterOfMass.SetXYZ(x,y,z); } 00073 00075 virtual Quaternion<T> const & GetPhyPropOrientation () const { return mPhyProp_qOrientation; } 00077 virtual void SetPhyPropOrientation ( Quaternion<T> const & orientation ) { mPhyProp_qOrientation = orientation; } 00079 virtual void SetPhyPropOrientation ( T r, T i, T j, T k ) { mPhyProp_qOrientation.SetRIJK(r,i,j,k); } 00080 00082 virtual Matrix3x3<T> const & GetPhyPropMomentOfInertiaTensor () const { return mPhyProp_mMomentOfInertiaTensor; } 00084 virtual T GetPhyPropMomentOfInertiaTensor ( int row, int col ) const { return mPhyProp_mMomentOfInertiaTensor(row,col); } 00086 virtual void SetPhyPropMomentOfInertiaTensor ( int row, int col, T value ) { mPhyProp_mMomentOfInertiaTensor(row,col) = value; } 00088 virtual void SetPhyPropMomentOfInertiaTensor ( Matrix3x3<T> const & MOI ) { mPhyProp_mMomentOfInertiaTensor = MOI; } 00089 00091 virtual Matrix3x3<T> const & GetPhyPropInvMomentOfInertiaTensor () const { return mPhyProp_mInvMomentOfInertiaTensor; } 00093 virtual T GetPhyPropInvMomentOfInertiaTensor ( int row, int col ) const { return mPhyProp_mInvMomentOfInertiaTensor(row,col); } 00095 virtual void SetPhyPropInvMomentOfInertiaTensor ( int row, int col, T value ) { mPhyProp_mInvMomentOfInertiaTensor(row,col) = value; } 00097 virtual void SetPhyPropInvMomentOfInertiaTensor ( Matrix3x3<T> const & InvMOI ) { mPhyProp_mInvMomentOfInertiaTensor = InvMOI; } 00098 00100 //const Vector3<T> & GetPhyPropLinearMomentum () const { return mPhyProp_vLinearMomentum; } 00102 //void SetPhyPropLinearMomentum ( Vector3<T> const & linearMomentum ) { mPhyProp_vLinearMomentum = linearMomentum; } 00104 //void SetPhyPropLinearMomentum ( T x, T y, T z ) { mPhyProp_vLinearMomentum.SetXYZ(x,y,z); } 00105 00107 //Vector3<T> const & GetPhyPropAngularMomentum () const { return mPhyProp_vAngularMomentum; } 00109 //void SetPhyPropAngularMomentum ( Vector3<T> const & angularMomentum ) { mPhyProp_vAngularMomentum = angularMomentum; } 00111 //void SetPhyPropAngularMomentum ( T x, T y, T z ) { mPhyProp_vAngularMomentum.SetXYZ(x,y,z); } 00112 00114 virtual Vector3<T> const & GetPhyPropLinearVelocity () const { return mPhyProp_vLinearVelocity; } 00116 virtual void SetPhyPropLinearVelocity ( Vector3<T> const & linearVelocity ) { mPhyProp_vLinearVelocity = linearVelocity; } 00118 virtual void SetPhyPropLinearVelocity ( T x, T y, T z ) { mPhyProp_vLinearVelocity.SetXYZ(x,y,z); } 00119 00121 virtual Vector3<T> const & GetPhyPropAngularVelocity () const { return mPhyProp_vAngularVelocity; } 00123 virtual void SetPhyPropAngularVelocity ( Vector3<T> const & angularVelocity ) { mPhyProp_vAngularVelocity = angularVelocity; } 00125 virtual void SetPhyPropAngularVelocity ( T x, T y, T z ) { mPhyProp_vAngularVelocity.SetXYZ(x,y,z); } 00126 00128 virtual Vector3<T> const & GetPhyPropLinearAcceleration () const { return mPhyProp_vLinearAcceleration; } 00130 virtual void SetPhyPropLinearAcceleration ( Vector3<T> const & linearAcceleration ) { mPhyProp_vLinearAcceleration = linearAcceleration; } 00132 virtual void SetPhyPropLinearAcceleration ( T x, T y, T z ) { mPhyProp_vLinearAcceleration.SetXYZ(x,y,z); } 00133 00135 virtual Vector3<T> const & GetPhyPropAngularAcceleration () const { return mPhyProp_vAngularAcceleration; } 00137 virtual void SetPhyPropAngularAcceleration ( Vector3<T> const & angularAcceleration ) { mPhyProp_vAngularAcceleration = angularAcceleration; } 00139 virtual void SetPhyPropAngularAcceleration ( T x, T y, T z) { mPhyProp_vAngularAcceleration.SetXYZ(x,y,z); } 00140 00142 virtual Vector3<T> const & GetPhyPropTotalForce () const { return mPhyProp_vTotalForce; } 00144 virtual void SetPhyPropTotalForce ( Vector3<T> const & totalForce ) { mPhyProp_vTotalForce = totalForce; } 00146 virtual void SetPhyPropTotalForce ( T x, T y, T z ) { mPhyProp_vTotalForce.SetXYZ(x,y,z); } 00147 00149 virtual Vector3<T> const & GetPhyPropTotalTorque () const { return mPhyProp_vTotalTorque; } 00151 virtual void SetPhyPropTotalTorque ( Vector3<T> const & totalTorque ) { mPhyProp_vTotalTorque = totalTorque; } 00153 virtual void SetPhyPropTotalTorque ( T x, T y, T z ) { mPhyProp_vTotalTorque.SetXYZ( x, y, z ); } 00154 00156 virtual Vector3<T> const & GetPhyPropDampingLinearVelocity () const { return mPhyProp_vDampingLinearVelocity; } 00158 virtual void SetPhyPropDampingLinearVelocity ( Vector3<T> const & dampingLinearVelocity ) { mPhyProp_vDampingLinearVelocity = dampingLinearVelocity; } 00160 virtual void SetPhyPropDampingLinearVelocity ( T x, T y, T z ) { mPhyProp_vDampingLinearVelocity.SetXYZ(x,y,z); } 00161 00163 virtual Vector3<T> const & GetPhyPropDampingAngularVelocity () const { return mPhyProp_vDampingAngularVelocity; } 00165 virtual void SetPhyPropDampingAngularVelocity ( Vector3<T> const & dampingAngularVelocity ) { mPhyProp_vDampingAngularVelocity = dampingAngularVelocity; } 00167 virtual void SetPhyPropDampingAngularVelocity ( T x, T y, T z ) { mPhyProp_vDampingAngularVelocity.SetXYZ(x,y,z); } 00168 00170 virtual T GetPhyPropGravitationalConstant () const { return mPhyProp_tGravitationalConstant; } 00172 virtual void SetPhyPropGravitationalConstant ( T g ) { mPhyProp_tGravitationalConstant = g; } 00173 #ifdef TAPs_ADD_RESTING_LEVEL_Y 00174 00175 virtual T GetPhyPropRestingLevel () const { return mPhyProp_tRestingLevel; } 00177 virtual void SetPhyPropRestingLevel ( T y ) { mPhyProp_tRestingLevel = y; } 00178 #endif//TAPs_ADD_RESTING_LEVEL_Y 00179 00180 //------------------------------------------------------------------------- 00181 // Get/Set Fns for (Dynamics) Physical Properties 00182 //========================================================================= 00183 00184 00185 //========================================================================= 00186 // Update Physical Properties_ 00187 //------------------------------------------------------------------------- 00188 00190 void ClearForce () { mPhyProp_vTotalForce.Clear(); } 00192 void ClearTorque () { mPhyProp_vTotalTorque.Clear(); } 00194 void ClearForceAndTorque () { mPhyProp_vTotalForce.Clear(); mPhyProp_vTotalTorque.Clear(); } 00196 void ClearLinearVelocity () { mPhyProp_vLinearVelocity.Clear(); } 00198 void ClearAngularVelocity () { mPhyProp_vAngularVelocity.Clear(); } 00200 void ClearLinearAcceleration () { mPhyProp_vLinearAcceleration.Clear(); } 00202 void ClearAngularAcceleration () { mPhyProp_vAngularAcceleration.Clear(); } 00203 00205 inline virtual void AddForce ( Vector3<T> const & Force ); 00206 00208 inline virtual void AddTorque ( Vector3<T> const & Torque ); 00209 00211 inline virtual void ScaleForce ( Vector3<T> const & Scale ); 00212 00214 inline virtual void ScaleTorque ( Vector3<T> const & Scale ); 00215 00219 inline virtual void AddForceWithLocation ( 00220 Vector3<T> const & Force, 00221 Vector3<T> const & AppliedLocation 00222 ); 00223 00224 //------------------------------------------------------------------------- 00225 // Update Physical Properties 00226 //========================================================================= 00227 00228 00229 //------------------------------------------------------------------------- 00230 protected: 00231 /* 00232 //------------------------------------------------------------------------- 00233 // REMARK: DxDt has to be static so that we can pass it to 00234 // ODESolver Fn. 00235 // But we don't want StateToArray and ArrayToState be static. 00236 // Therefore, we need to pass userData, i.e. this pointer 00237 // as a void pointer. 00238 static bool DxDt ( 00239 T dt, // i/p: time step 00240 Simulation::VectorSet<T> &x, // i/p: array x = {pos, vel} 00241 Simulation::VectorSet<T> &xdot, // o/p: array xdot = {vel, accel} 00242 void *userData // o/p: array of user data 00243 ); 00244 //------------------------------------------------------------------------- 00245 void StateToArray ( T *dst ); // copy Strand states to dst array 00246 void ArrayToState ( T *src ); // copy src array to Strand states 00247 void DdtStateToArray ( T *xdot, T dt ); // copy d/dt Strand states to dst 00248 // (xdot) array 00249 //void ClearForces (); // clear (all) forces (and maybe velocities too) 00250 //*/ 00251 //----------------------------------------------------------------------------- 00252 // Data Members -------------------------------------------------------------- 00253 /* 00254 //========================================================================= 00255 // For simulation 00256 //------------------------------------------------------------------------- 00257 Simulation::ODESolver<T> * m_prODESolver; // ODE solver 00258 Simulation::VectorSet<T> x0; // #m_iStateSize 00259 Simulation::VectorSet<T> xEnd; // #m_iStateSize 00260 int m_iStateSize; // #particles (or #primitives) * 6 00261 // where 6 = 3 positions + 3 velocities (for x,y,z) 00262 int m_iLimitStepCount; 00263 //*/ 00264 //------------------------------------------------------------------------- 00265 // (Dynamics) Physics Properties 00266 T mPhyProp_tElasticity; 00267 T mPhyProp_tMass; 00268 T mPhyProp_tVolume; 00269 Vector3<T> mPhyProp_vCenterOfMass; 00270 Quaternion<T> mPhyProp_qOrientation; 00271 00272 Matrix3x3<T> mPhyProp_mMomentOfInertiaTensor; 00273 Matrix3x3<T> mPhyProp_mInvMomentOfInertiaTensor; 00274 00275 //Vector3<T> mPhyProp_vLinearMomentum; //!< linear momentum 00276 //Vector3<T> mPhyProp_vAngularMomentum; //!< angular momentum 00277 Vector3<T> mPhyProp_vLinearVelocity; 00278 Vector3<T> mPhyProp_vAngularVelocity; 00279 Vector3<T> mPhyProp_vLinearAcceleration; 00280 Vector3<T> mPhyProp_vAngularAcceleration; 00281 00282 Vector3<T> mPhyProp_vTotalForce; 00283 Vector3<T> mPhyProp_vTotalTorque; 00284 00285 Vector3<T> mPhyProp_vDampingLinearVelocity; 00286 Vector3<T> mPhyProp_vDampingAngularVelocity; 00287 00288 T mPhyProp_tGravitationalConstant; 00289 #ifdef TAPs_ADD_RESTING_LEVEL_Y 00290 T mPhyProp_tRestingLevel; 00291 #endif//TAPs_ADD_RESTING_LEVEL_Y 00292 }; 00293 //============================================================================= 00294 END_NAMESPACE_TAPs 00295 //----------------------------------------------------------------------------- 00296 // Include definition if TAPs_USE_EXPORT is not defined 00297 //#if !defined( TAPs_USE_EXPORT ) 00298 #include "TAPsPhysicsSupport.cpp" 00299 //#endif 00300 //----------------------------------------------------------------------------- 00301 #endif 00302 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00303 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----