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:


home Home   up Up   ( Download )

#ifndef SPLINES_H_INCLUDED #define SPLINES_H_INCLUDED #include "global.h" #include "vectors.h" /* * SplineCurve class * represents a parametric cubic b-spline * curve. */ class SplineCurve { private: // control points on the // spline. Vec3* controlPoints; int numPoints; // B-Spline geometry matrix Mat4 Ms; public: // constructor SplineCurve(int numPoints); // destructor ~SplineCurve() { delete controlPoints; } // allows assigning at fixed control points // u - integer index in [0,numPoints-1] // x,y,z coordinate of control point void set(int u, float x, float y, float z); void set(int u, const Vec3* v); // accessor interpolating along spline curve // u - the parameter to interpolate the position of // in [0, numPoints-1] // r - pointer to vector to store the result in void get(float u, Vec3* r); // draw for testing purposes void draw(); }; /** * MotionPath * */ class MotionPath { private: // position float p; // vertices Vec3* vertices; int n; public: // constructor MotionPath(int numPoints); // destructor ~MotionPath() { delete vertices; }; // set point void set(int u, float x, float y, float z); // get point void get(float u, Vec3* pos, Vec3* dest); void get(float u, Vec3* pos); // draw as a line void draw(); // current position // move void move(float d); // get now void getNow(Vec3* pos, Vec3* dest); // reset, return to beginning void reset(); }; #endif