From 72956bdc7733f5744eab1488cbc4b5e685d4dad1 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 13 Jul 2011 16:49:58 +0000 Subject: Cleanup of the bullet state changes in the Entity::reset() functions, corrected a problem that prevented collision models from working on EntityDynamic. --- src/core/entity.cc | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'src/core/entity.cc') diff --git a/src/core/entity.cc b/src/core/entity.cc index a59c85c..53a0f95 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -617,7 +617,9 @@ void Entity::reset() entity_body_info = new btRigidBody::btRigidBodyConstructionInfo(0, 0, entity_collision_shape, inertia); entity_body = new btRigidBody(*entity_body_info); - entity_body->setActivationState(ISLAND_SLEEPING); + //entity_body->setActivationState(ISLAND_SLEEPING); + entity_body->setActivationState(WANTS_DEACTIVATION); + entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT); if (zone()) zone()->physics()->addRigidBody(entity_body); @@ -685,7 +687,7 @@ void EntityDynamic::reset() const float modelscale = radius() / model()->radius(); if (model()->collisionmodel() && model()->collisionmodel()->size()) { - // complex collision is enabled and a valid collision model has been found + // complex collision is enabled and a valid collision model has been found btCompoundShape *compoundshape = new btCompoundShape(); for (model::CollisionModel::CollisionMeshes::iterator it = model()->collisionmodel()->meshes().begin(); it != model()->collisionmodel()->meshes().end(); it++) { @@ -700,6 +702,7 @@ void EntityDynamic::reset() const float meshscale = mesh->scale() * modelscale; const btVector3 meshscalevec(meshscale, meshscale, meshscale); meshshape->setLocalScaling(meshscalevec); + meshshape->updateBound(); // apply collision mesh properties to the btCollisionShape btTransform child_transform; @@ -733,7 +736,7 @@ void EntityDynamic::reset() } else { // use a sphere with a radius matching the entity btSphereShape *sphereshape = new btSphereShape(radius()); - entity_collision_shape = sphereshape; + entity_collision_shape = sphereshape; } // set margin @@ -756,7 +759,7 @@ void EntityDynamic::reset() } else { entity_body->setActivationState(ISLAND_SLEEPING); } - + if (zone()) zone()->physics()->addRigidBody(entity_body); } @@ -771,17 +774,13 @@ void EntityDynamic::reset() motionstate()->setWorldTransform(t); } - if (entity_state == Docked) { - //body()->setLinearFactor(btVector3(0.0f, 0.0f, 0.0f)); - //body()->setAngularFactor(btVector3(0.0f, 0.0f, 0.0f)); - entity_body->setActivationState(DISABLE_SIMULATION); - } else { - //body()->setLinearFactor(btVector3(1.0f, 1.0f, 1.0f)); - //body()->setAngularFactor(btVector3(1.0f, 1.0f, 1.0f)); - if (entity_mass) { - entity_body->setActivationState(DISABLE_DEACTIVATION); + if (entity_mass) { + if (entity_state == Docked) { + entity_body->setActivationState(DISABLE_SIMULATION); + entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE); } else { - entity_body->setActivationState(ISLAND_SLEEPING); + entity_body->setCollisionFlags(entity_body->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE); + entity_body->setActivationState(DISABLE_DEACTIVATION); } } @@ -1165,9 +1164,9 @@ void EntityControlable::reset() // dynamic entities use btGImpactMeshShape btGImpactMeshShape *meshshape = new btGImpactMeshShape(mesh->triangles()); meshshape->setMargin(Cvar::sv_collisionmargin->value()); + const float meshscale = mesh->scale() * modelscale; - const btVector3 meshscalevec(meshscale, meshscale, meshscale); - + const btVector3 meshscalevec(meshscale, meshscale, meshscale); meshshape->setLocalScaling(meshscalevec); meshshape->updateBound(); @@ -1219,7 +1218,7 @@ void EntityControlable::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); - + entity_body->setActivationState(DISABLE_DEACTIVATION); //entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT); entity_actioninterface = new ActionInterface(this); @@ -1237,19 +1236,13 @@ void EntityControlable::reset() motionstate()->setWorldTransform(t); if (entity_state == Docked) { - //body()->setLinearFactor(btVector3(0.0f, 0.0f, 0.0f)); - //body()->setAngularFactor(btVector3(0.0f, 0.0f, 0.0f)); entity_body->setActivationState(DISABLE_SIMULATION); + entity_body->setCollisionFlags(entity_body->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE); } else { - //body()->setLinearFactor(btVector3(1.0f, 1.0f, 1.0f)); - //body()->setAngularFactor(btVector3(1.0f, 1.0f, 1.0f)); entity_body->setActivationState(DISABLE_DEACTIVATION); + entity_body->setCollisionFlags(entity_body->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE); } - //if (zone()) { - // // transfer entity location to motion state - // zone()->physics()->synchronizeSingleMotionState(entity_body); - //} set_dirty(); } -- cgit v1.2.3