aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-02-29 00:36:43 +0100
committerdec05eba <dec05eba@protonmail.com>2021-11-18 15:22:10 +0100
commitc3453fedbd270afe8d9dfc7f288ea7205f029b86 (patch)
tree57158583f023a50a21cc86811889d3ee3cf07fe4 /src
parent9ab59b76c0ece5e261c0152af3f830f48532e103 (diff)
Begin on physics
Diffstat (limited to 'src')
-rw-r--r--src/Physics/Physics.cpp40
-rw-r--r--src/RenderBackend/OpenGL/Texture2D.cpp1
2 files changed, 41 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
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");