Game Development Reference
In-Depth Information
Figure 8-21. Specifying the view frustum in terms of its center
That's still not all we can do with glOrthof() . What about zooming? Think about this. We know
that, via glViewportf() , you can tell OpenGL ES on which portion of the screen we wish to
render the contents of our view frustum. OpenGL ES will automatically stretch and scale the
output to align with the viewport. Now, if we make the width and height of your view frustum
smaller, we will simply show a smaller region of your world on the screen—that's zooming in.
If we make the frustum bigger, we can show more of your world—that's zooming out. We can
therefore introduce a zoom factor and multiply it by our frustum's width and height to zoom in
and out. A factor of 1 will show us the world, as in Figure 8-21 , using the normal frustum width
and height. A factor less than 1 will zoom in on the center of our view frustum, while a factor
greater than 1 will zoom out, showing us more of our world (for example, setting the zoom factor
to 2 will show twice as much of our world). Here's how we can use glOrthof() to do that:
gl.glOrthof(x - FRUSTUM_WIDTH / 2 * zoom, x + FRUSTUM_WIDTH / 2 * zoom, y - FRUSTUM_HEIGHT /
2 * zoom, y +FRUSTUM_HEIGHT / 2 * zoom, 1, -1);
Dead simple! We can now create a camera class that has a position at which it is looking (the
center of the view frustum), a standard frustum width and height, and a zoom factor that makes
the frustum smaller or bigger, thereby showing either less of our world (zooming in) or more of
our world (zooming out). Figure 8-22 shows a view frustum with a zoom factor of 0.5 (the inner
gray box), and a view frustum with a zoom factor of 1 (the outer, transparent box).
Search WWH ::




Custom Search