diff --git a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp index d3ac0b5ed..c0790aa31 100644 --- a/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp +++ b/src/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp @@ -345,7 +345,7 @@ void btDiscreteDynamicsWorld::setGravity(const btVector3& gravity) for ( int i=0;iisActive()) + if (body->isActive() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY)) { body->setGravity(gravity); } @@ -380,7 +380,7 @@ void btDiscreteDynamicsWorld::removeRigidBody(btRigidBody* body) void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body) { - if (!body->isStaticOrKinematicObject()) + if (!body->isStaticOrKinematicObject() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY)) { body->setGravity(m_gravity); } @@ -405,7 +405,7 @@ void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body) void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body, short group, short mask) { - if (!body->isStaticOrKinematicObject()) + if (!body->isStaticOrKinematicObject() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY)) { body->setGravity(m_gravity); } diff --git a/src/BulletDynamics/Dynamics/btRigidBody.cpp b/src/BulletDynamics/Dynamics/btRigidBody.cpp index 48c037e50..1ab07dda5 100644 --- a/src/BulletDynamics/Dynamics/btRigidBody.cpp +++ b/src/BulletDynamics/Dynamics/btRigidBody.cpp @@ -86,6 +86,8 @@ void btRigidBody::setupRigidBody(const btRigidBody::btRigidBodyConstructionInfo& setDamping(constructionInfo.m_linearDamping, constructionInfo.m_angularDamping); updateInertiaTensor(); + m_rigidbodyFlags = 0; + } diff --git a/src/BulletDynamics/Dynamics/btRigidBody.h b/src/BulletDynamics/Dynamics/btRigidBody.h index 708b2251e..1376ca544 100644 --- a/src/BulletDynamics/Dynamics/btRigidBody.h +++ b/src/BulletDynamics/Dynamics/btRigidBody.h @@ -38,6 +38,10 @@ extern bool gDisableDeactivation; #endif //BT_USE_DOUBLE_PRECISION +enum btRigidBodyFlags +{ + BT_DISABLE_WORLD_GRAVITY = 1 +}; ///The btRigidBody is the main class for rigid body objects. It is derived from btCollisionObject, so it keeps a pointer to a btCollisionShape. @@ -83,6 +87,10 @@ class btRigidBody : public btCollisionObject //keep track of typed constraints referencing this rigid body btAlignedObjectArray m_constraintRefs; + int m_rigidbodyFlags; + + int m_debugBodyId; + public: ///The btRigidBodyConstructionInfo structure provides information to create a rigid body. Setting mass to zero creates a fixed (non-dynamic) rigid body. @@ -503,7 +511,15 @@ public: return m_constraintRefs.size(); } - int m_debugBodyId; + void setFlags(int flags) + { + m_rigidbodyFlags = flags; + } + + int getFlags() const + { + return m_rigidbodyFlags; + } virtual int calculateSerializeBufferSize() const;