2013-11-20 11:09:27 +01:00
|
|
|
#ifndef PHYSICS_API_IMPL_H
|
|
|
|
#define PHYSICS_API_IMPL_H
|
|
|
|
|
|
|
|
#include "../PhysicsAPI.h"
|
2013-11-28 17:59:12 +01:00
|
|
|
#include "Octree.h"
|
2014-02-09 21:24:09 +01:00
|
|
|
#include <btBulletDynamicsCommon.h>
|
2013-11-20 11:09:27 +01:00
|
|
|
|
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Physics
|
|
|
|
{
|
|
|
|
class API_Impl : public API
|
|
|
|
{
|
|
|
|
public:
|
2014-02-12 10:23:07 +01:00
|
|
|
struct ContactSensorCallback : public btCollisionWorld::ContactResultCallback
|
|
|
|
{
|
|
|
|
ContactSensorCallback(btRigidBody& contactBody, EventAction_ApplyEffect effect, void* args)
|
|
|
|
: btCollisionWorld::ContactResultCallback(), body(contactBody), func(effect), args(args) {}
|
|
|
|
|
|
|
|
btRigidBody& body;
|
|
|
|
EventAction_ApplyEffect func;
|
|
|
|
void* args;
|
|
|
|
|
|
|
|
virtual bool needsCollision(btBroadphaseProxy* proxy) const
|
|
|
|
{
|
|
|
|
if(!btCollisionWorld::ContactResultCallback::needsCollision(proxy))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return body.checkCollideWithOverride(static_cast<btCollisionObject*>(proxy->m_clientObject));
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0, int partId0, int index0, const btCollisionObjectWrapper* colObj1, int partId1, int index1)
|
|
|
|
{
|
|
|
|
btVector3 pt;
|
|
|
|
if(colObj0->m_collisionObject == &body)
|
|
|
|
{
|
|
|
|
pt = cp.m_localPointA;
|
2014-02-12 10:57:55 +01:00
|
|
|
this->func((ICustomBody*)(colObj1->getCollisionObject()->getUserPointer()), this->args);
|
2014-02-12 10:23:07 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-12 12:38:52 +01:00
|
|
|
//assert(colObj1->m_collisionObject == &body && "Body does not match either collision object");
|
2014-02-12 10:23:07 +01:00
|
|
|
pt = cp.m_localPointB;
|
2014-02-12 10:57:55 +01:00
|
|
|
this->func((ICustomBody*)(colObj0->getCollisionObject()->getUserPointer()), this->args);
|
2014-02-12 10:23:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-20 11:09:27 +01:00
|
|
|
API_Impl();
|
|
|
|
virtual ~API_Impl();
|
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
void Init();
|
2013-11-20 11:09:27 +01:00
|
|
|
|
2013-11-25 10:54:27 +01:00
|
|
|
bool IsInLimbo( const ICustomBody* objRef );
|
|
|
|
void MoveToLimbo( const ICustomBody* objRef );
|
|
|
|
void ReleaseFromLimbo( const ICustomBody* objRef );
|
|
|
|
|
2014-02-11 13:36:14 +01:00
|
|
|
void SetGravityPoint(::Oyster::Math::Float3 gravityPoint);
|
|
|
|
void SetGravity(float gravity);
|
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
// Bullet physics
|
2014-02-10 14:18:45 +01:00
|
|
|
ICustomBody* AddCollisionSphere(float radius, ::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);
|
2013-11-25 10:54:27 +01:00
|
|
|
|
2014-02-11 09:15:21 +01:00
|
|
|
void SetTimeStep(float timeStep);
|
|
|
|
|
2014-02-09 21:24:09 +01:00
|
|
|
void UpdateWorld();
|
2014-01-15 10:44:31 +01:00
|
|
|
|
2014-02-12 10:23:07 +01:00
|
|
|
void ApplyEffect(Oyster::Collision3D::ICollideable* collideable, void* args, EventAction_ApplyEffect effect);
|
2014-01-21 14:10:31 +01:00
|
|
|
|
2013-11-25 16:57:38 +01:00
|
|
|
private:
|
2014-02-09 21:24:09 +01:00
|
|
|
btBroadphaseInterface* broadphase;
|
|
|
|
btDefaultCollisionConfiguration* collisionConfiguration;
|
|
|
|
btCollisionDispatcher* dispatcher;
|
|
|
|
btSequentialImpulseConstraintSolver* solver;
|
|
|
|
btDiscreteDynamicsWorld* dynamicsWorld;
|
|
|
|
std::vector<ICustomBody*> customBodies;
|
2014-02-11 09:15:21 +01:00
|
|
|
|
|
|
|
float timeStep;
|
2014-02-11 13:36:14 +01:00
|
|
|
|
|
|
|
::Oyster::Math::Float3 gravityPoint;
|
|
|
|
float gravity;
|
2013-11-20 11:09:27 +01:00
|
|
|
};
|
|
|
|
|
2013-11-28 10:26:29 +01:00
|
|
|
namespace Default
|
|
|
|
{
|
|
|
|
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto );
|
2014-01-29 11:22:04 +01:00
|
|
|
::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_BeforeCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter );
|
|
|
|
void EventAction_AfterCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss );
|
2014-01-17 16:07:25 +01:00
|
|
|
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object );
|
2013-11-28 10:26:29 +01:00
|
|
|
}
|
|
|
|
}
|
2013-11-20 11:09:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|