From e73c988b81fd14e178f35fb9ae6e8a1becd208bf Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Fri, 21 Feb 2014 09:54:32 +0100 Subject: [PATCH] Added ability to get previous velocity for rigid bodies --- .../Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 5 +++-- .../Physics/GamePhysics/Implementation/SimpleRigidBody.cpp | 5 +++++ Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h | 3 +++ Code/Physics/GamePhysics/PhysicsStructs-Impl.h | 4 +++- Code/Physics/GamePhysics/PhysicsStructs.h | 7 ++++--- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index df66bc12..631f8645 100644 --- a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -287,7 +287,8 @@ void API_Impl::UpdateWorld() if(simpleBody->GetRigidBody()->getActivationState() == ACTIVE_TAG) { this->customBodies[i]->CallSubscription_Move(); - } + } + simpleBody->SetPreviousVelocity(simpleBody->GetState().previousVelocity); } this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep); @@ -312,7 +313,7 @@ void API_Impl::UpdateWorld() ICustomBody* bodyA = (ICustomBody*)obA->getUserPointer(); ICustomBody* bodyB = (ICustomBody*)obB->getUserPointer(); - + bodyA->CallSubscription_AfterCollisionResponse(bodyA, bodyB, 0.0f); bodyB->CallSubscription_AfterCollisionResponse(bodyB, bodyA, 0.0f); } diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp index e2d87ce7..fe76ade7 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -422,4 +422,9 @@ void SimpleRigidBody::MoveToLimbo() void SimpleRigidBody::ReleaseFromLimbo() { this->rigidBody->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT); +} + +void SimpleRigidBody::SetPreviousVelocity(::Oyster::Math::Float3 velocity) +{ + this->state.previousVelocity = velocity; } \ No newline at end of file diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h index 4290b540..4d1ec3ce 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h @@ -64,6 +64,7 @@ namespace Oyster void SetCollisionShape(btCollisionShape* shape); void SetMotionState(btDefaultMotionState* motionState); void SetRigidBody(btRigidBody* rigidBody); + void SetPreviousVelocity(Math::Float3 velocity); void PreStep(const btCollisionWorld* collisionWorld); @@ -72,6 +73,8 @@ namespace Oyster void MoveToLimbo(); void ReleaseFromLimbo(); + + private: btCollisionShape* collisionShape; diff --git a/Code/Physics/GamePhysics/PhysicsStructs-Impl.h b/Code/Physics/GamePhysics/PhysicsStructs-Impl.h index 87cfcb17..56d5c4e8 100644 --- a/Code/Physics/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/Physics/GamePhysics/PhysicsStructs-Impl.h @@ -10,7 +10,7 @@ namespace Oyster { 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 ¢erPos, 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 ¢erPos, const ::Oyster::Math::Quaternion& quaternion, ::Oyster::Math::Float3 previousVelocity) { this->mass = mass; this->reach = reach; @@ -19,6 +19,7 @@ namespace Oyster this->dynamicFrictionCoeff = dynamicFrictionCoeff; this->centerPos = centerPos; this->quaternion = quaternion; + this->previousVelocity = ::Oyster::Math::Float3::null; } inline CustomBodyState & CustomBodyState::operator = ( const CustomBodyState &state ) @@ -30,6 +31,7 @@ namespace Oyster this->dynamicFrictionCoeff = state.dynamicFrictionCoeff; this->centerPos = state.centerPos; this->quaternion = state.quaternion; + this->previousVelocity = state.previousVelocity; return *this; } diff --git a/Code/Physics/GamePhysics/PhysicsStructs.h b/Code/Physics/GamePhysics/PhysicsStructs.h index 2f369b90..2ee7a59e 100644 --- a/Code/Physics/GamePhysics/PhysicsStructs.h +++ b/Code/Physics/GamePhysics/PhysicsStructs.h @@ -16,12 +16,13 @@ namespace Oyster public: // Default constructor 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 staticFrictionCoeff = 1.0f, ::Oyster::Math::Float dynamicFrictionCoeff = 1.0f, const ::Oyster::Math::Float3 ¢erPos = ::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 CustomBodyState & operator = ( const CustomBodyState &state ); @@ -34,7 +35,7 @@ namespace Oyster // Variables for state ::Oyster::Math::Float mass, restitutionCoeff, staticFrictionCoeff, dynamicFrictionCoeff; - ::Oyster::Math::Float3 reach, centerPos; + ::Oyster::Math::Float3 reach, centerPos, previousVelocity; ::Oyster::Math::Quaternion quaternion; }; }