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:
#include "global.h"
#include "world.h"
#include "clipping.h"
/*
* Game class
* Controls the world, rendering, key presses etc
*/
class Game
{
private:
// true while running
bool running;
// tour
bool tourRunning;
float tourPeriod;
MotionPath tourPosPath;
MotionPath tourObjPath;
// the world simulation
World* world;
// camera
CameraView camView; // position and view
GLfloat camFwdV; // forward velocity along z axis in m per s
GLfloat camFwdA; // acceleration of camera, while key depressed
GLfloat camHorizAV; // angluar velocity (deg per s) in xz plane when turning
GLfloat camVertAV; // anglular v (deg per s) in the zy plane when turning
// update camera orientation
void camUpdate(GLfloat dT);
// move along the tour path
void tourStep(GLfloat dT);
// move to predefined screenshot location
void viewPicture();
// shows help file
void showHelp();
// handles SDL events
void handleEvent(SDL_Event* event);
// get time
GLfloat getTime() {
return ((GLfloat)SDL_GetTicks()) / 1000.0;
}
public:
// constructor
Game();
// destructor
~Game();
// start game running (main loop)
void run();
// exit
void exit();
// start and stop automatic tour
void startTour();
void stopTour();
// reset
void reset();
};