| |
| | ||||
![]() | ||||||
| | | |||||
|
Outsourcing Reality: Integrating a Commercial Physics Engine Licensing
rendering engines is now a well-established practice, with great potential
cost and time savings over the development of a single game. As game developers
reach for new forms of gameplay and a better process for implementing
established genres, the wisdom of licensing physics engines is becoming
inescapable. Commercial engines such as Havok and Mathengine's Karma (at
press time, Criterion Software, makers of the Renderware line of development
tools, were in negotiations to acquire Mathengine) have become mature
platforms that can save months in development and test. Their robust implementations
can provide critical stability from day one, and their advanced features
can offer time advantages when developers are exploring new types of gameplay. The bare minimum we expect from a physics engine is fairly obvious: we want to detect when two objects are interacting and we want that interaction to be resolved in a physically realistic way - simple, right? As you progress deep into integration, however, you'll find physics affects your user interface, logic mechanisms, AI routines, player control, and possibly even your rendering pipeline (Figure 1).
Here at Cyan Worlds, we're more than a year into our use of a commercial physics engine, having integrated it with our own proprietary game engine. I'm going to share with you some of the nuts and bolts of our integration process. In the first part of this article, I'll talk about the fundamentals: data export, time management, spatial queries, and application of forces. Then, with an eye toward character-centric game implementations, I'll visit the twin demons of keyframed motion and player control. In these areas, challenges arise because both of them require that you bend the laws of physics somewhat, and that means you must draw some clear distinctions between what is physics and what is programming for effect. Integration Basics: Geometry Export There are
three categories of geometry supported by physics engines. The simplest
are primitives, represented by formulae such as sphere, plane, cylinder,
cube, and capsule. Some-what more expensive is convex polygonal geometry.
Convexity simplifies detection and response greatly, leading to improved
performance and better stability. Convex shapes are useful for objects
where you need the tighter fit that you can get from a primitive but don't
have to have concavity. Finally, there is polygonal geometry of arbitrary
complexity, also known as polygon soups. Soups are fairly critical for
level geometry such as caves and canyons but are notoriously difficult
to implement robustly and must be handled with care to avoid slowdowns.
Transforms Transforms
in a rigid-body simulation do not include scale or shear. This mathematical
simplification makes them fast and convenient to work with, but it leaves
you with the question of what to do with scale on your objects. For static
geometry, you can simply prescale the vertices and use an identity matrix.
For moving physical geometry, you'll most likely want to forbid scale
and shear altogether; there's not much point in having a box that grows
and shrinks visually while its physical version stays the same size.
However, if the proxy geometry will be used by several different visible geometries, you may wish to keep the vertices in their original coordinate system and simply swap in the visible geometry's transform (Figure 2b). This method will let you use physical instances, wherein the same physical body appears several different places in the scene. This latter approach, while enabling efficiency via instancing, can be less intuitive to work with because the final position of the physical geometry depends on the transforms of objects it's used for and not the position in which it was actually modeled. Time Management Dealing
with time cleanly is an extremely important thing to get right early on
in integrating a physics engine. There are three key aspects of time relevant
to simulation management: game time, frame time, and simulation time.
Rendering
frame rates can vary; if your physics step size varies, however, you'll
see different physical results - objects may miss collisions at some rates
and not at others. It's also often necessary to increment, or step, the
simulation at a higher rate than your display; physics will manage fast-moving
objects and complex interactions more accurately with small step sizes.
|
|||||||||||||||||||||||||||
|
|