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 ++++++++++++++++++++++++++++++++++ src/RenderBackend/OpenGL/Texture2D.cpp | 1 + 2 files changed, 41 insertions(+) create mode 100644 src/Physics/Physics.cpp (limited to 'src') 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 diff --git a/src/RenderBackend/OpenGL/Texture2D.cpp b/src/RenderBackend/OpenGL/Texture2D.cpp index 089a5f1..fa84353 100644 --- a/src/RenderBackend/OpenGL/Texture2D.cpp +++ b/src/RenderBackend/OpenGL/Texture2D.cpp @@ -67,6 +67,7 @@ namespace amalgine { glBindTexture(GL_TEXTURE_2D, texture_ref); //output_gl_error("bind texture"); + // TODO: Take into account GL_ARB_texture_non_power_of_two and resize the image to power of two glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->getWidth(), image->getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, image->getData()); //output_gl_error("set texture"); -- cgit v1.2.3