Home | People | Curriculum | Projects | Resources | Media

Computer Graphics

CMSC 212

Haverford College

Fall 2003

Lab 6

Friday, December 5

Ray Tracer for a Sphere

This project extends work from the previous lab assignment, and should not be started until the previous one is completed successfully (see instructor a more precise definition of "successfully").

Design and implement a simple ray tracer application to render a sphere using the Phong illumination model and the algorithms presented in class. You should only need OpenGL call to render a pixel in a color, and the ray tracer should determine the RGB components of that color. Please consider the following build path:

  1. Either become familar with the vector and matrix classes in the cs212 include directory at the path /Network/Servers/ or design and implement your own classes -- you will need solid classes with reliable methods.
  2. Render a simple sphere centered along the z-axis using flat shading (i.e., a binary approach where either the ray hits the sphere and displays the sphere color, or misses and displays the background color) -- it done properly, a circle should appear.
  3. Add a single light source at a location, and use the Phong illumination model to determine the color of each pixel -- this will likely be a slower, iterative step requiring "tweeking" the range of colors acceptable. You may want to vary only one color component initially, setting the others to constant -- eventually you can compose the three. If I recall correctly, you will want the color of the light to be opposite of the color of the sphere to render specular highlights.

The general format of the universe.ent file is (again) given here:

camera                  //string
e.x e.y e.z
l.x l.y l.z             //9 doubles
up.x up.y up.z
projection type         //string(parallel || perspective || frustum)
//if parallel:
xmin xmax
ymin ymax               //6 doubles
zmin zmax
//if projection:
height                  //3 doubles
distance from camera
//if frustum
xmin xmax
ymin ymax               //3 doubles
zmin zmax
num of objects          //int
for each object, a filename (.ent)

Grade Candy: to be considered only after completing the basic assignment above ...

Again, please submit either a file or a folder into the cs212 dropbox using the name convention login.6 (e.g.,

Links for CS212 -- Other CS212 Assignments: 0 1 2 3 4 5 6 7

Haverford College Page maintained by John Dougherty, David Wonnacott, and Rachel Heaton.
Computer Science Department, Haverford College.