COMP 4004: Advanced Computer Graphics (REVISED Jan. 25, 2006)
Slides:
Lecture 1: Introduction
Lecture 2: Files, Widgets and Coding
Lecture 3: Keyframing and Interpolation
Lecture 4: Complex Numbers and Quaternions
Lecture 5: The Arcball and Quaternion Interpolation
Reference Material:
The OpenGL Programming Guide (the Red Book), Version 1.0 (OpenGL 1.0). OpenGL is now up to 2.0 (Red Book 5th edition), but for the purposes of this course, this web version is nearly complete.
The OpenGL Reference Manual (the Blue Book), Version 1.0. Again, the current version of the Blue Book is 2.0, but this web version is good enough. The Blue Book consists principally of the man pages for the various OpenGL functions.
Assignments:
Coding Rules: All code used must be your own, must be code provided to you on this web page,
or (support) code in the form of free cross-platform libraries. See Lecture 2 slides for details. You may
also use code from COMP 3003.
A0: Rendering a Character (Worth 10%).
The task is to read in an ASCII text file describing a character and render it on screen.
All of this should be feasible based on your work in COMP 3003 last year.
You should set up a new GLUT main.cpp file instead of reusing files from COMP 3003.
You will be marked on code quality and comments as well as output.
Due: Friday, February 3, 4:00 pm.
- Read in the ASCII text file. See Lecture 1 slides for details of format.
- Render the character in a window with correct normals & shading.
- Document your code appropriately.
A1: Interpolation (Worth 10%).
Part I: Rotation
Download A1_rotate.zip . Add a makefile and compile it. When you run it, specify a file on the command line: e.g.
A1_rotate m2/747.m2
This code has the following features:
- It loads a .m2 file and renders it hierarchically. If you wish, compare it to your work on A0. Please note that the legoman and man files
have been edited to adjust bone origins, so you should not use the files from A0.
- There is an arcball for rotating the scene and the usual mouse controls for translation (shift-drag) and scaling (middle button drag).
- The 4 arrow keys and the '<' and '>' control Euler angle rotation: this is stored in each bone. Play with it and see how it works.
- The letter 'a' starts an animation sequence for which you will write angle interpolation code. Your code should interpolate a rotation
from the neutral (base) pose given in the text file to the new pose to which you have moved your character.
- The key '/' toggles between Euler/Cardan angle interpolation and quaternion interpolation. Your could should implement both.
- You should not need to edit any code except for Bone::Render(). If you do so properly, you will find that you can do full character
animation between the neutral pose and the new pose.
- It is strongly suggested that you work with the 747 model first, since this has only one bone. This will make your job much easier.
- The letter 'q' quits as usual.
Part II: Bezier Curves
Download A1_bezier.zip. Add a makefile and compile it. The only key command is 'q' to quit. The mouse drags the individual
points around. You should edit the display() routine so that it correctly displays the control polygon and the bezier curve. It would be nice if
it also had an option for turning the control polygon on & off.
A2: Flight Simulator with Collision Detection (Worth 15%).
Part I: Flight Simulation
Download A2_flightsim.tar. This code sets up some random bricks in 3 dimensions (in space), and renders
them with three grids (x = 0, y = 0, z = 0). Add to this code to get the simple flight simulator discussed in class. There are three distinct ways of doing this:
- Straightforward: Keep track of the plane's position (a point) and orientation (3 vectors or a quaternion) explicitly. When the keys are pressed, compute a suitable rotation matrix and apply to your stored position and orientation. Every time the idle() function is called, multiply the forward vector by the speed (controlled by keys '0' - '9') and by a constant that prevents you from moving too fast, and add it to the plane's position. In your display routine, you will want to
use your stored position and orientation to set up the modelview matrix using gluLookAt().
- More Elegant: Use a single transformation matrix to keep track of the plane's position and orientation. Update it in your keydown() and idle() routines. NOTE: this one is tricky, because you need to keep the *INVERSE* of the plane's transformation matrix to make it work properly: i.e. the matrix describes the transformation of the world into the view coordinates for the plane.
- Slick: Use the modelview matrix to keep track of the transformation for you. Note: this is essentially the same as the previous solution, but trickier to implement.
Part II: Collision Detection
Implement collision detection between your plane and the bricks you see floating in space. They each have a flag, isWireFrame. When you detect a collision, set this flag to true, and the blocks will render in wireframe. You should be able to fly around the environment turning blocks into wireframe by flying through them.
Since the bricks are convex, the test discussed in class for testing whether a point is outside a triangle should be all you need. Conveniently, the bricks are stored as a set of triangles, and the triangle class now has a routine Outside() which performs the test for you.
Your plane should be 4 units long, 1 unit wide and 1 unit high (i.e., it too can be represented as a brick), and you may find that the simplest approach is to add a function to the Brick class to test whether two bricks intersect.
Due Date: Monday, March 13, 4:00 pm.
A3: Reflecting Pool (Worth 20%).
In this assignment, you will be creating a small scene with several effects, roughly similar to this:

Part I: Shadows
Download A3_shadowpool.tar. This code is based on the running man assignment from COMP 3003, and renders
a running man next to a hole in the ground representing a reflecting pool. The 'a' key can be used to turn the animation on and off. Speed of the animation
can be controlled with the '+' and '-' keys. The position of the sun can be controlled with the arrow keys.
You should implement projected shadows to draw the running man's shadow on the ground.
Part II: Reflection
Implement reflection so that the man is reflected in the pool as he runs. As discussed in class, the equations are simplified because the ground plane is z = 0, and
the existence of the green ground means that you do not need to use stencil buffer tricks to restrict the drawing. As a bonus, if you rotate the scene, you can
see the man's reflection running upside-down underground. Remember also that you must flip the light position as well as the man.
Part III: Trees
Implement a method for drawing a tree procedurally, and place at least one tree in your scene so that it's reflection is visible in the pool.
Remember to cast its shadow as well. You will probably find the function drawTaperedCylinder() to be extremely useful for drawing parts of your tree.
Part IV: Rain
Add a particle system to draw rain.
Part V: Optimization
At this point, especially if you have multiple large trees, your animation may be running quite slowly. How would you optimize this scene? You do not need to
write the code for this. Your solution should be contained in a text file called A3_Q5.txt.
Happy coding!
Due Date: Friday, April 28, 5:00 pm.
Installing OpenGL on your home machine:
Students are encouraged to install OpenGL on their home machine, as this reduces dependence on a fixed lab time. Installing OpenGL &/or GLUT is up to the student: difficulties installing & / or running at home will not be taken into account when determining grades.
Information on installation on various platforms is given to help you get started. For further information, or if you are having trouble installing, please talk to the lecturer.
Windows
If you are running Windows 2000 or later, OpenGL should already be installed, but you will still have to download and install GLUT. Go here for details. Earlier releases of Windows may require separate installation of OpenGL.
Mac OS
If you are running OS X, then OpenGL and GLUT should already be installed, although versions of OS X prior to 10.2 had some problems with GLUT. You will have to install the Developer Tools if you wish to compile on OS X. These can be found either on one of the installation CD's, or at Apple's Developer web site.
Linux
If you are running Linux, there is no official implementation of OpenGL. There is however an open-source workalike library called Mesa 3D. It is nearly 100% compatible, and will certainly be sufficient for this course. Unfortunately, Mesa 3D renders in software, not in hardware, and is quite a lot slower, unless you also install a suitable set of hardware drivers. For nVidia cards, start at nVidia's driver page. For ATI cards, start at ATI's driver page.
Everything Else
For other operating systems, Mesa 3D will probably work, but there may be O/S-specific solutions available.