Frustum

introduction

In the last section we reproduced a technqiue for creating a perspective drawing. In this section we will look at what our program will need to know to reproduce perspective on the screen.

the geometry of perspective

On the etching by Durer I have superimposed a pyramid shape. The apex is at the eye of the artist. The pyramid is constructed so that it fits neatly within the viewing screen and extends far enough to include all the model. The part of the pyramid from the screen to the extreme left is called a frustum. This is a pyramid with its top cut off. In computer graphics the screen is called the viewport. Everything within the frustrum will get projected onto the viewport to create an perspective image on your screen.

The animation below illustrates how the frustum is used to project a 3D scene onto the viewport.

To the left is the frustum. It is the pyramid with the viewport illustrated as a green square. You can imagine a camera lying at the apex looking into the volume of the pyramid. What lies within the volume of the frustum beyond the viewport is projected onto the viewport along lines that focus onto the apex of the pyramid. The effect on the viewport image is more distance objects appear smaller. An effect of perspective is generated.

The image on the viewport is illustrated to the right, within the green square.

You can change the dimensions of the frustum in the labeled fields, to give different perspectives in the viewport. The meaning of these values is illustrated below.

Exercise : Play with the values in the labelled fields to see the result in the viewport.


The dimensions of the frustrum reflect the dimensions of the world you are trying to reconstruct in your game. From the beginning of designing your game you need to define what units of meaurement you are going to use. In the Durer scene you could define the frustum in units of metres, centimetres or millimetres. It is unlikely that you would choose kilometres or micrometres. Once you have decided on the units then you would build all your objects for your game with the same units.

The code for creating a frustum in OpenGL is listed below. In this example below 6 variables have already been defined for left, right, bottom, top, near and far.

Note : near and far are always positive. However left, right, bottom, top must have the correct sign relative to the coordinate system you wish to use. This will be discussed in the next section

// 
        Matrix4f projectionMatrix = Projection.perspective(left, right, bottom, top, near, far);