How to update Bullet after a node change (in Ogre)?

haimat
Posts: 5
Joined: Thu Apr 18, 2013 12:03 pm

How to update Bullet after a node change (in Ogre)?

Post by haimat »

In my Ogre application I move one node from it's current parent to another parent like this:

Code: Select all

	Vector3 absPos(node->_getDerivedPosition());
	Quaternion absOrient(node->_getDerivedOrientation());
	node->getParent()->removeChild(node);
	m_pSceneMgr->getRootSceneNode()->getChild("NewParentNode")->addChild(node);
	node->_setDerivedPosition(absPos);
	node->_setDerivedOrientation(absOrient);
That is working fine. However, this node is also part of the Bullet physics world, and that is causing trouble for me. As soon as I change the parent node as shown above, the moved node does change its position in the world space (it "jumps" to this new positiion). I can solve this however by removing the according rigid body from the Bullet simulation via m_dynamicsWorld->removeRigidBody(). But since I need Bullet for this object, that is not really a solution in my case.

So the problem is somehow related to Bullet. I tried to solve it by doing this after changing the parent node:

Code: Select all

	btRigidBody* rigid = getBtRigid(String("Cube"));
	btTransform tr = rigid->getWorldTransform();
	tr.setOrigin(BtOgre::Convert::toBullet(absPos));
	tr.setRotation(BtOgre::Convert::toBullet(absOrient));
	rigid->getMotionState()->setWorldTransform(tr);
	rigid->setWorldTransform(tr);
Unfortunately, that didn't help in my case.
Any other ideas what I might be missing here?
haimat
Posts: 5
Joined: Thu Apr 18, 2013 12:03 pm

Re: How to update Bullet after a node change (in Ogre)?

Post by haimat »

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.