Added ability to get previous velocity for rigid bodies

This commit is contained in:
Robin Engman 2014-02-21 09:54:32 +01:00
parent 3bee35785a
commit e73c988b81
5 changed files with 18 additions and 6 deletions

View File

@ -288,6 +288,7 @@ void API_Impl::UpdateWorld()
{ {
this->customBodies[i]->CallSubscription_Move(); this->customBodies[i]->CallSubscription_Move();
} }
simpleBody->SetPreviousVelocity(simpleBody->GetState().previousVelocity);
} }
this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep); this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep);

View File

@ -423,3 +423,8 @@ void SimpleRigidBody::ReleaseFromLimbo()
{ {
this->rigidBody->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT); this->rigidBody->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
} }
void SimpleRigidBody::SetPreviousVelocity(::Oyster::Math::Float3 velocity)
{
this->state.previousVelocity = velocity;
}

View File

@ -64,6 +64,7 @@ namespace Oyster
void SetCollisionShape(btCollisionShape* shape); void SetCollisionShape(btCollisionShape* shape);
void SetMotionState(btDefaultMotionState* motionState); void SetMotionState(btDefaultMotionState* motionState);
void SetRigidBody(btRigidBody* rigidBody); void SetRigidBody(btRigidBody* rigidBody);
void SetPreviousVelocity(Math::Float3 velocity);
void PreStep(const btCollisionWorld* collisionWorld); void PreStep(const btCollisionWorld* collisionWorld);
@ -72,6 +73,8 @@ namespace Oyster
void MoveToLimbo(); void MoveToLimbo();
void ReleaseFromLimbo(); void ReleaseFromLimbo();
private: private:
btCollisionShape* collisionShape; btCollisionShape* collisionShape;

View File

@ -10,7 +10,7 @@ namespace Oyster
{ {
namespace Struct namespace Struct
{ {
inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float3 reach, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float dynamicFrictionCoeff, const ::Oyster::Math::Float3 &centerPos, const ::Oyster::Math::Quaternion& quaternion) inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float3 reach, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float dynamicFrictionCoeff, const ::Oyster::Math::Float3 &centerPos, const ::Oyster::Math::Quaternion& quaternion, ::Oyster::Math::Float3 previousVelocity)
{ {
this->mass = mass; this->mass = mass;
this->reach = reach; this->reach = reach;
@ -19,6 +19,7 @@ namespace Oyster
this->dynamicFrictionCoeff = dynamicFrictionCoeff; this->dynamicFrictionCoeff = dynamicFrictionCoeff;
this->centerPos = centerPos; this->centerPos = centerPos;
this->quaternion = quaternion; this->quaternion = quaternion;
this->previousVelocity = ::Oyster::Math::Float3::null;
} }
inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state ) inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state )
@ -30,6 +31,7 @@ namespace Oyster
this->dynamicFrictionCoeff = state.dynamicFrictionCoeff; this->dynamicFrictionCoeff = state.dynamicFrictionCoeff;
this->centerPos = state.centerPos; this->centerPos = state.centerPos;
this->quaternion = state.quaternion; this->quaternion = state.quaternion;
this->previousVelocity = state.previousVelocity;
return *this; return *this;
} }

View File

@ -16,12 +16,13 @@ namespace Oyster
public: public:
// Default constructor // Default constructor
CustomBodyState( ::Oyster::Math::Float mass = 1.0f, CustomBodyState( ::Oyster::Math::Float mass = 1.0f,
::Oyster::Math::Float3 reach = ::Oyster::Math::Float3(0,0,0), ::Oyster::Math::Float3 reach = ::Oyster::Math::Float3::null,
::Oyster::Math::Float restitutionCoeff = 0.5f, ::Oyster::Math::Float restitutionCoeff = 0.5f,
::Oyster::Math::Float staticFrictionCoeff = 1.0f, ::Oyster::Math::Float staticFrictionCoeff = 1.0f,
::Oyster::Math::Float dynamicFrictionCoeff = 1.0f, ::Oyster::Math::Float dynamicFrictionCoeff = 1.0f,
const ::Oyster::Math::Float3 &centerPos = ::Oyster::Math::Float3::null, const ::Oyster::Math::Float3 &centerPos = ::Oyster::Math::Float3::null,
const ::Oyster::Math::Quaternion &quaternion = ::Oyster::Math::Quaternion(::Oyster::Math::Float3(0, 0, 0), 1)); const ::Oyster::Math::Quaternion &quaternion = ::Oyster::Math::Quaternion(::Oyster::Math::Float3(0, 0, 0), 1),
::Oyster::Math::Float3 previousVelocity = ::Oyster::Math::Float3::null);
// Assignment operator // Assignment operator
CustomBodyState & operator = ( const CustomBodyState &state ); CustomBodyState & operator = ( const CustomBodyState &state );
@ -34,7 +35,7 @@ namespace Oyster
// Variables for state // Variables for state
::Oyster::Math::Float mass, restitutionCoeff, staticFrictionCoeff, dynamicFrictionCoeff; ::Oyster::Math::Float mass, restitutionCoeff, staticFrictionCoeff, dynamicFrictionCoeff;
::Oyster::Math::Float3 reach, centerPos; ::Oyster::Math::Float3 reach, centerPos, previousVelocity;
::Oyster::Math::Quaternion quaternion; ::Oyster::Math::Quaternion quaternion;
}; };
} }