Rigid body restitution value.

Raven
Posts: 5
Joined: Wed May 04, 2011 5:49 pm

Rigid body restitution value.

Post by Raven »

Hi everyone,

When I look at the btrigidbody constructor I see it has a default value of 0.0 for restitution and is comment as "best for simulation behavior". However this is not the value that I need, and I kinda find it strange that there is no function to change this value internally or externally. So I modified the value directly, it works as intended most of the time, except for the value of 1.0.

According to my understanding, restitution of 1.0 mean you always get back 100% of initial force/velocity after collision, correct? However this is what I noticed, say if I start with a velocity of 30, I noticed after a while it will become -31, 33, -37, 48, -60, 90 ...etc... and so on until it explodes (the timestep can no longer catch the collision in time). Is the increase in velocity is due to some rounding error or restitution value is working differently then I how I thought it should?
bitshifternz
Posts: 6
Joined: Sun Apr 17, 2011 11:19 pm

Re: Rigid body restitution value.

Post by bitshifternz »

btRigidBody's base class btCollisionObject has setRestitution and getRestitution methods.

I was recently fiddling with restitution and got varying results depending on what collision algorithm was being used. A box colliding with another box worked as expected but a sphere colliding with a box didn't. These use different collision algorihms internally which I'm assuming is the reason for the different behaviour.

What collision shapes are you using?
Raven
Posts: 5
Joined: Wed May 04, 2011 5:49 pm

Re: Rigid body restitution value.

Post by Raven »

I didn't know they are in the collisionshape file, I'll have to look at that.

But so far, it doesn't matter what shape I'm using, sphere, box, compound they all behave the same when I set the restitution value inside the btrigidbody constructor to 1.0. If I have to describe the change in velocity, they explode in a way that similar to a Mass Spring system that explode (diverge) due to wrong timestep.

Edit: come to think of it ...

Basically what I'm doing is that I'm letting 2 objects collide inside a box, the 2 objects are dynamic rigidbodies while the box are constructed with static (0-mass) rigidbodies. I think the object to object collision is fine, but it's when they collide with the walls of the boxes that their velocity change drastically.

Edit #2:
by the way, if restitution is something that is set in collisionshape which is also the parents of softbody, does this mean it will also affect softbody collision as well? (Since so far I thought it only applies to rigidbody).
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Rigid body restitution value.

Post by Mako_energy02 »

Restitution is not on the shape, it's on the base class btCollisionObject.

http://bulletphysics.com/Bullet/BulletF ... bject.html

I'm not positive about this, but I think restitution may be like friction where the total force is calculated by the coefficients of both colliding bodies. So a restitution value of 1.0 on both bodies may result in added force. Just a theory, I haven't fiddled enough with restitution myself to say with confidence.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Rigid body restitution value.

Post by dphil »

I'm not positive about this, but I think restitution may be like friction where the total force is calculated by the coefficients of both colliding bodies
Yes I believe that is correct. The combination appears as though it should be multiplicative (for ex. if one has a restitution of 0 and the other has 1, the behaviour seems to be as if both have 0), however there does indeed seem to be added force if both are set to 1. Playing around with the values in my simulation, I found that to get an object to bounce on the ground back to roughly it's exact starting height, I need to set the ground's restitution to 1, and the object's to around 0.92. I'm guessing there is some error involved in the calculations (unless it is meant to behave this way, which seems a bit odd).

On a side note, there also seems to be instability in the torque on a "bouncing" object. After a couple bounces my objects often start spinning around wildly even though they are bouncing no a flat ground with nothing but gravity acting on them. Perhaps there is some numerical error in the local point on the object to which the rebounding force is applied.
bitshifternz
Posts: 6
Joined: Sun Apr 17, 2011 11:19 pm

Re: Rigid body restitution value.

Post by bitshifternz »

dphil wrote:On a side note, there also seems to be instability in the torque on a "bouncing" object. After a couple bounces my objects often start spinning around wildly even though they are bouncing no a flat ground with nothing but gravity acting on them. Perhaps there is some numerical error in the local point on the object to which the rebounding force is applied.
What collision shapes are you colliding? I get different results with different collision algorithms. With btBoxBoxCollisionAlgorithm I get a nice bounce but with btConvexConvexAlgorithm I don't. You can override the collision algorithm for different shapes with btCollisionDispatcher::registerCollisionCreateFunc. If you drop a box on a box ground with restitution of 1 on each you'll get a nice bounce. If you use btCollisionDispatcher::registerCollisionCreateFunc to override the collision algorithm for BOX_SHAPE_PROXYTYPE vs BOX_SHAPE_PROXYTYPE colliisions to use btConvexConvexAlgorithm you'll see the restitution behaviour is a lot less stable than it was using btBoxBoxCollisionAlgorithm.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm

Re: Rigid body restitution value.

Post by dphil »

I was dropping a box on a box ground (ie both rigid bodies with btBoxShapes, ground with mass set to 0, dropped box with mass set to 1), using whatever the default algorithm is (box-box, I guess). Interesting that your results seem to be correct/stable while mine are unstable.