From c3453fedbd270afe8d9dfc7f288ea7205f029b86 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 29 Feb 2020 00:36:43 +0100 Subject: Begin on physics --- src/Physics/Physics.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/Physics/Physics.cpp (limited to 'src/Physics') diff --git a/src/Physics/Physics.cpp b/src/Physics/Physics.cpp new file mode 100644 index 0000000..fb00d1d --- /dev/null +++ b/src/Physics/Physics.cpp @@ -0,0 +1,40 @@ +#include "../../include/Physics/Physics.hpp" + +#include + +// TODO: Figure out how to process physics in another thread. Should it be done simply by +// calling stepSimulation in another thread? + +static void physics_update_callback(btDynamicsWorld *dynamics_world, btScalar time_step) { + btDispatcher *dispatcher = dynamics_world->getDispatcher(); + int num_manifolds = dispatcher->getNumManifolds(); + for(int i = 0; i < num_manifolds; ++i) { + btPersistentManifold *contact_manifold = dispatcher->getManifoldByIndexInternal(i); + { + // The bodies that collided + const btCollisionObject *obj_this = contact_manifold->getBody0(); + const btCollisionObject *obj_other = contact_manifold->getBody1(); + } + int num_contacts = contact_manifold->getNumContacts(); + for(int j = 0; j < num_contacts; ++j) { + btManifoldPoint &pt = contact_manifold->getContactPoint(j); + const btVector3 &pt_this = pt.getPositionWorldOnA(); + const btVector3 &pt_other = pt.getPositionWorldOnB(); + const btVector3 &normal_on_other = pt.m_normalWorldOnB; + } + } +} + +namespace amalgine { + Physics::Physics() { + btDefaultCollisionConfiguration *collision_configuration = new btDefaultCollisionConfiguration(); + btCollisionDispatcher *dispatcher = new btCollisionDispatcher(collision_configuration); + btBroadphaseInterface *overlapping_pair_cache = new btDbvtBroadphase(); + btSequentialImpulseConstraintSolver *solver = new btSequentialImpulseConstraintSolver(); + btDiscreteDynamicsWorld *dynamics_world = new btDiscreteDynamicsWorld(dispatcher, overlapping_pair_cache, solver, collision_configuration); + const float gravity = -10.0f; + dynamics_world->setGravity(btVector3(0.0f, gravity, 0.0f)); + dynamics_world->setInternalTickCallback(physics_update_callback); + //dynamics_world->debugDrawWorld(); + } +} \ No newline at end of file -- cgit v1.2.3