Game Development Reference
In-Depth Information
So we only see the region (0,0,1) to ( FRUSTUM_WIDTH , FRUSTUM_HEIGHT ,-1) of our world. Wouldn't it
be nice if we could move the frustum, say, to the left? Of course that would be nice, and it is also
dead simple:
gl.glOrthof(x, x + FRUSTUM_WIDTH, 0, FRUSTUM_HEIGHT, 1, -1);
In this case, x is just some offset that you define. We can, of course, also move on the x and
y axes:
gl.glOrthof(x, x + FRUSTUM_WIDTH, y, y +FRUSTUM_HEIGHT, 1, -1);
Figure 8-20 shows what that means.
Figure 8-20. Moving the frustum around
We simply specify the bottom-left corner of our view frustum in the world space. This is already
sufficient to implement a freely movable 2D camera. But we can do better. What about not
specifying the bottom-left corner of the view frustum with x and y, but instead specifying the
center of the view frustum? This way we can easily center our view frustum on an object at a
specific location—say, the cannonball from the preceding example:
gl.glOrthof(x - FRUSTUM_WIDTH / 2, x + FRUSTUM_WIDTH / 2, y - FRUSTUM_HEIGHT / 2, y +FRUSTUM_
HEIGHT / 2, 1, -1);
Figure 8-21 shows what this looks like.
Search WWH ::




Custom Search