Game Development Reference
In-Depth Information
Figure 10-2. The two triangles—but something's wrong
Now that is strange. According to our theory, the red triangle (in the middle) should be in front of
the green triangle. The camera is located at the origin looking down the negative z axis, and from
Figure 10-1 we can see that the red triangle is closer to the origin than the green triangle. What's
happening here?
OpenGL ES will render the triangles in the order in which we specify them in the Vertices3
instance. Since we specified the red triangle first, it will get drawn first. We could change the
order of the triangles to fix this. But what if our camera wasn't looking down the negative z axis,
but instead was looking from behind? We'd again have to sort the triangles before rendering
according to their distance from the camera. That can't be the solution. And it isn't. We'll fix this
in a minute. Let's first get rid of this orthographic projection and use a perspective one instead.
A note on coordinate systems : You may notice that, in our examples, we start by looking down
the z axis, where if z increases toward us, x increases to the right and y increases up. This is
what OpenGL uses as the standard coordinate system. An easy way to remember this system
is called the right-hand rule . Begin by pressing the tips of your pinky and ring fingers of your
right hand against your right palm. Your thumb represents the x axis, your index finger pointed
straight out represents the y axis, and your middle finger pointed toward you represents the z
axis. See Figure 10-3 for an example. Just remember this rule and it will eventually come quite
naturally to you.
Figure 10-3. The right-hand rule
 
Search WWH ::




Custom Search