Move rigid body.

Larles

13-08-2008 20:40:36

Hello,

I have a basic problem: I want to move an object after definning its rigidBody.
I tried to setPosition on its sceneNode but it seems that DynamicsWorld keeps position vectors updated internally. Defining position on the object sceneNode thanks to setPosition works only if DynamicsWorld is not updated via the stepSimulation method, but when stepSimulation is called another time, my object gets the position it has befor pausing DynamicsWorld.

Sorry I'm pretty noob on physics usage.
thanks,

nikki

14-08-2008 07:10:03

You mean you want to change the position of the SceneNode relative to the RigidBody? The best way to do this, IMHO, would be to attach your Entity to a child SceneNode of the SceneNode, and offset that. That way, only the parent SceneNode's position is updated, and the child SceneNode stays offsetted.

Larles

14-08-2008 15:13:51

hmm I gues I was not clear enough.
Look, I have a falling box for example. During its fall I want to say, ok box now, if I press the spacebar, I want you to go to coordinate X;X;X; and keep falling there (or not).
I tried to manage it as a classic Ogre::Entity, with something like
myBox->getParentNode()->setPosition(Vector3(X,X,X))


But it only works if the DynamicWorld is paused, because if I ask to set a new position during the fall, nothing happens.

nord666

14-08-2008 15:28:24

Hello,

Bullet uses "btTransform" to store position and rotation(maybe a bit more). So, why dont we change directly the position with Bullet? Here the code:


// If you use Ogre::Vector3 to store the position
Ogre::Vector3 position; //Have to be initialized
btTransform transform; //Declaration of the btTransform
transform.setIdentity(); //This function put the variable of the object to default. The ctor of btTransform doesnt do it.
transform.setOrigin(OgreBulletCollisions::OgreBtConverter::to(position)); //Set the new position/origin
body->getBulletRigidBody()->setWorldTransform(transform); //Apply the btTransform to the body

// If you dont use Ogre::Vector3
btTransform transform;
transform.setIdentity();
transform.setOrigin(btVector3(btScalar(0.0f/* x */), btScalar(0.0f/* y */), btScalar(0.0f/* z */)));
body->getBulletRigidBody()->setWorldTransform(transform);


You should put this code in a function to doesn't have to copy it again and again.

I hope that will help you!

P.S.: It's the only way i have found. I hope that using pure Bullet doesn't upset you.

Larles

14-08-2008 16:31:29

It works fine, thanks nord666.
I guess we'll have to use pure bullet even for basic stuff like that until we have a full documentation of ogrebullet :)

thanks again.

nord666

14-08-2008 16:37:09

nope for the help!

And yes, OgreBullet doesn't use all the power of Bullet, like SoftBody. It's why i use Bullet instead of OgreBullet. :wink:

nikki

15-08-2008 06:28:53

I just use OgreBullet to 'connect' the RigidBodies to the SceneNodes and keep them updated, that's all. Its a very thin layer. Its not a complete wrapper (like Ogre on DirectX or OpenGL). We still have to use raw Bullet. It would be useless to wrap absolutely every Bullet method into OgreBullet, maybe just the ones that a thin wrapper should have, like the position updates, and the mesh to convex conversion etc.