moving btRigidBody to new position : rayTest issues [SOLVED]

nigul
Posts: 12
Joined: Tue Sep 22, 2009 1:40 pm

moving btRigidBody to new position : rayTest issues [SOLVED]

Post by nigul »

Hello,

I am currently using Bullet in order to have precise raycasting on various collision shapes in a 3D world. Rendering is done through Ogre3D.

3D objects are associated to an Ogre SceneNode and to a Bullet btRigidBody, both should always be at the same position.

When selecting a 3D object (with a mouse click), I perform a rayTest , and it works well. Then, the 3d object is moved (following the mouse mouvement) to a new position. the sceneNode coordinates are updated, the btRigidBody also seems to be moved (the center of mass coordinates do change)

in the following piece of code, _body is a btRigidBody *

Code: Select all

Vector3 pos = this->ogreSceneNode()->getPosition();

bt Transform btt;
this->_body->getMotionState()->getWorldTransform(btt);
btt.setOrigin(btVector3(pos.x,pos.y,pos.z)); // move body to the scene node new position

// update _body according to CharacterDemo demo

_body->getMotionState()->setWorldTransform(btt);
_body->setCenterOfMassTransform(btt);

when performing a new rayTest, only part of the btRigidBody is detected : the part that lies inside the initial bounding box

small picture to explain :
You do not have the required permissions to view the files attached to this post.
nigul
Posts: 12
Joined: Tue Sep 22, 2009 1:40 pm

Re: moving btRigidBody to new position : rayTest issues [SOLVED]

Post by nigul »

Few issues solved about this, maybe it can help :

in order to sync bullet & ogre objects, I just use the following :

update Ogre Scenenode from Bullet btRgidBody : just retrieve Origin and Rotation from btTransform and set Position and Orientation accordingly

update bullet btRigidBody from Ogre SceneNode : remove() btRigidBody from dynamicsWorld, update its transform (from MotionState) from Ogre Position (_getDerivedPosition) and Orientation(), add() modified btRigidBody to dynamicsWorld() and activate() it.

All works well by now !