Project 4 - 3D World
CS351: Introduction to Computer Graphics
11:59 pm Friday, Novemeber 19
Your assignment in this project is to write an OpenGL program
in which the the user can explore a virtual world.
The examples I will give in class will have to do with
making an undersea environment, but you are welcome to implement
any world you like.
The technical requirements are:
Projects which solidly meet these requirements will get 100 points.
I expect that most people will want to go beyond these
- The user should be able to navigate in 3D. This should
include translating forwards and backwards, rotating left and
right, and translating up and down. Tilting up and down and
spinning upside down are other possible optional camera motions.
- You should use texture mapping on a 3D object other than the
- You should have at least one reasonably complex and interesting
object in your world. An undersea plant, a piece of coral, or
a fish would be acceptable.
- Reshaping the window should not distort objects in the world.
Here is some code which
brings up the holodeck, with perspective projection.
Your job is to turn it into a 3D world, possibly undersea, which
the user can navigate around.
The holodeck code has global variables for the camera position,
the camera direction as a vector in the x-y plane (assuming
it can't tilt), and the camera direction as a rotation around the
camera's y-axis (the world's z-axis).
I found that having both
representations of the camera direction was useful;
it's up to you how you handle it.
However you store the camera state, remember that you need
to get a viewing transformation corresponding to that state
into the MODELVIEW matrix at the beginning of every frame.
Since it is very easy to get lost in 3D worlds, your program should
have a RESET button which brings the camera back to the starting
Have your program print out a message when it starts up, describing
all the button and mouse controls. This is a big help to the user.
Perhaps an even better solution is to use GLUI, a graphical user interface library, HOWEVER, I'd suggest getting your camera to work with the keyboard and mouse FIRST!
The holodeck code reads in the file grid.ppm which it
uses as a texture.
You'll want to find and use textures more appropriate to your
world; for instance, the image at the top of this page uses an
image of sand for the ocean floor.
You can find lots of texture images by vigorous Web surfing.
To convert an image in .gif, .jpg, .tiff,
or some other format, into .ppm, you can use xv or gimp
on the department Unix machines. On Windows, I use a free program called
Remember that texture images for OpenGL have to have dimensions
which are a power of two, eg. 128x256.
Modeling a fish with two Bezier patches and some polygons would
be perfectly acceptable. You could texture-map an eye onto it.
Here is some code which draws one
Bezier surface which could be the front of a fish.
Bezier surfaces are drawn in OpenGL with evaluators:
see pages 495-512 in the OpenGL book.
A 3D fractal plant, or piece of coral, would be
quite appropriate. Use an L-system. You can use
glutSolidCylinder and glutSolidSphere, etc.
Some shells are not too hard to define mathematically.
Pages 372-378 in the textbook (Hearn and Baker) discuss making fractal
terrains, techniques which would also be good for making rocks.
It's pretty easy to texture map a rock. You may want to look on the web for other resources since this is not our text book.
Reading in models you find on the Web is also fine for this part of
If you use Mr. Robbin's code, or someone else's code, to read in models,
acknowledge the source and the author of the code
(including URL, if appropriate) in your README file.
You should also acknowledge the source of models, textures, and anything
else that goes into your project that you find on the Web or elsewhere.
Notice what happens to your object when you reshape the window.
The gradual fade of the floor into the background in the image
above is done using the fog feature of OpenGL.
Try it, it's easy and it's great for oceans.
Remember to make the color of the background the same as the color of
the fog, using glClearColor.
Since the holodeck floor is a single square, it is easy to fly off
the end once you start navigating.
It is much nicer instead
to give the user the illusion of moving in an infinite
You can do this by
drawing the part of the
infinite floor that lies
underneath the camera, wherever the camera happens
Combined with fog, it gives a very compelling undersea effect.
Notice that this is not the same as moving the floor along with
the camera, which gives no illusion of motion at all.
What to turn in
Turn in all the source files of
your program, the executable, the Makefile, any input data files,
and a plain text documentation file