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 )

#include "global.h" #include "terrain.h" #include "textures.h" #include "clipping.h" #include "worldobjects.h" class World { private: // world time in seconds since // the world was first started GLfloat time; // visible distance from eye visible // in world coordinates GLfloat visibleDistance; // terrain TerrainGrid* floor; Texture* sandTex; float floorW, floorD; // thunderbird 4 VehicleObject* vehicle; // static objects StaticObject** staticObject; GrassObject** grassObjects; // fish FishObject** fish; // initializes the world void init(); // draws the landscape int draw_landscape(CameraView* view); public: // constructor World(); // destructor ~World(); // simulate the scene, updating the time // dT - the change in the world time in seconds // this will normally be the positive time // since the last simulate, but could be negative void simulate(GLfloat dT); // goes to the time of the picture void gotoPicTime(); // check for collision, and if // one occurs provides the point of // collision // position - vertex to check // direction - direction of vertex as it approached // result - when returns true contains the point of collision bool collisionDetect(Vec3* position, Vec3* direction, Vec3* result); // resets the simulation to time 0 // and all objects to their state at time 0 void reset(); // draws world that is currently // visible by the camera view // returns the triangle count for // the current frame int draw(CameraView* view); };