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:

clipping.h

home Home   up Up   ( Download )


#ifndef CLIPPING_H_INCLUDED #define CLIPPING_H_INCLUDED #include "global.h" #include "vectors.h" /** * The hyperplanes of a frustrum * projection. */ class FrustrumClipper { public: // hyperplanes HyperPlane nr; HyperPlane fr; HyperPlane left; HyperPlane right; HyperPlane top; HyperPlane bottom; // init FrustrumClipper() {} FrustrumClipper(FrustrumClipper* f); void set(FrustrumClipper* f); // sets the frustrum's clipping planes // to the frustrum defined by these // parameters void set(float viewingAngle, float aspectRatio, float nearD, float farD, const Vec3* pos, const Vec3* obj, const Vec3* above); // transform this using a transformation matrix void transform(Mat4* t); // inside the frustrum? bool inside(const Vec3* p); }; /* * CameraView class * Stores information about the current orienation * and direction of the camera, and methods to determine * if a point, or object is in view. */ class CameraView { private: // frustrum for clipping FrustrumClipper frust; // perspective constants GLfloat viewingAngle; GLfloat aspectRatio; GLfloat nearD; GLfloat farD; // camera orientation Vec3 pos; // position of the camera Vec3 obj; // forward Vec3 above; // upward Vec3 side; // normal to plane of pos,obj,above public: // constructor CameraView(GLfloat viewingAngle, GLfloat aspectRatio, GLfloat nearD, GLfloat farD); // set location and orientation void set(const Vec3* pos, const Vec3* obj, const Vec3* above); // is in view? bool inView(Vec3* p) { return frust.inside(p); } // set gl lookat to this orientation void lookAt(); // rotate vertically void rotateVert(float angle); // rotate horizontally void rotateHoriz(float angle); // move forward void moveForward(float dist); // move up void moveUp(float dist); // get position void getPosition(Vec3* r); // get forward vector void getForwardVector(Vec3* r); }; #endif