
Fall 2006
22C:151 Introduction to Computer Graphics
Assignment 5
Due: Wednesday, September 27th at 11:59 pm
Goal: Setup a 3D OpenGL program with perspective and simple geometry, and utilize matrices to manipulate objects.
Problem 1 (20 points): Write an OpenGL/GLUT program that renders 3D geometry into a 640 ×480 window.
•Part A (3 points): Set the projection matrix for 3D instead of 2D. Set your view frustum with a near plane at a
distance of 1, a far plane at distance 100, and a field of view of 90◦. Set the aspect ratio correctly. Hint: If you
are building on existing code, this should replace gluOrtho2D(). Also note the aspect ratio should not be 1.
•Part B (1 point): You can use either gluPerspective() or glFrustum() to do Part A. In your README
file, write the equivalent calls (to gluPerspective() and glFrustum()) that give the projection matrix
required for Part A.
•Part C (1 point): Set your eye point (using gluLookAt()) to have the eye at (0,5,5), looking at (0,0,0) with
an up vector of (0,1,0).
•Part D (2 points): Remember that in OpenGL you can equivalently think of “moving they eye” or “moving
the scene.” A single translation and a single rotation can give you a matrix equivalent to that generated by
gluLookAt(). What translation and what rotation are required? Write the answer in your README.
Hint: The answer may not be your first thought. You can check your answer by comparing your answer
with the matrix gluLookAt() creates. You can get this matrix by reading back the modelview matrix
using the following code:
GLfloat gluLookAtMatrix[16];
glMatrixMode(GL MODELVIEW);
glLoadIdentity();
gluLookAt( <...fill in correct values...>);
glGetFloatv(GL MODELVIEW MATRIX, gluLookAtMatrix );
printf("%f %f %f %f\n", gluLookAtMatrix[0], gluLookAtMatrix[4], <...etc...>);
printf("%f %f %f %f\n", gluLookAtMatrix[1], gluLookAtMatrix[5], <...etc...>);
<...etc...>
•Part E (3 points): Write a function (with no parameters) that draws a cone of height 2 with a radius of 1 at the
base.
–The tip of the cone should be at (0,0,2) and the base should be on the z= 0 plane (so (1,0,0), (-1,0,0),
(0,1,0), and (0,-1,0) are all on the cone’s base).
–The tip of the cone should be green and the base should be red at (-1,0,0) and blue at (1,0,0). Along the
base of the cone, you should smoothly interpolate between red and blue (e.g., the color at points (0,1,0)
and (0,-1,0) should be a dark purple color (0.5,0,0.5)).
–This function will be called from inside your display function, so it should not call glClear(),glFlush(),
or glutSwapBuffers().
–Suggestion: Use two triangle fans. One for the triangles on the base of the cone (in the z= 0 plane) and
one for the conical part. Since your cone will be made up of triangles, use at least 40 triangles to make it
appear smooth.