Feel free to send me an e-mail. If you do, be sure to include an email so that I can get back to you
Sub on the Ocean Floor
This is a rendered scene of a submarine circling an underwater structure deep under the sea. It uses the OpenGL utility toolkit (GLUT) and the OpenGL extension wrangler (GLEW).
How did I orient the sub along its path?
Basically you use a billboarding technique. What I did was to calculate a forward vector from the origin to the sub's world position. This was exactly what I wanted since the sub goes around in a circle following a parametric function. Then I calculate a right and up vector. These vectors are the basis vectors for the coordinate frame representing the new orientation of the sub. I then form an ortho-normal change of basis matrix to transform the subs world orientation to the frame represented by the afore mentioned matrix. The code is as follows:
Vector3<float> right( Submarine.x, 0.0f, Submarine.z ); // From the orgin
right.normalize( );
Vector3<float> &forward = crossProduct( right, Vector3<float>::Y_VECTOR );
forward.normalize( );
matrix[ 0 ] = right.getX( );
matrix[ 1 ] = right.getY( );
matrix[ 2 ] = right.getZ( );
matrix[ 3 ] = 0.0f;
matrix[ 4 ] = 0.0f;
matrix[ 5 ] = 1.0f;
matrix[ 6 ] = 0.0f;
matrix[ 7 ] = 0.0f;
matrix[ 8 ] = forward.getX( );
matrix[ 9 ] = forward.getY( );
matrix[ 10 ] = forward.getZ( );
matrix[ 11 ] = 0.0f;
matrix[ 12 ] = 0.0f;
matrix[ 13 ] = 0.0f;
matrix[ 14 ] = 0.0f;
matrix[ 15 ] = 1.0f;
glMultMatrixf( matrix ); // Orient the sub along its path...
Comments