Modeling a dice in a cup

rcharlton
Posts: 6
Joined: Wed Jun 10, 2009 1:36 pm

Modeling a dice in a cup

Post by rcharlton »

I'm trying to simulate a dice in a cup.

The dice is a chamfer-box constructed from a multi-sphere of 8 spheres. The cup is a compound object of 6 large boxes positioned to create a central chamber. It is flagged as a kinematic object which the user freely rotates.

The dice is 1.5 unit cube, mass 1. The cup is 5 x 7.5 x 5 and its boxes are 200 unit cubes.

This basically works but suffers from the following problems:
The dice occasionally receive very large (> 100) impulses. In this instance the dice can penetrate the cup and either escape completely or be shot backwards and penetrate the opposite box. Performance then drops significantly which I suspect compounds the problem.
When at rest the dice also intermittently penetrates and also 'floats' over the cup.

I'm running 1.75-rc3 on an iPhone so am limited to a 30hz update.

I'd appreciate any advice in how I might alleviate these problems.

Things I've tried so far are:
1. Making the cup's boxes extremely large.
2. Setting setCcdMotionThreshold and setCcdSweptSphereRadius on the dice.
3. Clamping the dice's impulse (to max 50) in the simulation tick callback.
4. Increasing/decreasing the maximum steps per update.
5. Conversely increasing/decreasing the step size.

Thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Modeling a dice in a cup

Post by Erwin Coumans »

It is not clear from the description what causes this massive impulse.

Bullet works best if your units are in meters, so it is best to change the units instead of using a 7.5 meter cup...

You might want to try to keep the cup static, and change the gravity/camera transforms instead.
Thanks,
Erwin
rcharlton
Posts: 6
Joined: Wed Jun 10, 2009 1:36 pm

Re: Modeling a dice in a cup

Post by rcharlton »

Thanks for the reply.

The interaction of the kinematic cup with the dice within Bullet creates the impulse. No other forces are applied externally. I'm driving the rotation of the cup from the phone's accelerometer so the cup's up vector = -gravity. Although this is sampled at 30hz it can produce some very rapid orientation changes.

Unfortunately keeping the cup static wouldn't produce the simulation I require since then the dice would only be moved by gravity and not the cup.

Thanks
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Modeling a dice in a cup

Post by Erwin Coumans »

Have you tried smoothing the change in gravity vector?
You could try to compute the linear/angular velocity of the previous and current gravity vector, and clamp the linear/angular velocity to a maximum.

The strong impulse might be due to penetration recovery. Could you try to use the split impulse feature, in the latest Bullet 2.75 RC3?

Code: Select all

dynamicsWorld->getSolverInfo().m_splitImpulse = true;
Is it really necessary to force 30hertz updates? It is best to stick to 60 hertz using stepSimulation(deltaTimeInSeconds), not providing 2nd and 3rd argument.
Thanks,
Erwin