Danbias/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.h

101 lines
3.9 KiB
C
Raw Normal View History

#ifndef PHYSICS_API_IMPL_H
#define PHYSICS_API_IMPL_H
#include "../PhysicsAPI.h"
2014-02-09 21:24:09 +01:00
#include <btBulletDynamicsCommon.h>
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
{
//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;
}
};
API_Impl();
virtual ~API_Impl();
2014-02-09 21:24:09 +01:00
void Init();
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
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);
ICustomBody* AddCharacter(::Oyster::Math::Float height, ::Oyster::Math::Float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
ICustomBody* AddTriangleMesh(const std::wstring fileName, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
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);
private:
2014-02-09 21:24:09 +01:00
btBroadphaseInterface* broadphase;
btDefaultCollisionConfiguration* collisionConfiguration;
btCollisionDispatcher* dispatcher;
btSequentialImpulseConstraintSolver* solver;
btDiscreteDynamicsWorld* dynamicsWorld;
std::vector<ICustomBody*> customBodies;
float timeStep;
2014-02-11 13:36:14 +01:00
::Oyster::Math::Float3 gravityPoint;
float gravity;
};
namespace Default
{
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto );
::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 );
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object );
}
}
}
#endif