From 05c560e7b9f508997a7c7c5e466329692796dab4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 10 Oct 2012 21:27:41 +0000 Subject: Provided bullet physics collision callback methods. --- src/core/entity.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/core/entity.cc') diff --git a/src/core/entity.cc b/src/core/entity.cc index 1b879f3..46bcd5d 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -646,6 +646,7 @@ void Entity::reset() //entity_body->setActivationState(ISLAND_SLEEPING); entity_body->setActivationState(WANTS_DEACTIVATION); entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT); + entity_body->setUserPointer((void *) this); if (zone()) zone()->physics()->addRigidBody(entity_body); @@ -779,6 +780,10 @@ void EntityDynamic::reset() // create physics body entity_body_info = new btRigidBody::btRigidBodyConstructionInfo(entity_mass, entity_motionstate, entity_collision_shape, inertia); entity_body = new btRigidBody(*entity_body_info); + // point the bullet user pointer to the entity + entity_body->setUserPointer((void *) this); + // enable custom collision callback + entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); if (entity_mass) { entity_body->setActivationState(DISABLE_DEACTIVATION); @@ -800,6 +805,9 @@ void EntityDynamic::reset() motionstate()->setWorldTransform(t); } + /* Does not work + + if (entity_mass) { if (entity_state == Docked) { entity_body->setActivationState(DISABLE_SIMULATION); @@ -809,6 +817,7 @@ void EntityDynamic::reset() entity_body->setActivationState(DISABLE_DEACTIVATION); } } + */ set_dirty(); } @@ -845,6 +854,10 @@ void EntityDynamic::frame(const unsigned long elapsed) } } +void EntityDynamic::collision(Entity *other) +{ +} + void EntityDynamic::serialize_server_create(std::ostream & os) const { Entity::serialize_server_create(os); @@ -1253,6 +1266,11 @@ void EntityControlable::reset() entity_body_info = new btRigidBody::btRigidBodyConstructionInfo(entity_mass, entity_motionstate, entity_collision_shape, inertia); entity_body = new btRigidBody(*entity_body_info); entity_body->setActivationState(DISABLE_DEACTIVATION); + // point the bullet user pointer to the entity + entity_body->setUserPointer((void *) this); + // enable custom collision callback + entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); + //entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); entity_actioninterface = new ActionInterface(this); @@ -1269,6 +1287,8 @@ void EntityControlable::reset() body()->setWorldTransform(t); motionstate()->setWorldTransform(t); + /* Does not work + if (entity_state == Docked) { entity_body->setActivationState(DISABLE_SIMULATION); entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE); @@ -1276,7 +1296,7 @@ void EntityControlable::reset() entity_body->setActivationState(DISABLE_DEACTIVATION); entity_body->setCollisionFlags(entity_body->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE); } - + */ set_dirty(); } -- cgit v1.2.3