Game Development Reference
In-Depth Information
Figure 14.13
The view frustum with near and far clipping planes.
outside the frustum doesn
'
t need to be drawn, so it is an indispensible member of
any 3D graphics engine.
The camera is at the tip of the pyramid, looking at the frustum through the near
clipping plane. Any object that is totally outside the six planes that describe the frus-
tum are outside the viewing area, which means they can be skipped during the ren-
dering passes. The six planes include the near and far clipping planes and the four
other planes that make up the top, left, right, and bottom of the frustum. It turns
out to be really efficient to test a point or a sphere against a frustum, and that is
exactly how this frustum will be used to cull objects in the scene graph. If you
didn ' t do this, you ' d be sending every triangle in your scene into the renderer, even
if it wouldn
t be seen by the player. That means your scenes would have to be a lot
less complicated, or shall I say boring, to keep up a fast frame rate.
A frustum is defined with four parameters: the field of view, the aspect ratio, the dis-
tance to the near clipping plane, and the distance to the far clipping plane. The field
of view, or FOV, is the full angle made by the tip of the pyramid at the camera loca-
tion (see Figure 14.14). The aspect ratio is the width of the near clipping plane
divided by the height of the near clipping plane. For a 640 × 480 pixel screen, the
aspect ratio would be 640.f/480.f or 1.33333334. The distance to the near and far clip-
ping planes should be given in whatever units your game uses to measure distance
'
feet, meters, cubits, whatever. With these parameters safely in hand, the six Plane
objects can be built.
Here
'
s the code for defining the Frustum class:
class Frustum
{
Search WWH ::




Custom Search