Implementing Sleep/Wake systems

Please don't post Bullet support questions here, use the above forums instead.
colinvella
Posts: 24
Joined: Sat Feb 09, 2008 2:38 pm
Location: Malta

Implementing Sleep/Wake systems

Post by colinvella »

I have a sleep/wake system in my own physics engine implementation that works as follows:

1) Track activity of objects, if activity within a threshold E for a period T, then the object is stabilised (V = W = 0) and marked as Sleeping
2) If an Active body collides with or touches a Sleeping Body, the latter will be marked as activated and the threshold time period reset

Note: No collisions between any two sleeping objects performed. Also, no kinetic integration for sleeping objects is performed. Activity function is V * V + W * W where V and W are the linear and angular velocities respectively. Finally, E and T are tunable parameters that control the aggressivness of the sleep/wake system.

The approach above has speeded up my simulation substantially, at least when bodies start settling in a stationary configuration.

I am however experiencing a problem as illustrated by the following example:
Imagine a stack of boxes that is eventually marked as sleeping. Now throw another body towards the lower portion of the stack. The collision causes a train of activations throughout the bodies, but this does not occur all the way up the stack because some boxes will simply drop away from the ones above without triggering a collision. This results in a number of stationary boxes floating in mid-air, still marked as sleeping.

The only solution that comes to mind is to still report intersection between adjacent boxes and track separation from one simulation step to the next. This may still not work in some cases as boxes in a stack may have settled very close to each other but not necessarily interpenetrating.

I'd like to hear your appraoches to this problem.
Thanks
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: Implementing Sleep/Wake systems

Post by bone »

I haven't implemented such a solution, but you might instead store of the existing collisions at the time you go to sleep (this would be per-object storage). So while you are sleeping, you don't do any extra work or reporting of intersections. Then when you wake an object up, you "activate" or check all those collisions you stored and activate any opposing objects.
colinvella
Posts: 24
Joined: Sat Feb 09, 2008 2:38 pm
Location: Malta

Re: Implementing Sleep/Wake systems

Post by colinvella »

I'll consider your idea, thanks! It might cause more "awakenings" than my current implementation, although it is definitely more preferable than having boxes forzen in mid-air.