CF_KINEMATIC_OBJECT/zero mass API question

Post Reply
eddybox
Posts: 25
Joined: Thu Nov 29, 2007 7:08 pm

CF_KINEMATIC_OBJECT/zero mass API question

Post by eddybox »

Hi,

I've been having several issues lately regarding kinematic bodies.

1. Minor (continuation of this thread): The fact that setting a kinematic body's velocity doesn't work (ie. gets overriden by the motion state, even if we aren't using one) is rather unpleasant, since it means having two different methods to "drive" bodies. But at least there's a workaround...

2. Major: Kinematic bodies are not affected by the simulation, yet they do not have zero mass. All the computations in the various constraint types use invMass, invInertiaLocal, etc. in order to compute jacobians and impulse magnitudes. This significantly degrades their ability to satisfy the constraint. Locally, I've hacked rigidBody.h to return 0 for invMass (and equivalents for inertias) if the body is kinematic or static, which has improved my results. However, I'm hesitant to check this in as it's actually lying to the method caller. Perhaps new versions of these methods, such as "invMassApparent" (which returns the body's current "apparent" mass) could be added and used where appropriate.

Any thoughts?

Thanks,
Eddy
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Several problems using Bullet

Post by Erwin Coumans »

It would be good to sort out those issue, if only there was a reproduction case that shows the problem.
eddybox wrote: 1. Minor (continuation of this thread): The fact that setting a kinematic body's velocity doesn't work (ie. gets overriden by the motion state, even if we aren't using one) is rather unpleasant, since it means having two different methods to "drive" bodies. But at least there's a workaround...
If you are not using a motion state, you are passing in a NULL pointer for the motionState in btRigidBodyConstructionInfo? How can it still be overridden by a motion state, if it is a NULL pointer?
2. Major: Kinematic bodies are not affected by the simulation, yet they do not have zero mass.
You should set the mass to zero for a kinematic objects, the interaction with rigid bodies should work fine. Can you check the CcdPhysicsDemo and enable USE_KINEMATIC_GROUND?

Can you explain the problem more in detail, and help with a reproduction case?
Thanks for the feedback,
Erwin
eddybox
Posts: 25
Joined: Thu Nov 29, 2007 7:08 pm

Re: Several problems using Bullet

Post by eddybox »

Let's concentrate on the 2nd issue.

I have bodies that regularly switch back and forth between kinematic and dynamic, do I really need to change the mass around each time? Isn't that what the KINEMATIC/STATIC flags are for?

As for repro, I'll put a simple one together, but if you look at any constraint code (hingeconstraint for example) it's pretty clear. The computed impulse is split into two parts: one for bodyA and one for bodyB. If bodyB is kinematic for instance, that impulse has no effect; yet the combined impulse is designed based on the two inertias, and you only get "half convergence".

Thanks,
Eddy
eddybox
Posts: 25
Joined: Thu Nov 29, 2007 7:08 pm

Re: Several problems using Bullet

Post by eddybox »

Hi Erwin,

I have a few modifications to btRigidBody and CcdPhysicsDemo that can show what I'm referring to. But so as to not "waste" both our time, I'd like to check something with you first:

Is the zero-mass requirement for kinematic bodies really necessary? This strikes me as odd API-wise. In my case, I switch bodies back and forth between kinematic and simulated, and ideally, I'd like to leave the mass untouched when making this change. Of course, I can switch masses back and forth, but in that case, why bother with the kinematic flag at all? I can just set velocities manually at that point and be done with it. (Personally, I find this more intuitive than using the motion state, since it's consistent for all flag settings.)

In the interest of improving the API (for my use-case anyways), an alternative could be to modify the getInvMass/Inertia() methods to return 0 if the body is static/kinematic (while leaving the "real" mass unchanged). This "fools" the various constraint solvers to give consistent results. I've made this change locally and it seems to work well.

So... if you're interested in this change, I'll send the repro+code. If not, (your call of course,) I'll deal with the API as it is. (ie. swap my masses when changing modes.)

Thanks,
Eddy

ps. That said, for a really quick example, you can make the following changes in CcdPhysicsDemo.cpp:
- enable USE_KINEMATIC_GROUND
- and change
"
if (!isDyna)
mass = 0.f;

btRigidBody* body = localCreateRigidBody(mass,trans,shape);
#ifdef USE_KINEMATIC_GROUND
if (mass == 0.f)
"
to
"
if (!isDyna)
mass = 0.1f; //**** changed

btRigidBody* body = localCreateRigidBody(mass,trans,shape);
#ifdef USE_KINEMATIC_GROUND
if (!isDyna) //**** changed
"
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: CF_KINEMATIC_OBJECT/zero mass API question

Post by Erwin Coumans »

The dynamics system expects mass=0 for non-dynamic objects, and mass!=0 for dynamic objects. The flags were introduced separately, because we have a strict split between collision and dynamic system, and the collision system doesn't have access to mass information.

We rather not break the Bullet 2.x API unless it is really necessary. We can take this into account for Bullet 3.x, which breaks the API anyway.

Can you clear up the confusion: is it just an API inconvenience or do things just not work?
In other words: if you switch the mass back and forth (together with the CF_KINEMATIC_OBJECT flag), as intended, do things work fine?

Thanks for the feedback,
Erwin
eddybox
Posts: 25
Joined: Thu Nov 29, 2007 7:08 pm

Re: CF_KINEMATIC_OBJECT/zero mass API question

Post by eddybox »

Hi Erwin,

Thanks for your response.
Yes, it's just an API inconvenience. (At first I thought it was a "real" problem, but setting mass=0 solves it.)
So I'll work around it. But I think that it would be an improvement (possibly for 3.x) to remove the zero-mass-dependency for kinematic bodies to work correctly.

Thanks,
Eddy
Post Reply