CS 248: Introduction to Computer Graphics

Pat Hanrahan


Handout

Overview

This assignment is designed to familiarize you with hierarchical 3D modeling and viewing transformations, as well as keyframe animation. You are asked to write very little code (at most 20 lines), which will interpolate keyframes. The bulk of your time will be spent using our custom-made hierarchical MOdeling and ANimation (MOAN) system to design, animate, and direct articulated figures.

MOAN is documented extensively on the class WWW pages. Its input is a text file describing a scene tree, which represents a modeling hierarchy. The figure below shows a simple scene tree describing a sphere squeezed between two cylinders. Rendering takes place by traversing the tree (an inorder walk), each node performing some GL calls specific to its type when visited:


A scene tree for a sphere squeezed between two cylinders. The light node required to make the objects visible (see the text) is omitted here for clarity.
The scene file for this scene tree is available on the Leland file system:
/usr/class/cs248/assignments/assignment3/examples/simple.sc
MOAN's window shows a predetermined, static view of the input scene; in particular, the camera is at the origin, and looks down the -z axis. In order to interactively view a scene from varying angles, place a joint transformation node near the root of the scene tree, and thus move the scene instead of the camera using MOAN's interactive editing facilities. Even if interactive camera movement is not desired, some transformation is necessary to move the scene away from the origin and place it within the viewing volume; this is the role of the leftmost translation in the figure.

MOAN also supports animation via keyframing. That is, you may manually associate different values for each parameter of a joint transformation with different frames, called keyframes; MOAN interpolates these parameter values at in-between frames, and can thus play back a smooth animation.

Finally, MOAN supports lighting. That is, scene tree nodes can create lights and affect the appearance of subsequent primitives - using glLight*() and glMaterial*(). You need not worry about lighting for this assignment, except for one detail: make sure your scenes define at least one light, so that your objects are not lost in the dark; to this end, create a single light node near the root of your scene by copying a light definition from an example scene file.

Before you try to use MOAN, you should review all class material relating to hierarchical modeling and animation:

  1. Chapter 3 of the OpenGL Programming Guide.
  2. Lectures 11 and 12 of the Course Notes.
  3. Lectures 11, 12, 13, and 16 (especially the BBOP video).
  4. Chapters 5 through 7 of Computer Graphics: Principles and Practice.
Also, you should read the on-line documentation of MOAN carefully before commencing work on the assignment. Please consult the class WWW pages on how to invoke MOAN from your account.

The philosophy of MOAN: MOAN is a simplified relative of SoftImage and Open Inventor, two commercial modeling and animation systems. In the past, this assignment required students to write actual OpenGL code. MOAN shields you from coding details and encourages trial-and-error experimentation by eliminating the need to recompile every time you change your model. MOAN is too simple and crude at times, as it is designed to match very closely OpenGL's approach to modeling; still, it's a good stepping stone to commercial systems. To complete the assignment, you need not look at MOAN's source code (except for the interpolation routines which are fully encapsulated); however, as the source code is very simple and extensively documented, you are welcome to peruse it and see how simple it is to code up the very powerful abstraction of hierarchical modeling.

Warning: MOAN is a brand new product, designed and coded by your TA Toli. As such, it may still have bugs. So

Modeling an Articulated Figure (20 points)

Your first task is to compose a scene tree which models an articulated figure. We suggest that you try modeling the skeleton described in lectures 11 and 12 of the Course Notes. However, if you feel so disposed, you may model any other animal or plant of sufficient complexity (like Audrey II in the Little Shop of Horrors). "Sufficient complexity" means that your scene tree should
  1. (10 points) have a depth of at least 5, containing at least 20 transformation nodes (either static or joint transformations), at least 5 of each type (scale, translation, rotation),
  2. (5 points) contain at least 20 primitives, and
  3. (5 points) represent a realistic object. Given the limited capabilities of MOAN, we do not expect you to produce Jurassic Park dinosaurs; a caricature, a stick figure, a 5 year old's drawing turned 3D, or anything bearing the semblance of a real object is adequate.
Of course, nodes that have no influence on the final renderings do not count towards meeting the sufficiency requirement. Make sure the object you choose to model fits in the conceptual framework of the subsequent parts of the assignment - it should have a "head" of some sort, etc. Save your scene tree for this part of the assignment in a file named figure.sc.

Hints:

Animation (40 points)

Your next task is to animate your figure. To this end, you add joint transformation nodes in your scene wherever limbs of your articulated figure join; alternatively, you may substitute joint transformations for static ones. Your end goal is to make your articulated figure go through a sufficiently complex cyclical motion, such as two steps in a moonwalk, a graceful pirouette, or a dolphin's jump through a hoop. "Sufficiently complex" means that
  1. (20 points) your scene tree should contain at least 10 animated joint transformation nodes, at least 5 translations and 5 rotations, each with at least 7 keyframes,
  2. (10 points) the figure should have the same configuration in the first and last frames of the animation (that's what makes it a cyclical motion),
  3. (5 points) the animation should be smooth, with adequate keyframes to prevent sudden jumps, and
  4. (5 points) the animation should depict a plausible, familiar movement, in a realistic fashion. As we mentioned earlier, we do not expect you to reproduce Species monsters moving in caves; however, we want something more than the "mating ritual of Magellan penguins dancing in anti-gravity fields," consisting of European - no offense intended; the writer is European, too - avant-garde artists in black, violently jerking their limbs all over the place.
Save your work in a new file named animation.sc.

Hints:

Multiple Figures (10 points)

Your next task is to create a scene tree representing two of your articulated figures standing opposite one other, and facing each other (3 points). Also, one of the figures should be animated as in the previous part while the other one stays almost stationary; in particular, the latter figure's "head" moves in such a way as to constantly "look" at the former figure while it's going through its movement cycle of the previous part (7 points). Save your work in a new file named pair.sc.

Multiple Views (20 points)

MOAN supports camera nodes which are ignored during rendering. Instead, immediately before the scene tree is traversed for rendering, a pruned traversal takes place to determine the viewing transformation. In particular, during this preliminary traversal, the scene is traversed in the same fashion as when rendered, but primitive nodes are ignored; also, as soon as a user-specified camera node is encountered,
  1. the adjoint A of the matrix on the top of the modelview stack is calculated,
  2. A post-multiplies a regular viewing matrix whose entries are determined by the camera node - this matrix is generated using glOrtho() or gluPerspective(), depending on the camera type -,
  3. the result becomes the new viewing transformation, and
  4. the traversal is pruned (aborted).
Your task is to extend pair.sc with camera nodes that allow the viewer to look at the scene as if the camera was placed at the "head" of each of your two articulated figures (10 points); also, each camera must point in the general direction of the other articulated figure throughout the animation (10 points). Save your work in a new file named views.sc.

Hint: figure out by hand what effect is achieved by traversing camera nodes in the fashion stated above. Trial-and-error experimentation using MOAN may be helpful, but concentrated thinking while taking a shower will achieve better results. Browsing through section 8 of lecture 9 in the Course Notes, as well as section 4 of lecture 15, might help...

Interpolation (10 points)

Your final task is to write the routine of MOAN that interpolates the parameters of joint transformations using Hermite, or "cubic," interpolation. To shield you from the internal representation of joint transformations, we have encapsulated all code performing keyframe interpolation in two files, namely interpolate.h and interpolate.c (or interpolate.C). These files declare and define functions for both linear and Hermite interpolation; we have written the code for the former, and we ask you to fill in the code for the latter. You should not need to write more than 20 lines of code. Make sure that your code
  1. (2 points) modifies no keyframes by accident,
  2. (2 points) does not miss any in-between frames,
  3. (2 points) interpolates all keyframes,
  4. (3 points) makes the derivative of the interpolated parameter tend to zero as the animation approaches any keyframe, and
  5. (1 point) is not excessively slow. You will only lose this point is your code is really inefficient, e.g. due to multiple passes over the in-between frames.
Consult the class WWW pages on setting up your account for this part of the assignment. Also, read interpolate.h to understand exactly the interface of the function you have to write.

Hint: understand the code of our linear interpolator before starting to write the Hermite one.

Extra Credit

As stated in the overview, MOAN supports lighting. Use this mechanism to enhance the realism and aesthetic appeal of your scenes. Save your extra credit work in new scene files. Reminder: chapter 6 of the OpenGL Programming Guide covers lighting in detail.

For more extra credit, build a scene consisting of 12,000 figures riding unicycles on a Hilbert curve. (Just kidding.) Good luck using the raptors for that.

Conclusion: Turning in Your Work.

You need to turn in the scene files from the first four parts of the assignment, namely figure.sc, animation.sc, pair.sc, views.sc, as well as your version of interpolate.c or interpolate.C. If you do any extra credit work, please submit it alongside a text file named README describing your work. You will find detailed submission instructions on the class WWW pages.

If any of your files fail to parse, your grade for the corresponding parts of the assignment will be reduced by 50%.

hanrahan@cs.stanford.edu
tolis@cs.stanford.edu

Copyright © 1996 Pat Hanrahan and Apostolos "Toli" Lerios