Setting center of mass causes wobbling

I want to add geometry to a physics node, off centered, and then use the setCenterOfMass() method to correct for that.

However, I'm finding that calling setCenterOfMass() causes my physics node to wobble oddly after it falls to the floor.



This code should produce the problem.


  public class CenterTest extends SimplePhysicsGame {

      protected void simpleInitGame() {        
           StaticPhysicsNode staticNode = getPhysicsSpace().createStaticNode();
           rootNode.attachChild( staticNode );

           final Box visualFloorBox = new Box( "floor", new Vector3f(), 5, 0.25f, 5 );
           staticNode.attachChild( visualFloorBox );
           staticNode.generatePhysicsGeometry();

           DynamicPhysicsNode dynamicNode = getPhysicsSpace().createDynamicNode();
           rootNode.attachChild( dynamicNode );

           final Box visualFallingBox = new Box( "falling box", new Vector3f(), 0.5f, 0.5f, 0.5f );
           visualFallingBox.getLocalTranslation().set(-4,0,0);  //make the box off centered
          
           dynamicNode.attachChild( visualFallingBox );
          
           dynamicNode.generatePhysicsGeometry();
      
           dynamicNode.setCenterOfMass(new Vector3f(-4,0,0));  //set the center of mass to correct for the off center box

           dynamicNode.getLocalTranslation().set( 0, 5, 0 );
          
           showPhysics = true;
       }

       public static void main( String[] args ) {
           new CenterTest().start();
       }
}



Am I doing something wrong?

The best would be to avoid setCenterOfMass, as the current implementation is a workaround because ODE does not really support changing the center of mass. I fixed the problem you encountered, though, as it really was a bug.

Thanks for the advice, much appreciated