3D Underwater World (using OpenGL and SDL)
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:
- global.h - Global constants
- main.cpp - Main method
- Game class handling key presses, event loop and holding the World object.
- World class containing simulated enviroment with lighting setup, simulation functions and rendering code.
- contains the CameraView class holding the current camera position
and orientation, and the FrustrumClipper class which uses hyperplanes
to calculate whether a point is in view or not, so only objects inview
- primitive functions for drawing simple geometric shapes, like quadrangles, and texturing them.
- contains a textured grid of elevations for use in the terrain
- generates a random fractal landscape using the diamond square function
- contains SplineCurve class and MotionPath class for holding a 3D path
for an object to move along. The camera uses two, one for its position
and one for its viewing object
- contains texture loading function, courtesy for John Carter and a Texture
class to wrap common functionality.
- contains my own bespoke 3D vector class Vec3, 4D matrix class Mat4 (with
transformation functions, and hyperplane class.
- holds base classes for world objects which contain class definitions and implementation of objects that are drawn and
the animation functionality
// libraries needed for OpenGL drawing
// debugging or release?
#define SUN_X 25.0
#define SUN_Y 70.0
#define SUN_Z 25.0
#define VISIBLE_DISTANCE 100.0
#define SUN_INTENSITY 0.7
#define VISIBLE_DISTANCE 200.0
#define SUN_INTENSITY 0.9
const GLfloat PI = 3.14159265;
// size of display area
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;