CMSC 437/691C
Graphical User Interface Programming


TUE,THU 5:30-6:45 PM ACIV 150
Fall 1996


Project 5: A 3D Asteroids Game


Date Due Tuesday, December 10, 1996 before midnight.

Purpose

To gain experience designing and implementing an interactive 3D graphics application using OpenGL.

Assignment

For this project, we say goodbye to our beloved drawing editor and plunge into the exciting world of interactive 3D computer games. You task is to construct a 3D asteroids game using the OpenGL graphics library.

Your program will have one 3D window which provides a view into the vast blackness interplanetary space, sprinkled with a starry background. Moving past you, at various speeds and and angles but always in straight lines you see a curious collection of asteroids of various size, shape and hue. For asteroids, these are very strange shapes indeed: cylinders, cones, dodecahedrons, even (can your eyes be deceiving you?) teapots. These asteroids are all rotating in various directions and moving more or less towards you so that from the moment they first appear as tiny specks in the distance until they whiz above, below, to the left or to the right of your field of view, only a handful of seconds have passed. Occasionaly, by random chance, an asteroid will hurl straight towards you and crash into your spaceship, in which case the game is over.

It is your (the user's) task to forestall this dreadful fate as long as possible by vaporizing the lethal asteroids with a laser gun before they have a chance to vaporize you. The laser gun itself is a long cylinderical object (as most guns are), visible towards the lower center of your window. It's vertical and horizontal orientation can be controlled interactively using the mouse, and this affects the direction of the laser beam, which can be fired by hitting the spacebar. When the spacebar is pressed, the gun emits a bright ray of laser light extending off into infinity. If this ray intersects an asteroid, it vaporizes into an expanding cloud of radiant gas.

Each asteroid you destroy counts for one point, and your total score for the current game is displayed either on the standard output, or using a text widget in a Motif window. The game can be paused, continued, terminated or restarted by pressing the 'p', 'c', 't', and 'r' keys respectively, or by pressing appropriate buttons in a Motif window, if you prefer.

Specific Tasks

We encourage you (the programmer) to use your creativity, but your program should implement at least the following functionality:

Undergraduates may render all objects in wireframe. Graduate students should use lighting and should display some sort of pyrotechnics when the asteroid is destroyed. It is not necessary to implement any Motif widgets, unless you want to.

Hints

We suggest that you maintain a display list of asteroids. Each asteroid should maintain a shape, a material, a position, an orientation, a velocity and an angular velocity. Each asteroid is created with random (within a certain range) values for these attributes. At each iteration of the simulation loop, the asteroid's position and orientation will be advanced according to the current velocity and angular velocity, and the scene will be redrawn. As asteroids pass out of view, they should be recycled with new random inital values. At each time step, each asteroid should be checked for collision with the spaceship, for which purpose both asteroid and spaceship may be modeled as spheres. Whenever the laser gun is fired, the laser ray should be checked for intersection against each asteroid, also using sphere's as models for the asteroids. If it intersects, the asteroid should be recycled immediately.

You can use the "aux" library for all your windowing and events if you want, or you can use the Motif GLDrawingArea widget, and get your events from X, just as you have for previous projects. The "aux" library has many built-in shape drawing routines, which can be used in either case. You can find the "aux" library, along with the source code from the textbook, in ~ian/pub/guip/opengl.

In ~ian/pub/guip/skel, there is a sample skeleton program for using the GLDrawingArea widget. If you use this skeleton, you will need to improve on the code and data structures significantly.


Ian Soboroff -- ian@umbc.edu