Merge branch 'GamePhysics' of https://github.com/dean11/Danbias into GameLogic
This commit is contained in:
commit
dc5783ad4f
|
@ -24,6 +24,8 @@ API_Impl::API_Impl()
|
||||||
this->dispatcher = NULL;
|
this->dispatcher = NULL;
|
||||||
this->solver = NULL;
|
this->solver = NULL;
|
||||||
this->dynamicsWorld = NULL;
|
this->dynamicsWorld = NULL;
|
||||||
|
|
||||||
|
this->timeStep = 1.0f/120.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
API_Impl::~API_Impl()
|
API_Impl::~API_Impl()
|
||||||
|
@ -39,7 +41,7 @@ API_Impl::~API_Impl()
|
||||||
delete this->broadphase;
|
delete this->broadphase;
|
||||||
this->broadphase = NULL;
|
this->broadphase = NULL;
|
||||||
|
|
||||||
for(int i = 0; i < this->customBodies.size(); i++)
|
for(unsigned int i = 0; i < this->customBodies.size(); i++)
|
||||||
{
|
{
|
||||||
delete this->customBodies[i];
|
delete this->customBodies[i];
|
||||||
this->customBodies[i] = NULL;
|
this->customBodies[i] = NULL;
|
||||||
|
@ -164,27 +166,33 @@ ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::O
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void API_Impl::SetTimeStep(float timeStep)
|
||||||
|
{
|
||||||
|
this->timeStep = timeStep;
|
||||||
|
}
|
||||||
|
|
||||||
void API_Impl::UpdateWorld()
|
void API_Impl::UpdateWorld()
|
||||||
{
|
{
|
||||||
this->dynamicsWorld->stepSimulation(1.0f/60.0f, 1.0f, 1.0f/60.0f);
|
this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep);
|
||||||
|
|
||||||
ICustomBody::State state;
|
ICustomBody::State state;
|
||||||
|
|
||||||
for(unsigned int i = 0; i < this->customBodies.size(); i++ )
|
for(unsigned int i = 0; i < this->customBodies.size(); i++ )
|
||||||
{
|
{
|
||||||
|
SimpleRigidBody* simpleBody = dynamic_cast<SimpleRigidBody*>(this->customBodies[i]);
|
||||||
btTransform trans;
|
btTransform trans;
|
||||||
dynamic_cast<SimpleRigidBody*>(this->customBodies[i])->GetMotionState()->getWorldTransform(trans);
|
simpleBody->GetMotionState()->getWorldTransform(trans);
|
||||||
this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z()));
|
this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z()));
|
||||||
this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w()));
|
this->customBodies[i]->SetRotation(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)
|
if(simpleBody->GetRigidBody()->getActivationState() == ACTIVE_TAG)
|
||||||
{
|
{
|
||||||
dynamic_cast<SimpleRigidBody*>(this->customBodies[i])->CallSubscription_Move();
|
simpleBody->CallSubscription_Move();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int numManifolds = this->dynamicsWorld->getDispatcher()->getNumManifolds();
|
int numManifolds = this->dynamicsWorld->getDispatcher()->getNumManifolds();
|
||||||
for (int i=0;i<numManifolds;i++)
|
for (int i = 0; i < numManifolds; i++)
|
||||||
{
|
{
|
||||||
btPersistentManifold* contactManifold = this->dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
|
btPersistentManifold* contactManifold = this->dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
|
||||||
const btCollisionObject* obA = contactManifold->getBody0();
|
const btCollisionObject* obA = contactManifold->getBody0();
|
||||||
|
@ -195,18 +203,6 @@ void API_Impl::UpdateWorld()
|
||||||
|
|
||||||
dynamic_cast<SimpleRigidBody*>(bodyA)->CallSubscription_AfterCollisionResponse(bodyA, bodyB, 0.0f);
|
dynamic_cast<SimpleRigidBody*>(bodyA)->CallSubscription_AfterCollisionResponse(bodyA, bodyB, 0.0f);
|
||||||
dynamic_cast<SimpleRigidBody*>(bodyB)->CallSubscription_AfterCollisionResponse(bodyB, bodyA, 0.0f);
|
dynamic_cast<SimpleRigidBody*>(bodyB)->CallSubscription_AfterCollisionResponse(bodyB, bodyA, 0.0f);
|
||||||
|
|
||||||
int numContacts = contactManifold->getNumContacts();
|
|
||||||
for (int j=0;j<numContacts;j++)
|
|
||||||
{
|
|
||||||
btManifoldPoint& pt = contactManifold->getContactPoint(j);
|
|
||||||
if (pt.getDistance()<0.f)
|
|
||||||
{
|
|
||||||
const btVector3& ptA = pt.getPositionWorldOnA();
|
|
||||||
const btVector3& ptB = pt.getPositionWorldOnB();
|
|
||||||
const btVector3& normalOnB = pt.m_normalWorldOnB;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -257,9 +253,7 @@ namespace Oyster
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventAction_AfterCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss )
|
void EventAction_AfterCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss )
|
||||||
{ /* Do nothing except returning business as usual. */
|
{ /* Do nothing except returning business as usual. */ }
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object )
|
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object )
|
||||||
{ /* Do nothing. */ }
|
{ /* Do nothing. */ }
|
||||||
|
|
|
@ -26,6 +26,8 @@ namespace Oyster
|
||||||
ICustomBody* AddCollisionBox(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
|
ICustomBody* AddCollisionBox(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
|
||||||
ICustomBody* AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
|
ICustomBody* AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
|
||||||
|
|
||||||
|
void SetTimeStep(float timeStep);
|
||||||
|
|
||||||
void UpdateWorld();
|
void UpdateWorld();
|
||||||
|
|
||||||
void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void* args, void(hitAction)(ICustomBody*, void*) );
|
void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void* args, void(hitAction)(ICustomBody*, void*) );
|
||||||
|
@ -37,6 +39,8 @@ namespace Oyster
|
||||||
btSequentialImpulseConstraintSolver* solver;
|
btSequentialImpulseConstraintSolver* solver;
|
||||||
btDiscreteDynamicsWorld* dynamicsWorld;
|
btDiscreteDynamicsWorld* dynamicsWorld;
|
||||||
std::vector<ICustomBody*> customBodies;
|
std::vector<ICustomBody*> customBodies;
|
||||||
|
|
||||||
|
float timeStep;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Default
|
namespace Default
|
||||||
|
|
|
@ -134,6 +134,49 @@ void SimpleRigidBody::SetRotation(Float3 eulerAngles)
|
||||||
this->state.quaternion = Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w());
|
this->state.quaternion = Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SimpleRigidBody::SetAngularFactor(Float factor)
|
||||||
|
{
|
||||||
|
this->rigidBody->setAngularFactor(factor);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleRigidBody::SetUpAndRight(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 right)
|
||||||
|
{
|
||||||
|
btMatrix3x3 rotation;
|
||||||
|
btVector3 upVector(up.x, up.y, up.z);
|
||||||
|
btVector3 rightVector(right.x, right.y, right.z);
|
||||||
|
rotation[1] = upVector.normalized();
|
||||||
|
rotation[0] = rightVector.normalized();
|
||||||
|
rotation[2] = upVector.cross(rightVector).normalized();
|
||||||
|
|
||||||
|
btQuaternion quaternion;
|
||||||
|
rotation.getRotation(quaternion);
|
||||||
|
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
||||||
|
|
||||||
|
btTransform trans;
|
||||||
|
this->motionState->getWorldTransform(trans);
|
||||||
|
trans.setRotation(quaternion);
|
||||||
|
this->motionState->setWorldTransform(trans);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SimpleRigidBody::SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward)
|
||||||
|
{
|
||||||
|
btMatrix3x3 rotation;
|
||||||
|
btVector3 upVector(up.x, up.y, up.z);
|
||||||
|
btVector3 forwardVector(forward.x, forward.y, forward.z);
|
||||||
|
rotation[1] = upVector.normalized();
|
||||||
|
rotation[0] = forwardVector.normalized();
|
||||||
|
rotation[2] = upVector.cross(forwardVector).normalized();
|
||||||
|
|
||||||
|
btQuaternion quaternion;
|
||||||
|
rotation.getRotation(quaternion);
|
||||||
|
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
|
||||||
|
|
||||||
|
btTransform trans;
|
||||||
|
this->motionState->getWorldTransform(trans);
|
||||||
|
trans.setRotation(quaternion);
|
||||||
|
this->motionState->setWorldTransform(trans);
|
||||||
|
}
|
||||||
|
|
||||||
Float4x4 SimpleRigidBody::GetRotation() const
|
Float4x4 SimpleRigidBody::GetRotation() const
|
||||||
{
|
{
|
||||||
return this->state.GetRotation();
|
return this->state.GetRotation();
|
||||||
|
|
|
@ -26,10 +26,14 @@ namespace Oyster
|
||||||
void SetSubscription(EventAction_Move function);
|
void SetSubscription(EventAction_Move function);
|
||||||
|
|
||||||
void SetLinearVelocity(Math::Float3 velocity);
|
void SetLinearVelocity(Math::Float3 velocity);
|
||||||
void SetPosition(::Oyster::Math::Float3 position);
|
void SetPosition(Math::Float3 position);
|
||||||
void SetRotation(Math::Float4 quaternion);
|
void SetRotation(Math::Float4 quaternion);
|
||||||
void SetRotation(::Oyster::Math::Quaternion quaternion);
|
void SetRotation(Math::Quaternion quaternion);
|
||||||
void SetRotation(Math::Float3 eulerAngles);
|
void SetRotation(Math::Float3 eulerAngles);
|
||||||
|
void SetAngularFactor(Math::Float factor);
|
||||||
|
|
||||||
|
void SetUpAndRight(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 right);
|
||||||
|
void SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward);
|
||||||
|
|
||||||
Math::Float4x4 GetRotation() const;
|
Math::Float4x4 GetRotation() const;
|
||||||
Math::Float4x4 GetOrientation() const;
|
Math::Float4x4 GetOrientation() const;
|
||||||
|
|
|
@ -84,6 +84,8 @@ namespace Oyster
|
||||||
virtual ICustomBody* AddCollisionBox(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0;
|
virtual ICustomBody* AddCollisionBox(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0;
|
||||||
virtual ICustomBody* AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0;
|
virtual ICustomBody* AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0;
|
||||||
|
|
||||||
|
virtual void SetTimeStep(float timeStep) = 0;
|
||||||
|
|
||||||
virtual void UpdateWorld() = 0;
|
virtual void UpdateWorld() = 0;
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,6 +137,10 @@ namespace Oyster
|
||||||
virtual void SetRotation(::Oyster::Math::Float4 quaternion) = 0;
|
virtual void SetRotation(::Oyster::Math::Float4 quaternion) = 0;
|
||||||
virtual void SetRotation(::Oyster::Math::Quaternion quaternion) = 0;
|
virtual void SetRotation(::Oyster::Math::Quaternion quaternion) = 0;
|
||||||
virtual void SetRotation(::Oyster::Math::Float3 eulerAngles) = 0;
|
virtual void SetRotation(::Oyster::Math::Float3 eulerAngles) = 0;
|
||||||
|
virtual void SetAngularFactor(::Oyster::Math::Float factor) = 0;
|
||||||
|
|
||||||
|
virtual void SetUpAndRight(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 right) = 0;
|
||||||
|
virtual void SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward) = 0;
|
||||||
|
|
||||||
::Oyster::Math::Float4x4 GetRotation() const;
|
::Oyster::Math::Float4x4 GetRotation() const;
|
||||||
::Oyster::Math::Float4x4 GetOrientation() const;
|
::Oyster::Math::Float4x4 GetOrientation() const;
|
||||||
|
|
Loading…
Reference in New Issue