From 5a49f660dfbdb0c684daf83c39a845efd58efc0b Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 12 Jul 2011 22:47:19 +0000 Subject: Disable physics for docked entities. --- src/core/entity.cc | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'src/core/entity.cc') diff --git a/src/core/entity.cc b/src/core/entity.cc index da94896..a59c85c 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -623,11 +623,13 @@ void Entity::reset() zone()->physics()->addRigidBody(entity_body); } - // transfer entity location to motion state - body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); + // transfer entity location to body body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); + body()->setAngularVelocity(btVector3(0.0f, 0.0f, 0.0f)); + body()->clearForces(); body()->setWorldTransform(t); + set_dirty(); } @@ -761,19 +763,26 @@ void EntityDynamic::reset() // transfer entity location to motion state body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); - body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); + body()->setAngularVelocity(btVector3(0.0f, 0.0f, 0.0f)); body()->setWorldTransform(t); + body()->clearForces(); if (motionstate()) { 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)); + //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)); + //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); + } else { + entity_body->setActivationState(ISLAND_SLEEPING); + } } set_dirty(); @@ -1210,7 +1219,6 @@ 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); @@ -1222,17 +1230,20 @@ void EntityControlable::reset() } } + body()->clearForces(); body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); - body()->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f)); + body()->setAngularVelocity(btVector3(0.0f, 0.0f, 0.0f)); body()->setWorldTransform(t); 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)); + //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)); + //body()->setLinearFactor(btVector3(1.0f, 1.0f, 1.0f)); + //body()->setAngularFactor(btVector3(1.0f, 1.0f, 1.0f)); + entity_body->setActivationState(DISABLE_DEACTIVATION); } //if (zone()) { -- cgit v1.2.3