Unstable Stacked tower

88Alex88
Posts: 5
Joined: Tue Apr 12, 2011 3:23 am

Unstable Stacked tower

Post by 88Alex88 »

Hi,
im doing a project using Bullet and Ogre.
I have advanced pretty much in using Bullet, but im having some trouble being able to have a tower made of btBoxShape stable.

To step the simulation, i do:

Code: Select all

if (fisicTimer.getMilliseconds() > 17){
dynamicsWorld->stepSimulation(fisicTimer.getMilliseconds()/1000.0f*velocidadSimulacion,10);
fisicTimer.reset();
}
And to create the tower, i use:

Code: Select all

fallShape = new btBoxShape(btVector3(1, 1, 1));
and

Code: Select all

collShape->calculateLocalInertia(mass,inertia); //mass = 1
    btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,motionState,collShape,inertia);
    body = new btRigidBody(fallRigidBodyCI);
    body->setFriction(friction); //friction = 0.9
    body->setRestitution(restitution); //restitution = 0.3
    body->setDamping(0.1, 0.1);
    dynamicsWorld->addRigidBody(body);
and to stack them, i give them the position btVector3(0, i*2+1, 0).

When I launch the simulation, the tower is like a little bouncy, and eventually it falls. If the blocks are made with btBoxShape(btVector3(10, 10, 10)) the tower stays stable, but i need to know why i cant use the previous size.

If you see something strange in the code, or have any idea of what could be making my simulation unstable, please, let me know. If you need any more information about my code, let me know.
Thanx :)
bimmy47
Posts: 6
Joined: Thu May 26, 2011 8:36 pm

Re: Unstable Stacked tower

Post by bimmy47 »

Hopefully someone with more experience will know for sure, but I believe I read that it has to do with the internal floating point precision. Basically (hopefully I am not mangling this) there is a collision buffer of 4cm around each cube which helps to speed things up ordinarily. When stacking cubes of 10m this 4cm buffer has little impact on the simulation, but when stacking cubes of only 1m it becomes a 4% margin of error (I think) and the calculated positions are less stable (again, I think). Now as to how to resolve that, I have read of several approaches to modifying bullet's scale in order to work well with small objects, and I have also read that you can modify the value for the collision buffer. As to which of these is best, I have no idea. Otherwise, you might also try calling btRigidBody->setActivationState(WANTS_DEACTIVATION) for each body during initialization. I don't know if this will work, but it seems like putting the cubes to sleep until they are bumped should make the tower stable.

EDIT: There is definitely info in the manual on both the collision buffer and scaling the bullet world. Rather than take my shoddy advice you are probably better off checking that out. ;)

EDIT 2: Sorry, the word I should have been using is collision margin, not buffer.
88Alex88
Posts: 5
Joined: Tue Apr 12, 2011 3:23 am

Re: Unstable Stacked tower

Post by 88Alex88 »

Thanx for the answer bimmy, i will take a look at that. If i find something usefull, that solves my problem, i will write it here.

Thanx again :)