Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2012-10-10 21:27:41 +0000
committerStijn Buys <ingar@osirion.org>2012-10-10 21:27:41 +0000
commit05c560e7b9f508997a7c7c5e466329692796dab4 (patch)
treee427006ef35f23cb1ef987442b496e4eb2622aca /src/core/physics.cc
parent8a6f3d478c825d226a21b73f5bcec2b92bf31ccb (diff)
Provided bullet physics collision callback methods.
Diffstat (limited to 'src/core/physics.cc')
-rw-r--r--src/core/physics.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/core/physics.cc b/src/core/physics.cc
index 9ffe13c..2c7dd96 100644
--- a/src/core/physics.cc
+++ b/src/core/physics.cc
@@ -8,10 +8,47 @@
#include "core/physics.h"
#include "core/zone.h"
+#include "btBulletDynamicsCommon.h"
#include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h"
namespace core {
+/* ---- Bullet collision callbacks --------------------------------- */
+
+//extern ContactAddedCallback gContactAddedCallback;
+
+/*
+ * see http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Callbacks_and_Triggers
+ */
+
+bool bullet_contact_added_callback(btManifoldPoint &cp, const btCollisionObject *body0, int partId0, int index0, const btCollisionObject *body1, int partId1, int index1)
+{
+ Entity *entity0 = static_cast<Entity *>(body0->getUserPointer());
+ Entity *entity1 = static_cast<Entity *>(body1->getUserPointer());
+
+ assert(entity0 && entity1);
+
+ // FIXME there should probably be an entity flag indiciating wether or not it has a collision callback
+
+ if ((entity0->type() == Entity::Dynamic) || (entity0->type() == Entity::Controlable)) {
+ static_cast<EntityDynamic *>(entity0)->collision(entity1);
+ }
+
+ if ((entity1->type() == Entity::Dynamic) || (entity1->type() == Entity::Controlable)) {
+ static_cast<EntityDynamic *>(entity1)->collision(entity0);
+ }
+ //con_debug << "collision " << entity0->label() << " - " << entity1->label() << std::endl;
+
+ // the return value should be ignored by bullet.
+ return true;
+}
+
+//bool bullet_contact_processed_callback(btManifoldPoint& cp,void* body0, void* body1);
+
+//bool bullet_contact_destroyed_callback(void* userPersistentData);
+
+/* ---- Bullet physics engine and algorithms ----------------------- */
+
btDefaultCollisionConfiguration *Physics::physics_configuration = 0;
btCollisionDispatcher *Physics::physics_dispatcher = 0;
btSequentialImpulseConstraintSolver *Physics::physics_solver = 0;
@@ -26,6 +63,9 @@ void Physics::init()
physics_dispatcher = new btCollisionDispatcher(physics_configuration);
btGImpactCollisionAlgorithm::registerAlgorithm(physics_dispatcher);
physics_solver = new btSequentialImpulseConstraintSolver;
+
+ // set custom bullet callbacks
+ gContactAddedCallback = bullet_contact_added_callback;
}
void Physics::done()