Center of mass World Transform for compound shapes

STTrife
Posts: 109
Joined: Tue May 01, 2012 10:42 am

Center of mass World Transform for compound shapes

Post by STTrife »

Hi there, I have (beginners) question about the world transform of compound shapes.
It sais in the manual that "The world transform of a rigid body is in Bullet always equal to its center of mass"

What exactly does mean in practice? In my situation I would create a compoundshape, and add some child shapes. Chances are big, my center of the compound shape, is not the same as the center of mass of the object.

When I create the object I have to pass a motionstate, with a worldtransform. Is the center of my compoundshape positioned at that point, or is the objects center of mass positioned at that point?

And if this isn't the case, what happens after that? Does bullet immediatly change the the world transform to match the center of gravity? And does it then also update the child's motion state to match this new worldtransform of their parent, or .. ?

What I do now:

I create a motion state for the compoundshape
I create a compound shape
#For each child shape:
I create a motionstate for the child object (I feel like I wouldn't have to do this, cause the local position/rotation of the child shape should never change right?)
I remember how much mass the child shapes add (totalmass+=childmass)
I create a collisionshape for the child
I add it to the compound shape
#endfor
I call calculateLocalInertia on the compound shape, using totalmass
I make a ConstructionInfo
I make the body
I add the body

So what exactly happens to the worldtransforms in the motionstates of the compound, and of the children? Or does nothing happen and do I have a problem cause my worldtransform of the compound is not at the center of mass of the object?

Thanks a lot for any help!
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: Center of mass World Transform for compound shapes

Post by Flix »

STTrife wrote:my center of the compound shape, is not the same as the center of mass of the object.
AFAIK, Bullet does not know and does not try to calculate the center of mass of the compound shape you pass to it: it just takes the point (0,0,0) in that shape and makes it the center of mass of your shape.
If you need to move it from there, you can shift all the child shapes inside the compound shape, or you can just create a new compound shape and add as a child shape the old compound shape shifted by an offset.
STTrife wrote:When I create the object I have to pass a motionstate, with a worldtransform. Is the center of my compoundshape positioned at that point, or is the objects center of mass positioned at that point?
The object center of mass [(0,0,0) inside the compound shape] is positioned at that point.
STTrife wrote:I create a motionstate for the child object (I feel like I wouldn't have to do this, cause the local position/rotation of the child shape should never change right?)
:? Maybe I'm missing something here... Motion states can be applied to btCollisionObjects (or more frequently to btRigidBodies): the children of a compound shape are btCollisionShapes (unless you extend the btCompoundShape class...); I suppose you're trying to inglobe existing rigid bodies into an existing btCompoundShape.
STTrife wrote:Or does nothing happen and do I have a problem cause my worldtransform of the compound is not at the center of mass of the object?
The latter as far as I know. But you can shift the center of mass inside the btCompoundShape manually and then update the local inertia.
There's a demo posted by Erwin you can download from here that can be useful: http://bulletphysics.org/Bullet/phpBB3/ ... shift+demo