Game Development Reference
In-Depth Information
There are two components to the sleep system: one algorithm to put objects to
sleep and another to wake them up again. We will look at both, after putting in place
some basic structure to support them.
Adding Sleep State
To support sleep we need to add three data members to the RigidBody class:
isAwake is a boolean variable that tells us whether the body is currently asleep,
and therefore whether it needs processing.
canSleep is a boolean variable that tells us if the object is capable of being
put to sleep. Objects that are under the constant control of the user (i.e., the
user can add forces to them at any time) should probably be prevented from
sleeping, for visual rather than performance reasons.
motion will keep track of the current movement speed (both linear and angu-
lar) of the object. This will be crucial for deciding if the object should be put
to sleep.
In the RigidBody classthisisimplementedas
Excerpt from src/body.cpp
class RigidBody
// ... Other RigidBody code as before ...
* Holds the amount of motion of the body. This is a recency-
* weighted mean that can be used to put a body to sleep.
real motion;
* A body can be put to sleep to avoid it being updated
* by the integration functions or affected by collisions
* with the world.
bool isAwake;
* Some bodies may never be allowed to fall asleep.
* User-controlled bodies, for example, should be
* always awake.
bool canSleep;
Search Nedrilad ::

Custom Search