Added on move functionality
This commit is contained in:
parent
e5e99924d9
commit
05aa3cc9e9
|
@ -71,7 +71,7 @@ Game::PlayerData* Game::CreatePlayer()
|
||||||
int i = InsertObject(this->players, (PlayerData*)0);
|
int i = InsertObject(this->players, (PlayerData*)0);
|
||||||
|
|
||||||
this->players[i] = new PlayerData();
|
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];
|
return this->players[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 r
|
||||||
|
|
||||||
void API_Impl::UpdateWorld()
|
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;
|
ICustomBody::State state;
|
||||||
|
|
||||||
|
@ -115,6 +115,10 @@ void API_Impl::UpdateWorld()
|
||||||
state.centerPos = Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z());
|
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());
|
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);
|
this->customBodies[i]->SetState(state);
|
||||||
}
|
}
|
||||||
|
@ -129,8 +133,8 @@ void API_Impl::UpdateWorld()
|
||||||
ICustomBody* bodyA = (ICustomBody*)obA->getUserPointer();
|
ICustomBody* bodyA = (ICustomBody*)obA->getUserPointer();
|
||||||
ICustomBody* bodyB = (ICustomBody*)obB->getUserPointer();
|
ICustomBody* bodyB = (ICustomBody*)obB->getUserPointer();
|
||||||
|
|
||||||
//dynamic_cast<SimpleRigidBody*>(bodyA)->CallSubsciptMessage(bodyA, bodyB, 0.0f);
|
dynamic_cast<SimpleRigidBody*>(bodyA)->CallSubscription_AfterCollisionResponse(bodyA, bodyB, 0.0f);
|
||||||
//dynamic_cast<SimpleRigidBody*>(bodyB)->CallSubsciptMessage(bodyB, bodyA, 0.0f);
|
dynamic_cast<SimpleRigidBody*>(bodyB)->CallSubscription_AfterCollisionResponse(bodyB, bodyA, 0.0f);
|
||||||
|
|
||||||
int numContacts = contactManifold->getNumContacts();
|
int numContacts = contactManifold->getNumContacts();
|
||||||
for (int j=0;j<numContacts;j++)
|
for (int j=0;j<numContacts;j++)
|
||||||
|
|
|
@ -22,14 +22,8 @@ SimpleRigidBody::SimpleRigidBody()
|
||||||
this->state.restitutionCoeff = 0.0f;
|
this->state.restitutionCoeff = 0.0f;
|
||||||
this->state.reach = Float3(0.0f, 0.0f, 0.0f);
|
this->state.reach = Float3(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
this->customTag = nullptr;
|
this->afterCollision = NULL;
|
||||||
}
|
this->onMovement = NULL;
|
||||||
|
|
||||||
SimpleRigidBody::SimpleRigidBody( const API::SimpleBodyDescription &desc )
|
|
||||||
{
|
|
||||||
this->collisionShape = NULL;
|
|
||||||
this->motionState = NULL;
|
|
||||||
this->rigidBody = NULL;
|
|
||||||
|
|
||||||
this->customTag = nullptr;
|
this->customTag = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -65,9 +59,26 @@ void SimpleRigidBody::SetSubscription(EventAction_AfterCollisionResponse functio
|
||||||
this->afterCollision = function;
|
this->afterCollision = function;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleRigidBody::CallSubsciptMessage(ICustomBody* bodyA, ICustomBody* bodyB, Oyster::Math::Float kineticEnergyLoss)
|
void SimpleRigidBody::SetSubscription(EventAction_Move function)
|
||||||
{
|
{
|
||||||
this->afterCollision(bodyA, bodyB, kineticEnergyLoss);
|
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
|
btDefaultMotionState* SimpleRigidBody::GetMotionState() const
|
||||||
|
@ -75,6 +86,11 @@ btDefaultMotionState* SimpleRigidBody::GetMotionState() const
|
||||||
return this->motionState;
|
return this->motionState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btRigidBody* SimpleRigidBody::GetRigidBody() const
|
||||||
|
{
|
||||||
|
return this->rigidBody;
|
||||||
|
}
|
||||||
|
|
||||||
SimpleRigidBody::State SimpleRigidBody::GetState() const
|
SimpleRigidBody::State SimpleRigidBody::GetState() const
|
||||||
{
|
{
|
||||||
return this->state;
|
return this->state;
|
||||||
|
|
|
@ -4,42 +4,50 @@
|
||||||
#include "..\PhysicsAPI.h"
|
#include "..\PhysicsAPI.h"
|
||||||
#include <btBulletDynamicsCommon.h>
|
#include <btBulletDynamicsCommon.h>
|
||||||
|
|
||||||
namespace Oyster { namespace Physics
|
namespace Oyster
|
||||||
{
|
{
|
||||||
class SimpleRigidBody : public ICustomBody
|
namespace Physics
|
||||||
{
|
{
|
||||||
public:
|
class SimpleRigidBody : public ICustomBody
|
||||||
SimpleRigidBody();
|
{
|
||||||
SimpleRigidBody( const API::SimpleBodyDescription &desc );
|
public:
|
||||||
virtual ~SimpleRigidBody();
|
SimpleRigidBody();
|
||||||
|
virtual ~SimpleRigidBody();
|
||||||
|
|
||||||
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 SetSubscription(EventAction_AfterCollisionResponse function);
|
void SetSubscription(EventAction_AfterCollisionResponse function);
|
||||||
void CallSubsciptMessage(ICustomBody* bodyA, ICustomBody* bodyB, Math::Float kineticEnergyLoss);
|
void SetSubscription(EventAction_Move function);
|
||||||
|
|
||||||
State GetState() const;
|
void CallSubscription_AfterCollisionResponse(ICustomBody* bodyA, ICustomBody* bodyB, Math::Float kineticEnergyLoss);
|
||||||
State & GetState( State &targetMem ) const;
|
void CallSubscription_Move();
|
||||||
void SetState( const State &state );
|
|
||||||
|
|
||||||
btDefaultMotionState* GetMotionState() const;
|
State GetState() const;
|
||||||
|
State & GetState( State &targetMem ) const;
|
||||||
|
void SetState( const State &state );
|
||||||
|
|
||||||
void SetCustomTag( void *ref );
|
btCollisionShape* GetCollisionShape() const;
|
||||||
void* GetCustomTag() const;
|
btDefaultMotionState* GetMotionState() const;
|
||||||
|
btRigidBody* GetRigidBody() const;
|
||||||
|
|
||||||
private:
|
void SetCustomTag( void *ref );
|
||||||
btCollisionShape* collisionShape;
|
void* GetCustomTag() const;
|
||||||
btDefaultMotionState* motionState;
|
|
||||||
btRigidBody* rigidBody;
|
|
||||||
|
|
||||||
Struct::CustomBodyState state;
|
private:
|
||||||
|
btCollisionShape* collisionShape;
|
||||||
|
btDefaultMotionState* motionState;
|
||||||
|
btRigidBody* rigidBody;
|
||||||
|
|
||||||
EventAction_AfterCollisionResponse afterCollision;
|
Struct::CustomBodyState state;
|
||||||
|
|
||||||
void *customTag;
|
EventAction_AfterCollisionResponse afterCollision;
|
||||||
};
|
EventAction_Move onMovement;
|
||||||
} }
|
|
||||||
|
void *customTag;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -142,6 +142,8 @@ namespace Oyster
|
||||||
virtual void SetState( const State &state ) = 0;
|
virtual void SetState( const State &state ) = 0;
|
||||||
|
|
||||||
virtual void SetSubscription(EventAction_AfterCollisionResponse function) = 0;
|
virtual void SetSubscription(EventAction_AfterCollisionResponse function) = 0;
|
||||||
|
virtual void SetSubscription(EventAction_Move function) = 0;
|
||||||
|
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* @return the void pointer set by SetCustomTag.
|
* @return the void pointer set by SetCustomTag.
|
||||||
|
|
Loading…
Reference in New Issue