Game Development Reference
In-Depth Information
You might be wondering why the view frustum of the parallel projection case in Figure 7-3 is
rectangular. It turns out that the projection is actually governed by how we define our clipping
planes. In the case of a perspective projection, the left, right, top, and bottom clipping planes
are not perpendicular to the near and far planes (see Figure 7-3 , which shows only the left and
right clipping planes). In the case of the parallel projection, these planes are perpendicular,
which tells OpenGL ES to render everything at the same size no matter how far away it is from
the camera.
Normalized Device Space and the Viewport
Once OpenGL ES has figured out the projected points of a triangle on the near clipping plane, it
can finally translate them to pixel coordinates in the framebuffer. For this, it must first transform
the points to so-called normalized device space . This equals the coordinate system depicted in
Figure 7-2 . Based on these normalized device space coordinates, OpenGL ES calculates the
final framebuffer pixel coordinates via the following simple formulas:
pixelX = (norX + 1) / (viewportWidth + 1) + norX
pixelY = (norY + 1) / (viewportHeight + 1) + norY
where norX and norY are the normalized device coordinates of a 3D point, and viewportWidth
and viewportHeight are the size of the viewport in pixels on the x and y axes. We don't
have to worry about the normalized device coordinates all that much, as OpenGL will do the
transformation for us automatically. What we do care about, though, are the viewport and the
view frustum. Later, you will see how to specify a view frustum, and thus a projection.
Matrices
OpenGL ES expresses projections in the form of matrices . We don't need to know the internals
of matrices. We only need to know what they do to the points we define in our scene. Here's the
executive summary of matrices:
ï?®
A matrix encodes transformations to be applied to a point. A transformation
can be a projection, a translation (in which the point is moved around), a
rotation around another point and axis, or a scale, among other things.
ï?®
By multiplying such a matrix with a point, we apply the transformation to
the point. For example, multiplying a point with a matrix that encodes a
translation by 10 units on the x axis will move the point 10 units on the
x axis and thereby modify its coordinates.
ï?®
We can concatenate transformations stored in separate matrices
into a single matrix by multiplying the matrices. When we multiply
this single concatenated matrix with a point, all the transformations
stored in that matrix will be applied to that point. The order in which
the transformations are applied is dependent on the order in which we
multiplied the matrices.
 
Search WWH ::




Custom Search