Game Development Reference
In-Depth Information
// And process them.
if (calculateIterations) resolver.setIterations(usedContacts * 2);
resolver.resolveContacts(contacts, usedContacts, duration);
}
We a d d a c a l l t o startFrame at the start of each frame of the game, and a call to
runPhysics wherever we want the physics to occur. A typical game loop might look
like this:
void loop()
{
while (1) {
// Prepare the objects for this frame.
world.startFrame();
// Calls to other parts of the game code.
runGraphicsUpdate();
updateCharacters();
// Update the physics.
world.runPhysics();
if (gameOver) break;
}
}
8.2
U SING THE P HYSICS E NGINE
We will look at a useful application of the mass-aggregate engine: creating structures
out of particle masses and hard constraints. Using this technique we can create and
simulate many larger objects. The possibilities are endless: crates; mechanical devices;
even chains and vehicles; or, with the addition of springs, soft deformable blobs.
8.2.1
R OPE -B RIDGES AND C ABLES
Sagging bridges, cables, and tilting platforms are all stalwarts of the platform game
genre, as well as having applications in other genres.
We can set up a bridge using pairs of particles suspended by cables. Figure 8.1
shows an arrangement that has this effect. Each pair of particles along the bridge is
linked with a rod constraint to keep them connected with their neighbors. Pairs of
Search Nedrilad ::




Custom Search