To gain experience designing and implementing an interactive 3D graphics application using OpenGL.
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.
We encourage you (the programmer) to use your creativity, but your program should implement at least the following functionality:
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.