2D? 3D? What Are You Talking About?


Before you can dive into the wonderful world of 3D math, you need at least a basic understanding of the differences between a 2D world and a 3D world. Grab a piece of paper and a pencil. Draw something on the piece of paper, and look at it. It is an example of a basic 2D world. The image you drew has two different dimensions, width and height. Now, look at this book you're holding. You'll notice that it too has width and height, but it also has an "added" dimension, namely depth. Each page of the book is essentially flat, but the book itself has depth.

In the 2D world, any point in space can be defined by a coordinate that represents the width and height of that point. You have an x axis (which is the width axis) that runs horizontally and the y axis (height), which runs perpendicular to the x axis or, in this case, vertically. Starting at the origin (0,0the center), the positive x axis coordinates run to the right, and the positive y axis coordinates run up. You can see an example in Figure 10.1.

Figure 10.1. A basic 2D Cartesian system.


Construction Cue

The people that originally made monitors must not have been paying attention in math class because you'll notice that when you talk about your screen coordinates, positive X is certainly to the right, but positive Y goes down rather than up as I just described. The same principles still apply, even if they are upside down.


Remember that piece of paper and the pencil you had? Take that pencil and push a hole through the center of the piece of paper so that half of the pencil is on either side of the paper. To make your 2D world 3D, you simply need to add a new axis to your coordinate system, for depth. This axis is the z axis and can be represented by the pencil you have sticking in the paper. Look at Figure 10.2 for a better idea of what the z axis is.

Figure 10.2. A basic 3D Cartesian system.


Left-handed? Right-handed?

Did you notice that I didn't mention which direction the positive z axis faces? I did so intentionally because (much like your computer screen's y axis going down) "it depends." The direction of the positive z axis is relative to which coordinate system you are using, either left-handed or right-handed.

I can just see the puzzled look you have right now. Left-handed? Right-handed? What is that supposed to mean? It's just a fancy way of informing the user of which way the positive z axis faces. Assuming you are looking directly at your sheet of paper with the pencil through it (so you see either eraser point of the pencil), positive z can be either away from you (toward the writing point of the pencil) or toward you (back toward the eraser side). To see where these names came from, take your left hand with the palm facing the sky (or ceiling if you happen to be inside). Rotate your hand so that your fingers point toward the positive x axis (to your right). Now, do the same thing with your right hand, palm up, fingers pointing toward the positive x axis. Look at the thumb on each hand. Assuming you've got a normal human body, the thumb on your left hand is pointing away from you, but the thumb on your right hand is pointing toward you. Whichever way your thumb is pointing is the direction of the positive z axis, hence the name of the coordinate system. See Figure 10.3 for a graphical representation.

Figure 10.3. Left- or right-handed coordinate system?


Construction Cue

Direct3D (which is the Application Programming Interface [API] this book covers) uses a left-handed coordinate system. So throughout this book, you can assume that we are using this system.


With that out of the way, you should be able to plot simple points in a 3D graph. For example, you know the origin has a point of (0,0,0), but what about a point that is located at say (-3,4,17)? This point is located 3 units to the left of origin, 4 units above origin, and 17 units away from you (assuming you're at the origin and this is a left-handed coordinate system). Plotting these points is what is actually used to create your rich worlds.



Beginning 3D Game Programming
Beginning 3D Game Programming
ISBN: 0672326612
EAN: 2147483647
Year: 2003
Pages: 191
Authors: Tom Miller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net