Game Development Reference
In-Depth Information
great for playing back sounds, spawning particle effects, or imparting damage and
destruction to the objects concerned.
Any game is going to need a good raycaster. A raycaster is something that returns
oneormoreobjectsthatintersectwithaproberay.Itisanextremelyusefulrou-
tine for finding out whether objects are in thelineofsightofanAIprocess,deter-
mining where to put bullet holes, and probing the surrounding geometry for
moving cameras, objects, or characters. If possible, you should also be able to do
something called a shapecast, which takes an entire object, like a sphere, and
casts it instead of a simple ray. This kind of thing is invaluable for creating good
third-person cameras. Depending on your physics system, raycasts or shapecasts
can be expensive.
Most physics SDKs can send lots of debug information into your rendering pipeline
so that things like collision shapes, acceleration vectors, and contact points are drawn
so you can actually see their magnitudes and directions. Watching physics data struc-
tures visually is the only way to debug physics. You simply can
t just look at the data
structures and diagnose problems easily. Consider this example: Two objects seem to
react in unexpected ways when they collide. When you look at the collision mesh
data, you find that they look correct in the debugger
'
s watch window. When you
turn the physics debug renderer on, you might notice that one of the collision hulls
is simply the wrong shape and needs to be fixed. You ' d never figure this out looking
at a long list of points in 3D space.
Most physics errors come from bad data or misuse of the API. For this reason, any
decent physics SDK should have a good way to report errors back to you in the
debug build. DirectX does this by sending error or informational messages to the
debugger
'
s output window. A good physics system should do the same thing. If
your artists have created a collision mesh the physics system can
'
'
t handle, it
'
s nice
to know right away rather than after you
ve spent all night debugging the problem.
Memory allocation is always a concern in computer games. They simply don
'
t use
memory in the manner that best suits the standard C-runtime memory allocator,
and for that reason, most games write their own memory allocation scheme. A phys-
ics system can be just as hard on memory as a graphics subsystem, and thus it needs
to use the same optimized memory system as the rest of your game. Look for hooks
in the SDK that let you circumvent the default memory allocator with your own.
Physics is expensive enough that you only want to simulate areas of the game the
player can actually see or be affected by. For this reason, most good physics systems
have easy ways for groups of objects to be enabled or disabled as a group, which
allows you to turn on and off areas to make the very best use of your CPU budget.
'
 
Search WWH ::




Custom Search