Game Development Reference
In-Depth Information
My advice is to start small. Make sure that you understand each component fully and
then move to the next. Have patience, and you ' ll never tweak a negative sign in anger
again.
3D Code Can Look Correct and Still Be Wrong
3D programming is easier to get wrong than right, and the difficult part is that a
completely miscoded system can look and feel correct. There will be a point
where things will begin to break down, but by that time you might have
hundreds or thousands of lines of bogus code. If something is wrong, and you
randomly apply a negative sign to something to fix it and don
'
t understand why
it fixed it, you should back up and review the math.
Coordinates and Coordinate Systems
In a 2D graphics system, you express pixel coordinates with two numbers: (X,Y).
These are screen coordinates to indicate that each integer number X and Y corre-
sponds to a row and column of pixels, respectively. Taken together as a pair, they
describe the screen location of exactly one pixel. If you want to describe a 2D coor-
dinate system fully, you need a little more data, such as where (0,0) is on the screen,
whether the X coordinate describes rows or columns, and in which direction the
coordinates grow
to the left or right. Those choices are made somewhat arbitrarily.
'
'
There
t create a 2D graphics engine that uses the
lower right-hand corner of the screen as your (0,0) point your origin. There ' s
nothing that would keep you from describing the X-axis as vertical and Y as hori-
zontal, and both coordinates grow positive toward the upper left-hand side of the
screen.
Nothing would keep you from doing this, except perhaps the risk of industry-wide
embarrassment. I said that these choices of coordinate system are somewhat arbi-
trary, but they do have a basis in tradition or programming convenience. Here
s nothing that says you couldn
'
san
example. Since the display memory is organized in row order, it makes sense to
locate the origin at the top left-hand side of the screen. Traditional Cartesian mathe-
matics sets the horizontal as the X-axis and the vertical as the Y-axis, which means
that programmers can relate to the graphics coordinates with ease. It doesn
'
t hurt
that the original designers of text-display systems read text from left to right, top to
bottom. If these were reversed, programmers would be constantly slapping their fore-
heads and saying,
Oh yeah, those idiots made the X-axis vertical!
 
 
Search WWH ::




Custom Search