setWorldTransform to move btRigidBody does not work

Post Reply
Xemame
Posts: 8
Joined: Mon Dec 20, 2010 3:47 pm

setWorldTransform to move btRigidBody does not work

Post by Xemame »

Hello!

I am using Bullet with Cubes and I display them with Ogre3D.
They move as they should do.

The problem appears when I move one of them: I put Origin and Rotation in a btTransform Trans (with setOrigin and setRotation) and then I apply getMotionState()->setWorldTransform(Trans) to the btRigidBody of the cube. Checking its position with getMotionState()->getWorldTransform after this, I see the position has changed.

However, the cube still moves has if it was at its previous position: if I put it in the air, it does not fall. If an other cube was on it, the other cube does not fall either, as if there still were the moved cube under it. :shock:

Somebody has an idea of what I am doing wrong?
Thanks!!!
serengeor
Posts: 22
Joined: Mon Dec 20, 2010 7:13 pm

Re: setWorldTransform to move btRigidBody does not work

Post by serengeor »

I had the same problem when I experimented with bullet and Irrlicht engine.

I had two cubes, one on top of the other.
If I removed the bottom one while the top one is deactivated, the top one stays in air.
I don't really know how to solve this problem, I guess you could activate all of them but that would decrease the performance I think.
pico
Posts: 229
Joined: Sun Sep 30, 2007 7:58 am

Re: setWorldTransform to move btRigidBody does not work

Post by pico »

You can try to use a Kinematic body if you want to udpate the position frequently.
Another option is to call "UpdateSingleAabb" from the btDiscreteDynamicsWorld (after you changed the transform).
Xemame
Posts: 8
Joined: Mon Dec 20, 2010 3:47 pm

Re: setWorldTransform to move btRigidBody does not work

Post by Xemame »

Hello!

In my scene, I have a big cube with a null mass (so it is static?) and cubes laying on it with a non null mass (so they are dynamics?).

My first try failed: I was doing UpdateSingleAabb on every RigidBody before every stepSimulation (I know it is not good for performances, it was just for the test). When I moved the big cube, the others stay in the air, as if they were still on the big cube. When I moved a small cube in the air, it did not fall. :(

My second try was successfull. I made the big cube as a kinematic objet with

Code: Select all

rb->setCollisionFlags(rb->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
rb->setActivationState(DISABLE_DEACTIVATION);
as describes in http://www.bulletphysics.org/Bullet/php ... f=9&t=3382

When I moved the big cube, the small cubes felt :D

I have some questions left:
  • is it the good way to make a kinematic object?
  • Do I have to change the speed of the kinematic objects in order to have realistic collisions? Do I have to change something else?
  • what are static and kinematic objets? bullet does not make them moving, but they collide with other objects? Bullet reads the position from the motionState of the kinematics, but not the one of the static?
  • what is rb->setActivationState(DISABLE_DEACTIVATION); for?
  • why is UpdateSingleAabb not working? is something wrong in my code?
  • how can i move dynamics objets? (the one with a non null mass)
Thank you for your answers!!!
Xemame
Posts: 8
Joined: Mon Dec 20, 2010 3:47 pm

Re: setWorldTransform to move btRigidBody does not work

Post by Xemame »

I found this in the Bullet user manual, page 24 (google was not my friend this time, it failed to find it :wink: )
If you plan to animate or move static objects, you should flag them as kinematic. Also disable the sleeping/deactivation for them during the animation. This means Bullet dynamics world will get the new worldtransform from the btMotionState every simulation frame.
body->setCollisionFlags( body->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
body->setActivationState(DISABLE_DEACTIVATION);
Now I know the good method to make a kinematic object, but the Bullet user manual does not inform if the speed of a kinematic object (or another thing) must be changed when its position changed, in order to have good collision with dynamic objects.

Somebody has information about this?

Thanks!
Post Reply