Added on move functionality

This commit is contained in:
Robin Engman 2014-02-10 13:55:01 +01:00
parent e5e99924d9
commit 05aa3cc9e9
5 changed files with 72 additions and 42 deletions

View File

@ -71,7 +71,7 @@ Game::PlayerData* Game::CreatePlayer()
int i = InsertObject(this->players, (PlayerData*)0);
this->players[i] = new PlayerData();
//this->players[i]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove);
this->players[i]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove);
return this->players[i];
}

View File

@ -102,7 +102,7 @@ ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 r
void API_Impl::UpdateWorld()
{
this->dynamicsWorld->stepSimulation(1.0f/120.0f, 1.0f, 1.0f/120.0f);
this->dynamicsWorld->stepSimulation(1.0f/60.0f, 1.0f, 1.0f/60.0f);
ICustomBody::State state;
@ -115,6 +115,10 @@ void API_Impl::UpdateWorld()
state.centerPos = Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z());
state.quaternion = Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w());
if(dynamic_cast<SimpleRigidBody*>(this->customBodies[i])->GetRigidBody()->getActivationState() == ACTIVE_TAG)
{
dynamic_cast<SimpleRigidBody*>(this->customBodies[i])->CallSubscription_Move();
}
this->customBodies[i]->SetState(state);
}
@ -129,8 +133,8 @@ void API_Impl::UpdateWorld()
ICustomBody* bodyA = (ICustomBody*)obA->getUserPointer();
ICustomBody* bodyB = (ICustomBody*)obB->getUserPointer();
//dynamic_cast<SimpleRigidBody*>(bodyA)->CallSubsciptMessage(bodyA, bodyB, 0.0f);
//dynamic_cast<SimpleRigidBody*>(bodyB)->CallSubsciptMessage(bodyB, bodyA, 0.0f);
dynamic_cast<SimpleRigidBody*>(bodyA)->CallSubscription_AfterCollisionResponse(bodyA, bodyB, 0.0f);
dynamic_cast<SimpleRigidBody*>(bodyB)->CallSubscription_AfterCollisionResponse(bodyB, bodyA, 0.0f);
int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)

View File

@ -22,14 +22,8 @@ SimpleRigidBody::SimpleRigidBody()
this->state.restitutionCoeff = 0.0f;
this->state.reach = Float3(0.0f, 0.0f, 0.0f);
this->customTag = nullptr;
}
SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
{
this->collisionShape = NULL;
this->motionState = NULL;
this->rigidBody = NULL;
this->afterCollision = NULL;
this->onMovement = NULL;
this->customTag = nullptr;
}
@ -65,16 +59,38 @@ void SimpleRigidBody::SetSubscription(EventAction_AfterCollisionResponse functio
this->afterCollision = function;
}
void SimpleRigidBody::CallSubsciptMessage(ICustomBody* bodyA, ICustomBody* bodyB, Oyster::Math::Float kineticEnergyLoss)
void SimpleRigidBody::SetSubscription(EventAction_Move function)
{
this->onMovement = function;
}
void SimpleRigidBody::CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Oyster::Math::Float kineticEnergyLoss)
{
if(this->onMovement)
this->afterCollision(bodyA, bodyB, kineticEnergyLoss);
}
void SimpleRigidBody::CallSubscription_Move()
{
if(this->onMovement)
this->onMovement(this);
}
btCollisionShape* SimpleRigidBody::GetCollisionShape() const
{
return this->collisionShape;
}
btDefaultMotionState* SimpleRigidBody::GetMotionState() const
{
return this->motionState;
}
btRigidBody* SimpleRigidBody::GetRigidBody() const
{
return this->rigidBody;
}
SimpleRigidBody::State SimpleRigidBody::GetState() const
{
return this->state;

View File

@ -4,13 +4,14 @@
#include "..\PhysicsAPI.h"
#include <btBulletDynamicsCommon.h>
namespace Oyster { namespace Physics
namespace Oyster
{
namespace Physics
{
class SimpleRigidBody : public ICustomBody
{
public:
SimpleRigidBody();
SimpleRigidBody( const API::SimpleBodyDescription &desc );
virtual ~SimpleRigidBody();
void SetCollisionShape(btCollisionShape* shape);
@ -18,13 +19,18 @@ namespace Oyster { namespace Physics
void SetRigidBody(btRigidBody* rigidBody);
void SetSubscription(EventAction_AfterCollisionResponse function);
void CallSubsciptMessage(ICustomBody* bodyA, ICustomBody* bodyB, Math::Float kineticEnergyLoss);
void SetSubscription(EventAction_Move function);
void CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Math::Float kineticEnergyLoss);
void CallSubscription_Move();
State GetState() const;
State & GetState( State &targetMem ) const;
void SetState( const State &state );
btCollisionShape* GetCollisionShape() const;
btDefaultMotionState* GetMotionState() const;
btRigidBody* GetRigidBody() const;
void SetCustomTag( void *ref );
void* GetCustomTag() const;
@ -37,9 +43,11 @@ namespace Oyster { namespace Physics
Struct::CustomBodyState state;
EventAction_AfterCollisionResponse afterCollision;
EventAction_Move onMovement;
void *customTag;
};
} }
}
}
#endif

View File

@ -142,6 +142,8 @@ namespace Oyster
virtual void SetState( const State &state ) = 0;
virtual void SetSubscription(EventAction_AfterCollisionResponse function) = 0;
virtual void SetSubscription(EventAction_Move function) = 0;
/********************************************************
* @return the void pointer set by SetCustomTag.