00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __NERIGIDBODY_H
00028 #define __NERIGIDBODY_H
00029
00030
00037 #include "base.h"
00038 #include "massparticle.h"
00039
00040 #include <vector>
00041
00042
00043 namespace NeoEngine
00044 {
00045
00046
00051 class NEOENGINE_API RigidBodyState
00052 {
00053 public:
00054
00056 Matrix m_kInvBodyInertiaTensor;
00057
00059 Matrix m_kInvInertiaTensor;
00060
00062 Vector3d m_kAngularVelocity;
00063
00065 Vector3d m_kTorque;
00066
00068 Matrix m_kRotation;
00069
00072 RigidBodyState() {}
00073
00081 RigidBodyState( const Matrix &rkInvBodyInertiaTensor, const Matrix &rkInvInertiaTensor, const Vector3d &rkAngularVelocity, const Vector3d &rkTorque, const Matrix &rkRotation ) : m_kInvBodyInertiaTensor( rkInvBodyInertiaTensor ), m_kInvInertiaTensor( rkInvInertiaTensor ), m_kAngularVelocity( rkAngularVelocity ), m_kTorque( rkTorque ), m_kRotation( rkRotation ) {}
00082
00086 RigidBodyState( const RigidBodyState &rkState ) : m_kInvBodyInertiaTensor( rkState.m_kInvBodyInertiaTensor ), m_kInvInertiaTensor( rkState.m_kInvInertiaTensor ), m_kAngularVelocity( rkState.m_kAngularVelocity ), m_kTorque( rkState.m_kTorque ), m_kRotation( rkState.m_kRotation ) {}
00087
00093 bool operator < ( const RigidBodyState &rkState ) const { return( false ); }
00094
00100 bool operator == ( const RigidBodyState &rkState ) const { return( ( m_kInvBodyInertiaTensor == rkState.m_kInvBodyInertiaTensor ) && ( m_kInvInertiaTensor == rkState.m_kInvInertiaTensor ) && ( m_kAngularVelocity == rkState.m_kAngularVelocity ) && ( m_kTorque == rkState.m_kTorque ) && ( m_kRotation == rkState.m_kRotation ) ); }
00101 };
00102
00103
00104 #ifdef WIN32
00105 # ifdef _MSC_VER
00106 # pragma warning( disable : 4231 )
00107 # endif
00108 # ifndef __HAVE_VECTOR_NERIGIDBODYSTATEOBJ
00109 UDTVectorEXPIMP( RigidBodyState );
00110 # define __HAVE_VECTOR_NERIGIDBODYSTATEOBJ
00111 # endif
00112 #endif
00113
00114
00120 class NEOENGINE_API RigidBody : public MassParticle
00121 {
00122 friend class PhysicsManager;
00123
00124 private:
00125
00127 std::vector< RigidBodyState > m_vkStateStack;
00128
00129
00130
00131 protected:
00132
00134 Vector3d m_kAngularVelocity;
00135
00137 Vector3d m_kTorque;
00138
00140 Matrix m_kInvBodyInertiaTensor;
00141
00143 Matrix m_kInvInertiaTensor;
00144
00146 Matrix m_kRotationMatrix;
00147
00149 float m_fRestitutionCoeff;
00150
00152 float m_fFrictionCoeff;
00153
00154
00155 public:
00156
00158 bool m_bManaged;
00159
00160
00163 RigidBody();
00164
00167 virtual ~RigidBody();
00168
00173 virtual SceneNode *Duplicate();
00174
00182 const Vector3d &ApplyForce( const Vector3d &rkForce, const Vector3d& rkPos, bool bLocal = false );
00183
00190 void ApplyImpulse( const Vector3d& rkImpulse, const Vector3d& rkPos, bool bLocal = false );
00191
00195 void ResetTorque();
00196
00200 inline void ResetForceAndTorque() { ResetForce(); ResetTorque(); }
00201
00206 virtual void Update( float fDeltaTime );
00207
00212 virtual void SetAngularVelocity( const Vector3d &rkVelocity );
00213
00220 Vector3d GetPointVelocity( const Vector3d &rkPoint, bool bLocal = false );
00221
00225 inline const Vector3d &GetAngularVelocity() const { return m_kAngularVelocity; }
00226
00232 void SetMassiveBlock( const Vector3d &rkDim, float fMass );
00233
00238 void SetInvBodyInertiaTensor( const Matrix &rkInvBodyInertiaTensor );
00239
00243 inline const Matrix &GetInvInertiaTensor() const { return m_kInvInertiaTensor; }
00244
00249 void SetRestitution( float fCoeff ) { m_fRestitutionCoeff = CLAMP< float >( fCoeff, 0.0f, 1.0f ); }
00250
00254 inline float GetRestitution() const { return m_fRestitutionCoeff; }
00255
00260 void SetFriction( float fCoeff ) { m_fFrictionCoeff = CLAMP< float >( fCoeff, 0.0f, 1.0f ); }
00261
00265 inline float GetFriction() const { return m_fFrictionCoeff; }
00266
00270 virtual void PushState();
00271
00276 virtual void PopState( bool bSet = true );
00277
00281 virtual void ClearState();
00282 };
00283
00284
00285 };
00286
00287
00288 #endif