CGFLib - A library for Computer Graphics @ FEUP
 All Classes Files Functions Variables Pages
Helper classes for scene elements

Table of Contents

To assist in the creation of scenes, a set of classes where created for the elements more commonly found. The principle behind the creation of these classes was not to make a full abstraction or wrapping of the underlying technology (OpenGL), but just to provide a starting point, from which these basic blocks could be improved or extended.

In this page you will find some information and usage examples regarding the following classes:

CGFcamera

Conceptually, a camera can be defined by its extrinsic parameters (position, orientation) and intrinsic parameters (lens opening, width/height ratio, distortion, etc.).

In terms of OpenGL support, a simple pinhole camera model is used, and that can be defined by two transformation matrices:

These two matrices can be created in many different ways. The model/view matrix, for instance, can be created as a composition of transformations (e.g. a translation, followed by a rotation), or by using OpenGL/GLU utility functions such as gluLookat. The projection matrix matrix can be created by resorting to functions such as glFrustum or glOrtho to define different types of projections.

The definition/update of these two matrices takes place in the following methods:

In the default implementation, the projection matrix is defined as a perspective matrix, and with horizontal and vertical angles proportional to the window width/height ratio. The model/view matrix is indirectly controlled by the mouse: mouse events handled by the default CGFinterface invoke methods on the active camera to translate, rotate and pan around a point ahead of the camera.

To implement a different kind of camera (e.g. an orthographic camera or a target-oriented camera), one could derive from CGFcamera and reimplement those two methods.

CGFlight

The CGFlight class wraps an OpenGL light and provides basis methods for enabling/disabling a light, and setting common light parameters. As lights in OpenGL do not have a visible representation, CGFlight is also able to draw a sphere to represent a light's position.

In this implementation, the constructor allows to specify the OpenGL light identifier (in the form of GL_LIGHT_n), a position and an optional direction. All other light parameters that can be set are listed in the reference of CGFlight. These are typically set at intialization, but can be changed during the main application loop.

Other important methods for managing lights are the following:

Extended implementations of CGFlight could for instance allow changes in position and orientation.

CGFobject

This is a simple class meant to be the base class for drawable objects. Its expected usage is that any initialization and pre-calculations needed for drawing the object are performed in the constructor, and that a draw() method is implemented, for doing the actual rendering of the object in execution time. The library provides an example of this: the CGFaxis class.

CGFappearance

CGFappearance is also an helper class, in this case one devoted to enclose functionality regarding objects' appearance, namely in terms of material properties and textures.

In this basis implementation, in terms of material properties, it is possible to set basic properties, such as ambient, diffuse and specular reflection coefficients, among others. These can be set when an instance of CGFappearance is created, via its CGFappearance::CGFappearance(float*, float*, float*, float) constructor, or by setting/changing them via a series of methods available for that purpose (see the CGFappearance class reference).

Textures in CGFappearance

In terms of textures, it is possible to use the CGFappearance::CGFappearance(string, int, int) constructor, or the CGFappearance::setTexture(string) to automatically load a texture and assign it to an appearance.

Additionally, it is also possible to load a texture using the CGFtexture class (see below), and assign it to a CGFappearance instance by reference, using the CGFappearance::CGFappearance(CGFtexture *, int, int) or the CGFappearance::setTexture(CGFtexture *) method. This is particularly useful to avoid loading and storing the same image multiple times, when the same texture is to be used in more than one appearance.

CGFtexture

CGFtexture is used to load, store and refer textures in general. It is meant to be used in CGFappearance instances.