Game Development Reference
In-Depth Information
When we come to perform the rigid-body update, we check the body and return
without processing if it is asleep:
void RigidBody::integrate(real duration)
if (!isAwake) return;
// ... Remainder of the integration as before ...
The collision detector should still return contacts between objects that are asleep, as
we'll see later in this section. These dormant collisions are important when one object
in a stack receives a knock from an awake body.
Despite collisions being generated, when two objects are asleep, they have no ve-
locity or rotation, so their contact velocity will be zero and they will be omitted from
the velocity resolution algorithm. The same thing happens with interpenetration.
This provides the speed-up in the collision response system.
We need to add a method to the RigidBody class that can change the current state
of an object's isAwake member. The method looks like this:
Excerpt from src/contacts.cpp
void RigidBody::setAwake(const bool awake)
if (awake) {
isAwake= true;
// Add a bit of motion to avoid it falling asleep immediately.
motion = sleepEpsilon*2.0f;
} else {
isAwake = false;
This code toggles the current value of isAwake . If the body is being put to sleep, it
makes sure it has no motion: both linear and angular velocity are set to zero. This
makes sure collisions (as we saw before) have no closing velocity, which improves
performance for sleeping bodies in contact.
If the body is being awakened, then the motion variable is given a value. As we'll
see in the next section, an object is put to sleep when the value of this motion drops
below a certain threshold. If the value of this variable is below the threshold, and the
Search Nedrilad ::

Custom Search