Copyright Tristan Aubrey-Jones January 2008.
This is an example OpenGL SDL application which creates an animated 3D underwater world (screenshot), with "Thunderbird 4" with headlights moving on a spline path, a randomly generated sand terrain, sunken ship/submarine/treasure chest models, and swaying fish and seaweed. It is designed to demonstrate basic OpenGL features, and the structure is as follows:
#ifndef PRIMITIVES_H_INCLUDED
#define PRIMITIVES_H_INCLUDED
#include "global.h"
#include "textures.h"
#include "vectors.h"
/* FaceInfo class
Holds the details of a texture mapping
Onto a quad
*/
class FaceInfo
{
public:
// constructors
FaceInfo():
cr(1.0), cg(1.0), cb(1.0), t(NULL),
tl(0.0), tr(1.0), tt(0.0), tb(1.0) {}
FaceInfo(float r, float g, float b):
cr(r), cg(g), cb(b), t(NULL),
tl(0.0), tr(1.0), tt(0.0), tb(1.0) {}
FaceInfo(Texture* tex):
t(tex),
cr(1.0), cg(1.0), cb(1.0),
tl(0.0), tr(1.0), tt(0.0), tb(1.0) {}
FaceInfo(Texture* tex,
float tl, float tr, float tt, float tb):
t(tex),
cr(1.0), cg(1.0), cb(1.0),
tl(tl), tr(tr), tt(tt), tb(tb) {}
// colour
float cr, cg, cb;
// texture image
Texture* t;
// texture positions
float tl, tr, tt, tb;
// start and stop face
void Begin();
void Vertex(int i);
void End();
// init an array all ready
static void initBox(FaceInfo* array,
float r, float g, float b);
static void initBox(FaceInfo* array,
Texture* tex);
};
/**
* Primitives class
* contains methods for drawing primitive objects.
*/
class Primitives
{
public:
// draw a unit square in the
// x,y plane
static void drawSquare();
// draw sphere
static void drawSphere();
// draw a cylinder
static void drawCylinder();
// draw a disk
static void drawDisk();
// draws a box
// vertices - an array of 8 vertices
static void drawBox(Vec3 vertices[], Vec3 normals[]);
static void drawBox(Vec3 vertices[], Vec3 normals[], FaceInfo faces[]);
// initializes an array of vertices to
// those for a 1x1 cube
static void initBox(Vec3 vertices[]);
// calculate the normals for each box vertex
static void boxNormals(Vec3 vertices[], Vec3 normals[]);
};
#endif