Game Development Reference
In-Depth Information
Excerpt from src/contacts.cpp
// Calculate the acceleration-induced velocity accumulated this frame.
real velocityFromAcc = body[0]->getLastFrameAcceleration() *
duration * contactNormal;
if (body[1])
{
velocityFromAcc -= body[1]->getLastFrameAcceleration() *
duration * contactNormal;
}
// If the velocity is very slow, limit the restitution.
real thisRestitution = restitution;
if (real_abs(contactVelocity.x) < velocityLimit)
{
thisRestitution = (real)0.0f;
}
// Combine the bounce velocity with the removed
// acceleration velocity.
desiredDeltaVelocity =
-contactVelocity.x -
thisRestitution * (contactVelocity.x - velocityFromAcc);
I have placed this series of operations in its own method, calculateDesired-
DeltaVelocity , which is called as part of the calculateInternals method. This is
preferable to having the calculations performed each time the velocity resolver tries
to find the most severe collision.
This approach removes almost all the visible vibrations in the cyclone physics
engine. One of the optimization techniques we'll meet in the next chapter removes
the rest.
15.3
T YPES OF F RICTION
I've mentioned friction several times throughout the topic, and now it's time to tackle
it head on.
Friction is the force generated when one object moves or tries to move in con-
tact with another. No matter how smooth two objects look, microscopically they are
rough, and these small protrusions catch one another, causing a decrease in the rela-
tive motion or a resistance to motion beginning.
Friction is also responsible for a small part of drag, when air molecules try to
move across the surface of an object. (Drag has a number of different factors, such as
turbulence, induced pressure, and collisions between the object and air molecules.)
Search Nedrilad ::




Custom Search