Introduction
Clipping is very important in 3D graphics. The main purpose is to prevent the triangle drawing routine from trashing memory and drawing out of the screenspace. 3D-clipping can also help you to speed up your rendering engine.
2D Or 3D Clipping?
Basically there are two different approaches to clipping. The first and most common is the 2D clipping algorithm. In this kind of algorithm the clipping is done at the last stage of rendering. The triagle-routine used to render the polygons onto the screen make sure that you don't draw outside the screen. This can be very fast, but increases the complexity of the triangle-filler (and it's not as easy as 3D-clipping can be). This clipping method works directly with two-dimensional screen-coordinates.
In 3D clipping you do everything in 3D space. (In my examples it's done in camera-space. If you don't know about this don't worry about it.) If we want to clip in 3D space we need to have a description of the stuff the camera of our rendering-engine can see. When we use perspective projection (the most common projection type) this space can be described as a frustum.
3D Clipping 3D clipping is required when displaying 3D objects that can have negative z values when transformed to world space. Consider again our 40x40x40 cube. If we assume the cube vertices are defined in world space instead of object space, the cube will be drawn centered at the world space origin. This means the front half of the cube will extend through z=0 and into negative z space. This will cause major problems when we project the world space points to screen space when displaying the cube. 3D clipping solves this problem by clipping a polygon's world space points against a specified z plane, called the near clipping plane. Any z coordinates that extend into this plane are set to the near clipping value, and their x and y coordinates are adjusted accordingly. Besides the near clipping plane,