All pastes #983342 Raw Edit

Anonymous

public text v1 · immutable
·published 2008-04-13 08:48 UTC
rendered paste body
    *
       Introduction

In this lesson, we will see what is a Viewing Volume and a Viewport. I think this is necessary to understand the Viewing Volume to know how OpenGL works and draw a vertex from the *abstract* 3D space to the window of the screen.

Some informations was found in the OpenGL Programming Guide also known as The Red Book (html version here). This book is really usefull, I encourage you to read it !
 

    *
       Viewing Volume

The 3D space is defined by 3 axis (vectors) : X, Y and Z. These 3 axis creates an axis system (see Tutorial 4 for a representation of this axis system). All points of the 3D space can be expressed as a linear combination of these vectors. A point is point represented by its coordinates (x, y, z), which means x * X + y * Y + z * Z (upper case is a vector, low case is a scalar). The volume of the entire 3D space is infinity.

The Viewing Volume delimites the 3D space by creating a closed volume. Points outside this volume will not appears on the screen.
This particularity explain the first call glTranslate (just after glLoadIdentity) : we go inside the Viewing Volume. At start, we are on the front plane of the viewing volume.

The Viewing Volume can be created with two different kind of projections :
    Perspective Projection  Render object affected by the distance, a car is seen smaller when it move away.
    Orthographic Projection Render object NOT affected by the distance like a menu, a text on the screen, 2D objects ...
 

    *
       Perspective Projection

With this kind of projection, the viewing volume shape is a truncated pyramid (its top is cutted).

This shape is abtained by 6 cutting planes : front, back, right, left, top and bottom planes (planes at the volume boundary). These planes are commonly called Clipping Planes. These planes can be created with the aid of the method :
    glu.gluPerspective(fovy, aspect, near, far)
The fovy parameter is the angle between the plane that goes downwards and the plane that goes upwards.
The aspect ratio is generaly the aspect ratio of the window (window is the region of the screen in which the scene is rendered).

Each parameters are represented in this picture :

Picture Copyrith © Addison-Wesley Publishing Company

The Viewing Volume looks like :

Viewing Volume obtained with gluPerspective

The X and Y axis are parallel to the near plane. The origin of the axis system is the center of the near plane. The Z axis is perpendicular to the near plane and points towards the view.
The call glLoadIdentity reset the axis system, like represented in the above picture.


Parameter values

Here is an exemple of a viewing volume with perspective projection :
    gluPerspective(45.f, width/height, 1.f, 500.f)
The aspect parameter is the ratio between the width and the height of the window (component holding the OpenGL scene).