diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-02-29 00:36:43 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-11-18 15:22:10 +0100 |
commit | c3453fedbd270afe8d9dfc7f288ea7205f029b86 (patch) | |
tree | 57158583f023a50a21cc86811889d3ee3cf07fe4 /src/Physics/Physics.cpp | |
parent | 9ab59b76c0ece5e261c0152af3f830f48532e103 (diff) |
Begin on physics
Diffstat (limited to 'src/Physics/Physics.cpp')
-rw-r--r-- | src/Physics/Physics.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
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 <btBulletDynamicsCommon.h> + +// 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 |