Gravity force not set when mass changes

Stillmoon
Posts: 4
Joined: Thu Dec 10, 2009 5:00 pm

Gravity force not set when mass changes

Post by Stillmoon »

In the project I'm working on, we occasionally need to change the mass of rigid bodies. We call btRigidBody::setMassProps with the new mass and inertia while the simulation is running.

However, setMassProps does not recalculate the force due to gravity, which of course, depends on the mass.

This was easy enough to fix by calling

Code: Select all

someBody->setGravity(someBody->getGravity());
after setMassProps.

Is this something setMassProps should handle internally? If so, adding

Code: Select all

m_gravity = m_gravity_acceleration * mass;
to the end of setMassProps should do the trick.

This may also help solve some of the "slow-motion" gravity issues I read about, if the rigid bodies' mass is being set after it's added to the dynamics world.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Gravity force not set when mass changes

Post by Erwin Coumans »

Good point. We should add this indeed,

Code: Select all

m_gravity = acceleration * (btScalar(1.0) / m_inverseMass);
Here is the new issue: http://code.google.com/p/bullet/issues/detail?id=364

Thanks for the feedback,
Erwin