Table of Contents:

s

Objective:

OpenGL is a library of functions that allow the quick rendering of 3D polygons using methods discussed in CS417. The objective of this project was to learn how to write an interactive program using OpenGL as a rendering engine. We wanted to learn how to allow a user to interact within a 3D environment in real-time. Thus we settled on a game similar to the classic Asteroids arcade game.

Design and Implementation:

The story for the game is simple. The player is in a ship in a 3D box. All objects stay within the box by bouncing off the walls when they attempt to leave. Within the box there are 200 asteroids flying about the players ship. The player can fly his ship and shoot up to 10 shots in a given moment. When an asteroid is hit, it explodes, and the player gets 100 points plus a number of points corresponding to the accuracy of his previous shots. If the ship bumps into an asteroid, the game is over. The game engine was written in C++. There are classes representing every object in the game, including the stars, asteroids, explosions, and the players ship. The object representing the game world has a pointer to the players ship, a linked list of the active asteroids, and arrays for all stars in the box. The Ship itself keeps track of the shots it has fired. Information about the orientation, position, angular and position velocities of these objects are stored within these classes. When the shots are updated, a collision detection algorithm is run between the shots and the asteroids. The algorithm first checks for intersection of bounding spheres for the two objects, then individually calculates all remaining potential collisions. As the computations involved in this updating procedure was designed to be mostly additive, and collision detection was not to expensive in the worst case, I also allowed for anti-ailiasing to be done under OpenGL, which made the image better quality by removing the jagged edges on surfaces, but slowed down the frame rate dramatically. Thus, I only recommend using this on fast Pentium machines.

The game engine was designed with speed in mind. The simulation of flying trhough a volume had to be smooth. Thus, there I decided to use cubes as a starting point for the asteroids. This way there would be a low number of polygons, and explosions would be simpler. The next design consideration was how to make the physics of the engine easy to update. This lead to the storage of all possible information in such a way that everything could be updated additively. Not only were the velocities of the objects updated in an additive vector format, but so were the Up, View, and Right vectors for the ships camera when rotations are done. Lastly the model for obtaining user input is a combination of the push/pull paradigm. I decided to use a mostly pull system, whereby the user interface is polled for the states of keys on the keyboard when the information is needed for calculations. However, it would be a noticeable problem if the user happened to press the fire key when the computer wasn't polling and thus not get a shot fired. Thus, whenver a fire button is pressed, a windows message is "pushed" onto the message queue saying that the key has been pressed, gauranteeing that a shot will be fired.

Results:

The resulting controls for the game and some screen shots are given below:

Key                                     Action
---                                     ------
Arrow Keys                              Dive, climb, and turn
Ctrl, Alt                               Pitch and Yaw
Space Bar                               Fire
Left Shift                              Accelerate
Ins(0 with NumLock off)                 Brake
S or s                                  Polygon anti-alias toggle(default off)
P or p                                  point anti-alias toggle(default off)
A or a                                  Asteroid Color Cycling
C or c                                  Cross Hair Color cycling
F or f                                  Shot Color Cycling
Q or q                                  quit

Further Information:

There are a wealth of books out on how to write in OpenGL, see References for one or two good ones. Note to future students: debugging a game is fun/addictive and in general very unproductive. Enjoy:)!

Also, here is a list of some improvements and add-ons to the game itself: First, sound could quite easily be added to this application, so that whenever a particular event occurred, say firing a shot or hitting an asteroid, a sound was played as well. It also would be fairly easy to write an elementary computer player for this game so that players could dogfight against the computer. This computer player could access the information as to the position of all other objects in the world and make its actions like the persons ship. In the are of graphics, the cubes used to represent asteroids could be expanded into more complex polyhedra, or could use OpenGL's Texture mapping functions. Next, using TCP/IP over Windows Sockets, it shouldn't be difficult to add basic networking support for player to player play. This change however, would require the design of a client/server architecture. One copy of the program would have to be started to accept connections from another computer. The client would have to send the players UI input, and handle receives of the state of the world relative to other players. The Win32 API also has functions for joystick support, which might make the flight simulation more realistic.

Download:

The generator has one executable, two sample files, and requires versioe 4.2 of the Microsoft Foundation Classes, as well as Opengl for Windows 95. These last three documents should go in the WINDOW\SYSTEM directory.

BLAST.EXE, OPENGL32.DLL, GLU32.DLL

Acknowledgements:

As with our L-Systems project, we would like to thank Prof. Bruce Land for his time and patience in helping us through this project. Without his support and guidance, this could not have been completed. As always, we thank PepsiCola Inc. for being able to produce enough Mountain Dew to meet our demanding needs. Remember, it's not just caffeine, it's a way of life.

References:

Neider, J., Davis, T., and Woo, M. OpenGL Programming Guide. Addison Wesley.

Wright, Richard Jr. and Sweet, M. OpenGL SuperBible. The Waite Group.