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
* TerrainGrid class
* Creates a random terrain using the
* diamond-square fractal algorithm.
* Tristan Aubrey-Jones 18/12/2007
class TerrainGrid: public RegularGrid
// height (as normals created in advance to create in
// the unit square)
// roughness constant
// the dimension exponent e, where dimensions = (2^e,2^e)
// performs the square step of the diamond-square algorithm
void performSquareStep(int sqrSize, RegularGridVertex ran);
// peforms the diamond step of the diamond-square algorithm
void performDiamondStep(int sqrSize, RegularGridVertex ran);
// res - resolution exponent
// e.g. (1 gives 2x2, 8 gives 256x256)
TerrainGrid(int res, float roughness, Vec3 v, Texture* tex):