CPSC 324, Fall 2002
Lab 11: Hierarchical Graphics

OUR FINAL OpenGL LAB brings us to the
topic of hierarchical computer graphics. You will be using the
classes defined in the header file, Models.h,
that was handed out in class. Using these classes, you can
build a data structure, known as a scene graph, to represent
a scene. One of the classes, Model, represents an object
that consists of other objects. This makes it possible to construct
hierarchical graphics models. You can animate the scene by changing
color or transformations applied to the objects.

You will need a copy of the folder /home/cs324/opengl-models-starter
for this lab, so you should copy it into your own account. Generally,
there are only a few places where you need to make changes in order to
create a new program. You will probably have to add some variables to
gl_canvas.h so that you can use them to do the animation. You
certainly need to change the definition of the createWorld
function in gl_canvas.cc. This is where the actual scene is
constructed. And to do animation, you will have to rewrite the
timerEvent function. In my "car-world" example, I defined three
new variables (moonRotate, sunRotate, and carRotate) of type Rotate*
in gl_canvas.h, and then I wrote these modified versions
of the two functions in gl_canvas.cc. This program produces a world
that contains a sun, a moon, and a flat world with some trees and a car:

During the lab, you will be working on a simple hierarchical model. This
will be graded during the lab. A programming exercise based on the lab
will be due the week after Thanksgiving.

In-class Exercise:

Since a "solar system" is one of the canonical examples of a hierarchical
computer graphics model, let's make one. You should keep your copies of
Models.h and the programming
for car-world handy so you can refer to them. Keep in mind that, by default,
the x- and y-values that are visible in the world are in the range
-5 to 5.

The solar system will consist of
a blue earth, a yellow sun, and a gray moon. The sun and the moon will
give off light. The sun will go around the earth as the earth goes around the
sun.

To begin, add two variables of type Rotate* to gl_canvas.h.
These will represent the rotation of the moon around the earth and
of the earth around the sun.

In gl_canvas.cc, rewrite the createWorld function. Start
by removing the commands that create the simple example scene. (Leave in
world, xRotate, yRotate, and worldVies.) Create
a moon-model that consists of a visible gray sphere and a positional light,
both at (0,0,0). Use some emissive color for the sphere.

Now, create an earth-model that consists of a blue earth at (0,0,0)
and a moon that is translated by a fixed amount along the x-axis away from
the origin and is also subject to the rotation transformation that will make
the moon rotate around the earth. The moon should rotate around the
y-axis.

Finally, add the earth-model and a glowing yellow sun to the world.
(Put a sphere and a positional light at the origin.) Add the
earth-model, translated by a fixed amount along the x-axis and also subject
to the rotation that will make the earth rotate around the sun.
The earth should rotate around the y-axis

If you compile and run the program at this point, you should see the
sun, earth, and moon lined up from the center of the screen to the right.
The earth should be illuminated both by the sun and by the moon. You might
want to adjust the sizes, positions, or brightnesses of the objects.

To make the scene animate, you should rewrite the timerEvent method
to change the angles of rotation in the transformations that move the earth
and moon. The moon should rotate about 13 times faster than the earth.
For example, increase the earth angle by 1 and the moon angle by 13.

Show me your running program during lab. This is worth 5 points.
You can add a frame from the animation to your Web page, but this is not
required.

Programming Exercise:

The second part of the lab is a programming exercise that will be due
after Thanksgiving. It is worth 15 points. You should create a more
complex and interesting animation using opengl-models-starter.
The model in your program must be hierarchical. That is, it must
use objects of type Model that contain other objects.
One nice possibility is to create a mobile. I will talk about this
possibility in class.