Game Development Reference
In-Depth Information
Which Way Is Up?
Drawn toLife: TheNext Chapter is a Wii title I worked on that was technically a
3D game, but the camera was locked along a single plane, giving it the feel of a
2D platformer. One of my early tasks was getting a new enemy into the game
and hooking up some basic AI. I went into the design tool and placed the spawn
point for the monster. When I loaded up the game, the monster wasn
'
t there. I
couldn
t find him anywhere. After banging my head against this problem for a
while, one of the programmers came up and casually mentioned that they were
using the Z-axis as the vertical axis, not Y. Y represented depth, so I was setting
the position of the creature to somewhere behind the scenery instead of up in
the air. This became a common bug throughout development, albeit an easy one
to fix.
'
A 3D world requires a 3D coordinate system. Each coordinate is expressed as a trip-
let: (X,Y,Z). This describes a position in a three-dimensional universe. As you might
expect, a location on any of the three axes is described with a floating-point number.
The range that can be expressed in a 32-bit floating-point number in IEEE format is
shown in Table 14.1.
The diameter of the known universe is on the order of 10 26 meters. The smallest the-
oretical structures of the universe, superstrings, have an estimated length of 10 35
meters. You might believe that a 32-bit floating-point number is more than sufficient
to create a 3D simulation of everything in our universe, but you ' d be wrong. Even
though the range is up to the task, the precision is not. Oddly enough, we may one
day find out that the universe is best expressed in terms of 256-bit integers, which
would give enough range and precision to represent a number from 0 to ~10 76 ,
plenty to represent the known universe, ignoring irrational or transcendental num-
bers like
.
So where does that leave you and your 32-bit IEEE floating-point number with its
decent range and lacking precision? The IEEE format stores an effective 24 bits of
resolution in the mantissa. This gives you a range of 1.67 ×10 7 . How much is that?
As Table 14.2 indicates, you should set your smallest unit based on your game
π
Table 14.1 Precision of Floating-Point Numbers
Single Precision, 32-bit
Double Precision, 64-bit
2 126 to (2
2 23 )×2 127
2 1022 to (2
2 52 )×2 1023
 
Search WWH ::




Custom Search