Box stacking

Started by
39 comments, last by Dirk Gregorius 8 years, 8 months ago

Hi guys,

I'm trying to get stable box stacking with my physics engine. I use an accumulated impulse model but I dont pre-apply last accumulated impulse at the beginning of each timestep, basically I don't have a preStep function as in box2d lite. Actually, I tried to implement it but it made the simulation totally unstable. I create persistent contact manifolds by checking contact proximity at each step, I use something like;


if (contact.position.distanceToSquared(contacts[i].position) <= 0.004) {
      // Use previous contact impulses
}

My allowed penetration is 0.01 and bias is 0.1, iteration 10.

At each iteration I calculate impulses like this;


// Normal Impulse
deltaNormalImpulse = c.massNormal * (-vn + c.bias)
oldImpulse = c.normalImpulse;
c.normalImpulse = Math.max(oldImpulse + deltaNormalImpulse, 0.0);
deltaNormalImpulse = c.normalImpulse - oldImpulse;

// I use the same approach for calculating the tangent and binormal impulses
deltaTangentImpulse = c.massTangent * (-vt);
maxTangentImpulse = 0.6 * c.normalImpulse;
oldTangentImpulse = c.tangentImpulse;
c.tangentImpulse = clamp(oldTangentImpulse + deltaTangentImpulse, -maxTangentImpulse, +maxTangentImpulse);
deltaTangentImpulse = c.tangentImpulse - oldTangentImpulse;

deltaBinormalImpulse = c.massBinormal * (-vb);
maxBinormalImpulse = 0.6 * c.normalImpulse;
oldBinormalImpulse = c.binormalImpulse;
c.binormalImpulse = clamp(oldBinormalImpulse + deltaBinormalImpulse, -maxBinormalImpulse, +maxBinormalImpulse);
deltaBinormalImpulse = c.binormalImpulse - oldBinormalImpulse;

and here is the result;

https://vimeo.com/135466972 (Watch on vimeo for HD version)

Box stacking is not stable, they fall down in the long run. By the way, sleeping is not enabled in this demo, but I think it should be stable without sleeping, isn't it?

Waiting for your tips.

Thanks, Uza

Advertisement

This is a friction problem which is usually solved with warmstarting. I recommend giving it another try and debug what is going wrong

Try this:

A vertical stack of 5 boxes of 0.05km/^3 using 5 iterations, without contact caching, nor sleeping, nor any damping. The boxes should slide of the top of each other approx. after 6 seconds.

Later try only with contact caching enable. The vertical stack should be stable. Otherwise you have bug somewhere.


Also make sure that the ground inertia tensor is a zero matrix (not the identity).

Irlan, the inertia tensor for the ground is a zero matrix. Warm starting seems to be correct but I just saw this post of Dirk http://www.gamedev.net/topic/613945-sequential-impulse-bias-velocities/#entry4878940 where he mentions projecting the last friction impulse onto the new friction directions. I don't do this. This might be the source of the problem?

I am not sure if this is your problem, but I doubt it would make such a difference that it gets less stable.

I said about the Inertia just for precaution.

Like Dirk said, old friction solutions wouldn't solve your problem.

Seeing your video I remember this behaviour occurred when NOT using contact caching. Therefore, you may check how you're computing the tangential directions and velocity.

If you don't pre-apply the last accumulated impulse you don't have warm-starting.

I think I'm doing it wrong. Do I need to copy tangents along with impulses when caching contact data?

I just tried stacking spheres and it was extremely stable. No problem there, so is this an indication that the source of the problem is in the contact manifold generation for boxes?

Each contact point holds the normal and tangential impulses;
Before a manifold generation, make a copy of the old manifold;
If there is a match between the manifold contact points then copy the normal impulse and project the old manifold tangential impulses on the new tangential directions;
Apply the old impulses one time (that is, warm-start the solver);
Apply new impulses for how many iterations you want updating the accumulated impulses during the iterations;

Basically, thats all needed.

Test your colllision detection routine separately for a box pair drawing the contact points and normal persistently.

This topic is closed to new replies.

Advertisement