CSC 418/2504 Computer Graphics Assignment 2 solution


Original Work ?


5/5 - (3 votes)

Part A [50 marks in total]

Below are 3 exercises covering different topics from the weeks of class up to the midterm. They require
thought, so you are advised to consult the relevant sections of the textbook, the online lecture notes and
slides, and your notes from class well in advance of the due date. Your proofs and derivations should be
clearly written, mathematically correct, and concise. All questions require showing the steps toward the
solution, and marks will be subtracted if this is not the case.

Even if you cannot answer a question
completely, it is very important that you show your (partial) answers and your reasoning. Otherwise
your TA will not be able to award you partial marks. Both Part A and Part B must be done individually
and electronically submitted. Part A must be in PDF format, by scanning your handwritten solution or
by using LaTeX/word to typeset it.

1. Viewing and Projection [19 marks]

Perspective projection preserves linearity but does not preserve parallelism. Indeed, the
perspective projection of two parallel 3D lines will intersect at a 2D point called the vanishing
point, and this point will generally not be at infinity.

a) [9 marks] Let
l1(u) = p1 + ud
l2(u) = p2 + ud
be the parametric equations of two 3D lines, where p1, p2 are 3D points and d is a 3D
vector, all represented in the camera’s 3D reference frame. The parameter u is a real
number. Assuming that the camera’s focal length is f and its image plane is aligned with
the xy-plane, give an expression for the homogeneous coordinates of the line’s vanishing

b) [5 marks] Even though it does not happen in general, there are special cases of parallel 3D
lines that do project to parallel lines under perspective projection. Give an orientation
vector d for which the lines in part a) project to parallel lines.

c) [5 marks] Let
1(u, v) = p1 + ud + vd’
2(u, v) = p2 + ud + vd’
be the parametric equations of two parallel 3D planes, with p1, p2 and d defined as in (a).
d’ is another 3D vector and v is a real number. Give an expression for the projection of the
line of intersection between these two planes. This line is usually called the vanishing line
and, when the planes are parallel to the ground, it coincides with the horizon. Hint: Use
you solution for part (a).

2. Surfaces [14 marks]

To create a vase shape, the following parametric curve can be rotated about the z axis (a
and b are constants defining the shape of the curve):
̅( ) (


a) [5 marks] Give a parametric equation and appropriate parameter bounds for the
resulting surface of revolution p(u, v) in terms of the surface parameters u and v.

b) [5 marks] Give an equation for the tangent plane at point p(u, v) in terms of the
surface parameters u and v.

c) [4 marks] Give an equation for the outward-facing unit normal vector at point p(u, v) in
terms of the surface parameters u and v.

3. Visibility [17 marks]

This illustration shows a top-down view of a 3D scene, where each blue edge corresponds
to a planar square perpendicular to the image plane (i.e. coming out of the page) and the
eye of an alternative viewpoint lies in the image plane. The short vectors are normal
vectors. The eye location is illustrated by the black dot.

a) [4 marks] Assuming the particular scene and camera placement shown above, is it
possible to exclude any polygons from rendering? Explain your answer.
b) [8 marks] Draw a BSP tree for the above scene by adding the segments in the labeled
order (i.e. from ‘a’ to ‘h’, breaking segments as necessary).
c) [5 marks] Describe how your tree will be traversed when rendering the scene from the
eye location specified.

Turning in Your Solutions to Part A

To submit your solution to Part A, make sure that the contents of the PDF file are legible and include it
inside the folder named a2 in the tgz file for your submission for part B.
solid w/ outlines
hinge joint
Figure 1: 3D Robot penguin.

Part B: Animating & Rendering a 3D Object [50 marks in total]

In this assignment, you will create a simple keyframe animation tool, and use it to animate a 3D character.
3D geometry and DOFs
You will first define a penguin in 3D as in Figure 1. The penguin will have 24 degrees-of-freedom (DOFs)
that define the pose of the penguin at any time. In assignment 1, the DOFs were just the 2D rotation angles
of the penguin’s joints and the opening widths of the beak.

For this assignment, the DOFs will be as follows. The penguin’s knee and elbow joints are 1 DOF
hinge joints that can only rotate forward and backward; the penguin’s beak has a single open-close DOF
(as before); the hip and shoulder joints each have 3 angles of rotation; the penguin’s head has one degree
of freedom so that it can rotate around the neck axis. Finally, the penguin can globally translate and rotate
in space, i.e., a translation/rotation is applied to the entire penguin. (This adds 3 DOFs for translation
and 3 more for rotation.) Rotation should be about the penguin’s (approximate) centroid, regardless of the

(a) [10 marks] Design the parts in terms of suitable shapes and deformations, and draw them using
OpenGL. Your penguin does not need to look exactly like the one in the figure (e.g., the geometry can
be more complicated). You do not need to draw circles for joints; drawing eyes or other decorations
is optional, but they should not obscure the shape and motion of the character.

Rendering style

Your program should include five rendering modes: wireframe, solid, solid with outlines, “shiny metal,”
and “matte:”
(b) [10 marks] Basic polygon rendering styles: The first three rendering styles are shown in the figure.
Solid and wireframe can be created using the same geometry routines (e.g., glVertex calls), but
with different settings for glPolygonMode.

Solid can be drawn together with outlines, by rendering wireframes fill after the solid fill has been rendered within the display function, but using
glPolygonOffset on the wireframe rendering. (See the OpenGL reference books for information on these routines). The user should be able to choose the rendering style in the user interface.

Note that in general, it is not required that the outlines are perfectly crisp; drawing them perfectly is
not easy in OpenGL, or required for this assignment.

(c) [5 marks] Material properties: In addition to the above styles, the user should also be able to draw
the penguin using solid polygons with a “metallic” or “matte” appearance. To do this, you will need
to assign material properties to your polygons via glMaterial and define a light source using
glLight. Again, refer to the manual for information on how to set up light sources and shading in

(d) [10 marks] Light source control: You should add controls to the user interface to allow the user to
control the position of the light source around the object. You should define the light source position
to be sufficiently far away from the object so that it does not interfere with the object’s motion. For
the purposes of the assignment it suffices to move the light source on a circle parallel to the xy-plane,
of a sufficiently large radius.

Keyframe Animation

The second goal in this part of the assignment is to create a keyframe animation tool that allows you to
set keyframes, and then play back an animation that interpolates those keyframes. The values of the DOFs
at each frame will be defined by a function q¯(t) that defines the values of the DOFs at each time t. This
function will be defined by interpolating keyframes. Each keyframe comprises a time and a pose, that is,
a pair (ti
, q¯i
), where the pose q¯i
is a 24-dimensional vector containing the DOFs at time ti
. That is, q¯i
contains the value of each joint angle, the gripper distances, and the global translation and rotation of the
torso at time ti

(e) [5 marks] The animation tool should work as follows. Each DOF in the character will correspond
to a “spinner” in the user interface; adjusting a slider will change the corresponding DOF for the
character shown in the display window. Pressing the button “Update Keyframe” sets the current
pose as a keyframe in the animation system, and then pressing “Start/Stop animation” plays back
the animation. Use of the starter code is required. Be sure to include a sample set of keyframes with
your electronic submission.

(f) [5 marks] When you play back the animation, the smoothly varying pose q¯(t) should be computed by
Catmull-Rom interpolation of the keyframes (this interpolation will be covered in the next tutorial).
Helper Code
We have provided helper code that has many of the data structures and user interface elements already in

The compiled skeleton code will display a solid shaded cube located at the origin. You can move the
cube using the UI (Root→translate x/y/z). A sample keyframe file has been provided and can be loaded
to demonstrate the animation and render-to-file capabilities. Your main job is to define the procedures for
rendering the character at a given time, and for computing the interpolation. See the code for details.

To unpack, compile and run this demo on CDF, download the file a2.tgz and use the following commands
tar xvfz a2.tgz
cd a2/penguin3d
There are several different parts to this assignment, and it will be easiest to tackle them one at a time —
and debug each part in turn — rather than trying to implement everything at once. First, design the animal
and the joint angles.


We recommend that you render each polygon with a solid color, perhaps a different
color for each face. Make sure you’ve got Z-buffering working properly so that visibility is correct. Make
sure that the character moves properly when adjusting the controls. Be careful when designing rotations.

If you represent an angle between 0 and 360 degrees, then do not animate angles near 0 since that might lead
to a discontinuity. Similarly, if you represent angles between -180 and 180 degrees then you will be best
to keep your angles, on average, near zero rather than near 180 or -180 degrees. We suggest you enable
lighting and tackle the last two rendering styles (metallic, matte) only after you are done with everything

Turning in your Solution to Part B
All your code should remain in the directory a2/penguin3d. In addition to your code, you must complete
the files CHECKLIST and REPORT contained in that directory. Failure to complete these files will result
in zero marks on your assignment.

(g) [5 marks] The REPORT file should be a well-structured written (or diagramatic) explanation of the
basic components of your implementation. The description should be a clear and concise guide to
the concepts, not a simple documentation of the code.

Note that this file should not be thought of as a substitute for putting detailed comments in your code.
Your code should be well commented if you want to receive full (or even partial) credit for it.

To pack and submit your solution, execute the following commands from the directory containing your
code (i.e., a2/penguin3d):
cd ../../
tar cvfz a2-solution.tgz a2
submit -c csc418h -a A2b a2b-solution.tgz (if registered for CSC418)
submit -c csc2504h -a A2b a2b-solution.tgz (if registered for CSC2504)