How to set the object's world position in bullet?

In my Ogre3d application I am first changing the parent of a node like this:

// save object "Cube" into node*; then ...
Vector3 absPos(node->_getDerivedPosition());
Quaternion absOrient(node->_getDerivedOrientation());
node->getParent()->removeChild(node);
node->_setDerivedPosition(absPos);
node->_setDerivedOrientation(absOrient);


The idea is that after the parent node has been changed the object's position and orientation should remain the same. However, even though this is working fine, it seems that afterwards bullet is again overwriting the object's position. If I remove the object's rigid body from bullet, then everything works fine. If not, then as soon as I change the parent the object's position is changed.

So I thought I simply need to update bullet as well:

btRigidBody* rigid = getBtRigid(String("Cube"));
btTransform tr = rigid->getWorldTransform();
tr.setOrigin(BtOgre::Convert::toBullet(absPos));
tr.setRotation(BtOgre::Convert::toBullet(absOrient));
rigid->setWorldTransform(tr);


However, that doesn't work, the object still jumps to another position after the parent is changed. But it is related to bullet for sure, because as said if I remove the object from bullet physics, then it works.

Any ideas what I am missing here?

I would try updating the motion state transform as well, since it's a rigid body:

btRigidBody* rigid = getBtRigid(String("Cube"));
btTransform tr = rigid->getMotionState()->getWorldTransform();
tr.setOrigin(BtOgre::Convert::toBullet(absPos));
tr.setRotation(BtOgre::Convert::toBullet(absOrient));
rigid->getMotionState()->setWorldTransform(tr);


You should check your physics update loop, how are you handling rigid bodies and their corresponding scene nodes? I update mine like so:

btVector3 pos = body->getCenterOfMassPosition();
node->setPosition((float)pos[0], (float)pos[1], (float)pos[2]);

btQuaternion orientation = body->getOrientation();
node->setOrientation(Ogre::Quaternion(orientation.w(), orientation.x(), orientation.y(), orientation.z()));


Also, if you don't already, you should use the BtOgre debug drawer, it's really helpful for things like this.

• No, unfortunately setting the motion state does not change anything in my case. Also, I don't want to update the Ogre node from bullet, but vice versa. – Matthias Jul 7 '13 at 13:58

Found the problem: I forgot to update the bullet motion state. After removing the rigid from bullet and re-adding it with the updated motion state it works now.

• What do you mean "update the bullet motion state?" – Blue Wizard Jul 7 '13 at 18:05
• I create a new RigidBodyState object via new BtOgre::RigidBodyState(movedNode);, then I use this new object in the creation of a new bullet rigid body, as usual. – Matthias Jul 7 '13 at 22:02