Center of Mass Offset

stevenLD
Posts: 10
Joined: Fri Sep 14, 2007 1:27 am

Center of Mass Offset

Post by stevenLD »

I want to change the center of mass of my btRigidBody object. My RigidBodies are comprised of a CompoundShape each having one or more offset box- or sphere-shapes. I read a post that said the center of the btRigidBody is always the center of mass. I've also found setCenterOfMassTransform and btMotionState.m_centerOfMassOffset.

So, its the end of the day, and I'm totally burned out. What is the appropriate way to change the center of mass of a btRigidBody?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Center of Mass Offset

Post by Erwin Coumans »

What is the appropriate way to change the center of mass of a btRigidBody?
The center of mass is the center of the btRigidBody. So if you want to shift the center of mass, you need to shift the collision shapes, and graphics rendering the opposite way. You can use a btCompoundShape to shift the collision child shapes. Also, you need to correct the center of mass graphically. The motion state has some helper functionality to make this easier.

Would be nice if there would be some demo/documentation to clarify this further.
Thanks,
Erwin
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: Center of Mass Offset

Post by pico »

The center of mass is the center of the btRigidBody. So if you want to shift the center of mass, you need to shift the collision shapes, and graphics rendering the opposite way. You can use a btCompoundShape to shift the collision child shapes. Also, you need to correct the center of mass graphically. The motion state has some helper functionality to make this easier.
Has the center of mass in Bullet any computational influence? When using "body->setCenterOfMassTransform(0,-0.5,0)" on a standard cube the behaviour doesn't change to me. As you describe above, the cube got just an offset.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Center of Mass Offset

Post by Erwin Coumans »

pico wrote:
Has the center of mass in Bullet any computational influence? When using "body->setCenterOfMassTransform(0,-0.5,0)" on a standard cube the behaviour doesn't change to me.
You have to offset/shift the graphics and collision shapes, instead of the rigid body: there is no center of mass _offset_ or shift in a rigid body. The setCenterOfMassTransform sets the world transform for a rigid body, which is always equal to the center of mass of the rigid body in world space. So instead of shifting the rigid body, you need to shift the graphics and collision shapes.

To shift the collision shapes, please check out CcdPhysicsDemo, and enable CENTER_OF_MASS_SHIFT. To shift the graphics transform, use the btDefaultMotionState, it has a centerOfMassOffset.

As I mentioned before, having a sample/demo would make this easier.
Thanks,
Erwin