![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsPhysicsSupport.cpp 00003 ******************************************************************************/ 00008 /****************************************************************************** 00009 SUKITTI PUNAK (04/25/2005) 00010 UPDATE (12/03/2010) 00011 ******************************************************************************/ 00012 #include "TAPsPhysicsSupport.hpp" 00013 // Using Inclusion Model (i.e. definitions are included in declarations) 00014 // (this name.cpp is included in name.hpp) 00015 // Each friend is defined directly inside its declaration. 00016 00017 BEGIN_NAMESPACE_TAPs 00018 //============================================================================= 00019 //----------------------------------------------------------------------------- 00020 template <typename T> 00021 PhysicsSupport<T>::PhysicsSupport () 00022 : mPhyProp_tElasticity( 1 ) 00023 , mPhyProp_tMass( 1 ) 00024 , mPhyProp_tVolume( 1 ) 00025 , mPhyProp_vDampingLinearVelocity( 0.01, 0.01, 0.01 ) 00026 , mPhyProp_vDampingAngularVelocity( 0.01, 0.01, 0.01 ) 00027 , mPhyProp_tGravitationalConstant( 9.81 ) 00028 #ifdef TAPs_ADD_RESTING_LEVEL_Y 00029 , mPhyProp_tRestingLevel( 0 ) 00030 #endif//TAPs_ADD_RESTING_LEVEL_Y 00031 { 00032 #ifdef TAPs_DEBUG_MODE 00033 std::cout << "PhysicsSupport<" << typeid(T).name() << "> default constructor\n"; 00034 #endif//TAPs_DEBUG_MODE 00035 } 00036 //----------------------------------------------------------------------------- 00037 template <typename T> 00038 PhysicsSupport<T>::PhysicsSupport ( const PhysicsSupport<T> & orig ) 00039 : mPhyProp_tElasticity( orig.mPhyProp_tElasticity ) 00040 , mPhyProp_tMass( orig.mPhyProp_tMass ) 00041 , mPhyProp_tVolume( orig.mPhyProp_tVolume ) 00042 , mPhyProp_vCenterOfMass( orig.mPhyProp_vCenterOfMass ) 00043 , mPhyProp_qOrientation( orig.mPhyProp_qOrientation ) 00044 00045 , mPhyProp_mMomentOfInertiaTensor( orig.mPhyProp_mMomentOfInertiaTensor ) 00046 , mPhyProp_mInvMomentOfInertiaTensor( orig.mPhyProp_mInvMomentOfInertiaTensor ) 00047 00048 //, mPhyProp_vLinearMomentum( orig.mPhyProp_vLinearMomentum ) 00049 //, mPhyProp_vAngularMomentum( orig.mPhyProp_vAngularMomentum ) 00050 , mPhyProp_vLinearVelocity( orig.mPhyProp_vLinearVelocity ) 00051 , mPhyProp_vAngularVelocity( orig.mPhyProp_vAngularVelocity ) 00052 , mPhyProp_vLinearAcceleration( orig.mPhyProp_vLinearAcceleration ) 00053 , mPhyProp_vAngularAcceleration( orig.mPhyProp_vAngularAcceleration ) 00054 00055 , mPhyProp_vTotalForce( orig.mPhyProp_vTotalForce ) 00056 , mPhyProp_vTotalTorque( orig.mPhyProp_vTotalTorque ) 00057 00058 , mPhyProp_vDampingLinearVelocity( orig.mPhyProp_vDampingLinearVelocity ) 00059 , mPhyProp_vDampingAngularVelocity( orig.mPhyProp_vDampingAngularVelocity ) 00060 00061 , mPhyProp_tGravitationalConstant( orig.mPhyProp_tGravitationalConstant ) 00062 { 00063 #ifdef TAPs_DEBUG_MODE 00064 std::cout << "PhysicsSupport<" << typeid(T).name() << "> copy constructor\n"; 00065 #endif//TAPs_DEBUG_MODE 00066 } 00067 //----------------------------------------------------------------------------- 00068 // Destructor 00069 template <typename T> 00070 PhysicsSupport<T>::~PhysicsSupport () 00071 { 00072 #ifdef TAPs_DEBUG_MODE 00073 std::cout << "PhysicsSupport<" << typeid(T).name() << "> destructor\n"; 00074 #endif//TAPs_DEBUG_MODE 00075 } 00076 //----------------------------------------------------------------------------- 00077 template <typename T> 00078 std::string PhysicsSupport<T>::StrInfo () const 00079 { 00080 std::stringstream ss; 00081 ss << "PhysicsSupport<" << typeid(T).name() << "> ==> " 00082 << "\n Elasticity " << GetPhyPropElasticity() 00083 << "\n Mass: " << GetPhyPropMass() 00084 << "\n Volume: " << GetPhyPropVolume() 00085 << "\n Center of mass " << GetPhyPropCenterOfMass() 00086 << "\n Gravitational constant " << GetPhyPropGravitationalConstant() 00087 << "\n Orientation " << GetPhyPropOrientation() 00088 //<< "\n LinearMomentum " << GetPhyPropLinearMomentum() 00089 //<< "\n AngularMomentum " << GetPhyPropAngularMomentum() 00090 << "\n Linear Velocity " << GetPhyPropLinearVelocity() 00091 << "\n Linear Velocity Damping " << GetPhyPropDampingLinearVelocity() 00092 << "\n Angular Velocity " << GetPhyPropAngularVelocity() 00093 << "\n Angular Velocity Damping " << GetPhyPropDampingAngularVelocity() 00094 << "\n Linear Acceleration " << GetPhyPropLinearAcceleration() 00095 << "\n Angular Acceleration " << GetPhyPropAngularAcceleration() 00096 << "\n Total Force " << GetPhyPropTotalForce() 00097 << "\n Total Torque " << GetPhyPropTotalTorque() 00098 << "\n Moment of Inertia " << GetPhyPropMomentOfInertiaTensor() 00099 << "\n Inverse of Moment of Inertia " << GetPhyPropInvMomentOfInertiaTensor() 00100 << "\n"; 00101 return ss.str(); 00102 } 00103 //----------------------------------------------------------------------------- 00104 // Assignment Operator 00105 template <typename T> 00106 PhysicsSupport<T> & PhysicsSupport<T>::operator= ( PhysicsSupport<T> const & orig ) 00107 { 00108 mPhyProp_tElasticity = orig.mPhyProp_tElasticity; 00109 mPhyProp_tMass = orig.mPhyProp_tMass; 00110 mPhyProp_tVolume = orig.mPhyProp_tVolume; 00111 mPhyProp_vCenterOfMass = orig.mPhyProp_vCenterOfMass; 00112 mPhyProp_qOrientation = orig.mPhyProp_qOrientation; 00113 00114 mPhyProp_mMomentOfInertiaTensor = orig.mPhyProp_mMomentOfInertiaTensor; 00115 mPhyProp_mInvMomentOfInertiaTensor = orig.mPhyProp_mInvMomentOfInertiaTensor; 00116 00117 //mPhyProp_vLinearMomentum = orig.mPhyProp_vLinearMomentum; 00118 //mPhyProp_vAngularMomentum = orig.mPhyProp_vAngularMomentum; 00119 mPhyProp_vLinearVelocity = orig.mPhyProp_vLinearVelocity; 00120 mPhyProp_vAngularVelocity = orig.mPhyProp_vAngularVelocity; 00121 mPhyProp_vLinearAcceleration = orig.mPhyProp_vLinearAcceleration; 00122 mPhyProp_vAngularAcceleration = orig.mPhyProp_vAngularAcceleration; 00123 00124 mPhyProp_vTotalForce = orig.mPhyProp_vTotalForce; 00125 mPhyProp_vTotalTorque = orig.mPhyProp_vTotalTorque; 00126 00127 mPhyProp_vDampingLinearVelocity = orig.mPhyProp_vDampingLinearVelocity; 00128 mPhyProp_vDampingAngularVelocity = orig.mPhyProp_vDampingAngularVelocity; 00129 00130 mPhyProp_tGravitationalConstant = orig.mPhyProp_tGravitationalConstant; 00131 #ifdef TAPs_ADD_RESTING_LEVEL_Y 00132 mPhyProp_tRestingLevel = orig.mPhyProp_tRestingLevel; 00133 #endif//TAPs_ADD_RESTING_LEVEL_Y 00134 00135 return *this; 00136 } 00137 //----------------------------------------------------------------------------- 00138 //============================================================================= 00139 00140 00141 00142 00143 //============================================================================= 00144 // Update Physical Properties 00145 //----------------------------------------------------------------------------- 00146 template <typename T> 00147 void PhysicsSupport<T>::AddForce ( Vector3<T> const & Force ) 00148 { 00149 mPhyProp_vTotalForce += Force; 00150 } 00151 //----------------------------------------------------------------------------- 00152 template <typename T> 00153 void PhysicsSupport<T>::AddTorque ( Vector3<T> const & Torque ) 00154 { 00155 mPhyProp_vTotalTorque += Torque; 00156 } 00157 //----------------------------------------------------------------------------- 00158 template <typename T> 00159 void PhysicsSupport<T>::ScaleForce ( Vector3<T> const & Scale ) 00160 { 00161 mPhyProp_vTotalForce[0] *= Scale[0]; 00162 mPhyProp_vTotalForce[1] *= Scale[1]; 00163 mPhyProp_vTotalForce[2] *= Scale[2]; 00164 } 00165 //----------------------------------------------------------------------------- 00166 template <typename T> 00167 void PhysicsSupport<T>::ScaleTorque ( Vector3<T> const & Scale ) 00168 { 00169 mPhyProp_vTotalTorque[0] *= Scale[0]; 00170 mPhyProp_vTotalTorque[1] *= Scale[1]; 00171 mPhyProp_vTotalTorque[2] *= Scale[2]; 00172 } 00173 //----------------------------------------------------------------------------- 00174 template <typename T> 00175 void PhysicsSupport<T>::AddForceWithLocation ( 00176 Vector3<T> const & Force, 00177 Vector3<T> const & AppliedLocation 00178 ) 00179 { 00180 AddForce( Force ); 00181 AddTorque( AppliedLocation ^ Force ); 00182 } 00183 //----------------------------------------------------------------------------- 00184 // Update Physical Properties 00185 //============================================================================= 00186 00187 00188 END_NAMESPACE_TAPs 00189 //----------------------------------------------------------------------------- 00190 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00191 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----