CS160 Program 3: Selecting, Lighting, and Shading
Due Friday, November 21, 2003 MIDNIGHT
Submit Prog3 directory using CATS Submit Program
Objectives:
Learn to use OpenGL shading, lighting, materials, textures,
and picking.
Note: this is the last official assignment and your last chance
to make up late day. You cannot make
up late days on the project. Make every attempt to get this
in early if you now have late days.
As in the past, the assignment is available before we have
discussed how to do all the things involved. However, you
can implement it gradually. You can set up the GUI, and
design the grid with a hill, and make the sun revolve,
and create the plane.
Students have suggested some alternative methods, which are
generally more complex that those we ask for. I have put in
square brackets [] suggestions for alternatives that are acceptable.
This is a challenging assignment. Start early.
Assignment:
This assignment will be to design and animate a terrain scene,
with a moving sun and a movable rocket.
You will design the terrain by picking vertices from a
polygon grid that is initially a randomly perturbed height
field.
-
The Camera (10%): You should be able to control the camera
as in the previous assignment, but be able to freely
in space, not just over the ground and basket.
You can use (x,y,z) positions for the camera location if you
like, rather than spherical coordinates.
Be able to zoom out enough to see the whole terrain.
Look at the center of the terrain.
[If you want, you can
implement three more sliders and change the lookat point,
also, but it isn't required in the assignment.]
-
The Terrain (25%):
Your ground plane will be represented as an array of vertices
representing a 51x51 grid (at least). Having an odd-sized grid
means you have one center vertex. Two coordinates of each vertex
will be constant and determined by the grid (as in assignment 1).
The third coordinate of the grid will be the height, which can
be above or below the zero height value.
The vertices around the boundary of the grid should always
have a constant height value and not be changed by sliders.
For the initial scene, make the grid height gradually slope
upward to the center of the grid, to make a hill that is
in height 30% of the width of the grid. You could do this
with a sine curve or a gaussian function, whatever is easiest
for you. Draw the grid polygons using triangles this time,
not quadrilaterals. You can still use an array, but there will
be two triangles in each cell.
The shading color of each vertex in the grid will be determined
by its height value. Let -1 to 1 represent the range of
possible height values. If a vertex is less than -.5,
it will be colored dark blue; from -.5 to 0, colored green.
From 0 to 0.5, colored brown; and from 0.5 to 1.0, colored
white. Pick colors that you find attractive.
Make the white (snow) and blue (water) very shiny, and the
brown very matte (non-shiny), and the green in between.
We will be using OpenGL materials for this, so the colors
will vary depending on how the light strikes it.
[If you wish to make a more complex material model where the
colors gradually change, that is fine, but unnecessary.]
To implement lighting, you have to set normal vectors for
each vertex. To make the shading smooth, you need the
normal to be the average of the normal vectors of the triangles
that surround each vertex. Your grid data structure should therefore
contain a vector parameter giving the normalized vertex normal
for each vertex. You can calculate these for the initial
terrain, and then recalculate them for any vertex that you move.
-
Picking (20%): Be able to select a grid polygon by
moving the mouse over it and clicking the mouse button.
This is done using OpenGl picking.
This becomes the active polygon, and should be colored yellow.
If you pick outside the grid, so that nothing is selected,
there will be no active polygon and none will be colored yellow.
Using three "Height" sliders on the GUI, be able to move the height
of the selected triangle's vertices up or down throughout the
possible range (see above for possible values).
The sliders' bounds should be -1 to 1, but this should represent
a range of possible values from -30% of the grid width to
30% of the grid width.
[If you wish to make an alternative strategy where you can pick
multiple triangles, that is fine as long as there is some way
to alter height selectively. I.e., make the height change
more rapidly for the triangles near the center of the picking region
than for the outskirts; or, be able to change the size of the
pick region on the GUI.]
-
The Background (5%): Read in a texture map of a sky of
some other reasonable scene as a background. This should
always be in the background, no matter where the scene is
viewed from. You can achieve this effect by texture mapping
a large polygon and drawing it before you change the camera
position or do other transformations.
If you want to make an environment surrounding the whole
scene, you can, but it isn't required for the assignment.
Put in a texture toggle button to turn off drawing the
background, because texture mapping may slow the drawing
down on some computers.
-
The Sun (10%): Create a sun object that revolves in a circle
around (above and below) the terrain scene. The sun will
be a sphere, as well as a slightly yellow (mostly white)
point light source. Have a "Sun" toggle button on the GUI that
causes the sun to start revolving. The sun will continue to
revolve until the button is turned off. When the button is
turned off, the sun should continue to shine, and remain in
the last position. It should start from this position
when you press play again. The sun should
be bright enough, and the ground an appropriate reflectivity,
that you can clearly see the effect of the sun moving across
the terrain. The sun should not light the terrain after it
has set, of course. The sun should be unrealistically close
to the terrain, so that you can watch it go around the entire
cycle. It should not go through the terrain, however.
-
The Plane (20%):
Create an airplane object. This can be as simple as a cone,
with wings, or more complex. (If you want, you can read in
a geometrical model; not at all required.)
Color it as you like but make it shiny.
You should be able to control the position and orientation of
the plane using 6 sliders on the GUI. The sliders should
make it possible to roll, pitch and yaw the plane.
There should be a spotlight pointing from the nose of the
plane forward at all times. It can be white. Put two
red spotlights lights on the wings, pointing forward.
The brightness should be appropriate for the scene, and you
should be able to clearly see all three spots on the white
top of the mountain when the plane is near it and pointing at it.
-
Other Lights (5%):
Make a dim white ambient light that is initially on. This
should only be bright enough to see the general shape of
the terrain and objects. Make a button on the GUI to turn
this light on and off.
-
The GUI (5% beyond above):
The widgets that you will need are: one exit button;
three camera sliders similar to those in the last
assignment; six rocket sliders to rotate and translate
freely, including roll, pitch, and yaw;
one or four terrain sliders to raise or lower selected
grid cell points;
one sun toggle button to cause the sun to rise and set
over the scene as an animation, until the button is turned off
(you can independently turn the sun and off if you like);
one texture toggle button to cause the texture-mapped
background to turn on and off; and
one ambient light toggle button to turn on and off the
ambient light.
Submission
-
Submission must be done using
the submit utility from CATS. Run "quickhelp submit"
or "submit -m"
on a CATS machine to get more info on the submit command.
To submit the assignment, do the following:
- Create a DIRECTORY called "
prog3". It should
contain all the files required to make your program
compile/run.
- Run "
make clean" in the directory to ensure you
do not submit .o files or the compiled program, or you
will lose points for possibly over-filling the directory.
- From prog3's parent directory (if you are in the prog3
directory, type "
cd .."), tar the directory with
the command "tar cvf prog3.tar prog3".
I strongly suggest you untar it (see above) to check.
- Compress the tar file with the command
"
gzip prog3.tar". This will produce the file
"prog3.tar.gz" which you will submit.
- Submit prog3.tar.gz with the command
"
submit cmps160-jw.f03 prog3 prog3.tar.gz".
Questions?:
E-mail
amin@cse.ucsc.edu and
wilhelms@cse.ucsc.edu