379
23
AJitter‐TolerantRigidBody
SleepCondition
Eric Lengyel
Terathon Software
23.1Introduction
One of the primary optimizations employed by any physics engine is the ability
to put a rigid body to sleep when it has reached a resting state. A sleeping rigid
body is not processed by the physics engine until some kind of event occurs, such
as a collision or broken contact, necessitating that it is woken up and simulated
once again. The fact that most rigid bodies are in the sleeping state at any one
time is what allows a large number of simulated objects to exist in a game level
without serious performance problems.
A problem faced by all physics engines is how to decide that a rigid body has
actually come to rest. If we put an object to sleep without being sure that it has
come to rest, then we risk accidentally freezing it in mid-simulation, which can
look odd to the player. On the other hand, if we are too conservative and wait for
too strict of a condition to be met before we put an object to sleep, then we can
run into a situation where too many objects are being simulated unnecessarily
and performance suffers.
The sleep decision problem is complicated by the fact that all physics en-
gines exhibit some jitter no matter how good the constraint solver is. If the right
sleep condition isn’t chosen in the design of a physics engine, then jitter can pre-
vent an object from ever going to sleep. Or at the very least, jitter can delay an
object from entering the sleep state, and this generally causes a higher number of
objects to be simulated at any given time. This chapter discusses a simple condi-
tion that can be used to determine when it is the proper time to put a rigid body to
sleep, and it is highly tolerant to jitter.
Get Game Engine Gems 2 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.