Game Physics Engine Development: How to Build a Robust Commercial-Grade Physics Engine for your Game by Ian Millington

Kindle Print Replica

July 23, 2010
Publisher: CRC Press
ISBN: 978-0123819765

The Cyclone game engine featured in the book was written specifically for this book and has been utilized in iPhone application development and Adobe Flash projects. The companion website will include the full source code of the Cyclone physics engine, along with example applications that show the physics system in operation. 

Notes

The book covers the creation of a rigid-body, iterative, impulse-based physics engine. The engine supports particle effects, flight simulation, car physics, crates, destructible objects, cloth, and ragdolls. The source code is based on the GLUT toolkit, which wraps OpenGL in a platform-independent way.

Classical mechanics are the laws that govern how large objects move under the influence of gravity and other forces. This is the physics implemented in games: particle movement (bullets, sparks, fireworks, smoke, and explosions), flight simulation, automotive physics, rigid-body, soft-body (clothes, flags, ropes), ragdoll, fluid flow (water, fire, smoke).

If you are a one-person hobbyist working on your game in the evenings, then developing a complete physics solution might take your time away from improving graphics or game play.

Engines that simulate rigid bodies are called mass aggregate engines. They treat objects as a whole. A box might be simulated as if it were made up of eight masses, one at each corner, connected by rods. Mass aggregate engines are easier to program because they don't need to understand rotations. The equations of motion can be expressed purely in terms of linear motion. The whole object rotates naturally as a result of the connections between masses.

It is very difficult to make things truly rigid in a physics engine. Extra code is needed to reconstruct the rigid body from the slightly springy set of masses. This extra code may grow in size significantly. Fortunately, we can extend a mass aggregate engine into a full rigid-body system by adding rotations.

Contact resolution: One approach is to handle contacts one by one, making sure each works well on its own. This is called the iterative approach and it is very fast. The downside is that one contact can affect another, and sometimes these interactions can be significant. The iterative approach is the technique used in the physics engine built in this book. Another approach is to calculate the exact interaction between different contacts and determine an overall set of effects for all objects at the same time. This is a Jacobian-based approach and it is very time-consuming. A third option is to create our own set of laws for the specific configuration of objects. This is a reduced coordinate approach and it is used in engineering software to achieve accurate simulation. It is very slow.

The engine in this book uses impulses to resolve contacts. Think of impulses as a series of miniature collisions, rather than a constant force. Some other engines use forces for resting contacts and impulses for collisions.