Add flags to btRigidBody to disable world gravity.

Use setFlags/getFlags with BT_DISABLE_WORLD_GRAVITY

See http://code.google.com/p/bullet/issues/detail?id=324
This commit is contained in:
erwin.coumans 2010-02-03 23:58:48 +00:00
parent 219517db2d
commit 87b313d715
3 changed files with 22 additions and 4 deletions

View File

@ -345,7 +345,7 @@ void btDiscreteDynamicsWorld::setGravity(const btVector3& gravity)
for ( int i=0;i<m_nonStaticRigidBodies.size();i++) for ( int i=0;i<m_nonStaticRigidBodies.size();i++)
{ {
btRigidBody* body = m_nonStaticRigidBodies[i]; btRigidBody* body = m_nonStaticRigidBodies[i];
if (body->isActive()) if (body->isActive() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY))
{ {
body->setGravity(gravity); body->setGravity(gravity);
} }
@ -380,7 +380,7 @@ void btDiscreteDynamicsWorld::removeRigidBody(btRigidBody* body)
void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body) void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
{ {
if (!body->isStaticOrKinematicObject()) if (!body->isStaticOrKinematicObject() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY))
{ {
body->setGravity(m_gravity); body->setGravity(m_gravity);
} }
@ -405,7 +405,7 @@ void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body)
void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body, short group, short mask) 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); body->setGravity(m_gravity);
} }

View File

@ -86,6 +86,8 @@ void btRigidBody::setupRigidBody(const btRigidBody::btRigidBodyConstructionInfo&
setDamping(constructionInfo.m_linearDamping, constructionInfo.m_angularDamping); setDamping(constructionInfo.m_linearDamping, constructionInfo.m_angularDamping);
updateInertiaTensor(); updateInertiaTensor();
m_rigidbodyFlags = 0;
} }

View File

@ -38,6 +38,10 @@ extern bool gDisableDeactivation;
#endif //BT_USE_DOUBLE_PRECISION #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. ///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 //keep track of typed constraints referencing this rigid body
btAlignedObjectArray<btTypedConstraint*> m_constraintRefs; btAlignedObjectArray<btTypedConstraint*> m_constraintRefs;
int m_rigidbodyFlags;
int m_debugBodyId;
public: public:
///The btRigidBodyConstructionInfo structure provides information to create a rigid body. Setting mass to zero creates a fixed (non-dynamic) rigid body. ///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(); return m_constraintRefs.size();
} }
int m_debugBodyId; void setFlags(int flags)
{
m_rigidbodyFlags = flags;
}
int getFlags() const
{
return m_rigidbodyFlags;
}
virtual int calculateSerializeBufferSize() const; virtual int calculateSerializeBufferSize() const;