|
OpenGL is used to draw every object seen in the CAVE. A good introduction to OpenGL can be found at SGI. Before anything can be drawn in the CAVE, OpenGL needs to be initialized. Our code does this with the init_gl CAVE callback function (see game.c++). Not much is done, simply clearing the display. Once the GL is initialized, drawing can occur. However, the lighting must be in place for any objects to appear. This is the purpose of the beginning of the System::DrawWorld() function. First, ambient light is turned down (so that our 'sun' will highlight the objects), and then a light is placed at infinity behind and to the right of the CAVE center (along the vector (1,0,1)). Light is turned on using GL_ENABLE(GL_LIGHTING) and GL_DISABLE(GL_LIGHTING). Now that the stage is set and the lights are on, it's time to draw things. Four basic objects were drawn in the CAVE:
Points
Points were used to draw several objects in the CAVE. These include the background stars, the outline of the radar, the energy shield, and the blips on the radar. This is done simply by telling OpenGL what color the points are, specifying that points will be drawn, and then giving the point's X, Y, and Z coordinates. Here is the basic format: Lines
Lines were used to draw only two things: the direction arrow and the velocity indicator on the radar scope. The basic structure of this code is the same as the code to draw points, except that two vertices must be specified, with the line being drawn between them. Here is an example: Spheres Many things in our world are drawn with spheres: the planet, the asteroids, bullets, and bombs. The drawing of these objects is somewhat of a mystery... this is the only place in our code where we use the OpenGL Utilities. An object called a Quadric Surface is created, using gluSphere. This function accepts the number of phi and theta samples to make the sphere out of (i.e., 4 and 4 would create a very rough, poorly approximated sphere, while 16 and 16 would create a very smooth sphere). To speed up the drawing functions, only large spheres are approximated well. Smaller spheres (such as bullets and bombs), were approximated poorly. Ships The two types of ships were by far the most complicated objects to draw. These objects are made up of triangles, being careful to create a closed surface. To do this, we created an array of vertices of the surface, and then an array which gives the three vertices which describe each triangle face. These two arrays were created by sketching designs on paper. Then, since OpenGL needs to know the normal vector of each face (for lighting purposes), the normal of each face is computed (NOTE: we happened to use a left-hand rule to specify the triangle points and the normal computation, but these cancel each other out to give OpenGL the correct normal vector). Finally, for each triangle, the normal vector and the three triangle vertices (in 3D, remember) are specified for OpenGL. |