CPSC 4050 / 6050

Spring 2014

Oh Shoot!

Homework Assignment 2

Due: Tuesday, February 4, 2014

side view
        of spheres

Problem Description:

You are to write a very basic raycasting renderer that renders a set of spheres arranged in space. Shoot a ray from the camera viewpoint through the center of each pixel, and color that pixel the color of the closest sphere hit by the ray. If the ray hits no sphere, color the pixel black.

Your camera should be located 1/2 meter from the origin at (0, 0, 0.5) and be aimed along the negative z-axis. The viewscreen should be centered at the origin; parallel with the x-y plane, and with sides parallel to the x and y-axes. The height of the viewscreen should be 0.4 m, and its aspect ratio is 5/4. The scene should consist of five spheres with the following properties (all measurements in meters):






(-0.3, 0.1, -0.5)



(0.0, -0.2, -0.8)



(0.3, 0.3, -1.1)



(0.1, 0.2, -0.3)



(-0.2, -0.25, -0.4)

The figure above shows a side view of the scene, with the +x axis pointing towards you, out of the image.

Basic Requirements:

Your program should be named raycast. The program should be able to render and display either a parallel projection or a perspective projection of the scene, and should allow a variable pixmap resolution for rendering the scene. The program commandline should have the format (note: the square brackets denote optional arguments; they should not be included on the command line.):

raycast [l|v] [pixwidth] [filename.ext]

where l indicates parallel projection viewing, and v indicates perspective projection viewing, and pixwidth is a positive integer denoting the width of the pixmap in pixels. The default viewing option is v and the default pixel width is 250. If filename is provided, the image should be saved to an image file with this name,
when the user presses the w key, using the filename extension given by ext to determine image file type. Pressing the w key should do nothing if no filename is provided. The program should quit when the user presses either the q or the ESC key.

You should test your program by rendering very small images. Once the program is working try a higher resolution of at least 750 x 600 pixels and save this image.

Advanced Extension:

Introduce planes to the scene. For example, the five spheres could be placed in an open box formed by the intersection of five planes, top, bottom, left, and right planes, and a back plane.

Expected Output:

Here is what the output of the basic assignment should look like:

Orthographic View
Perspective View


Please write the program in C++ , using OpenGL and GLUT graphics routines for the display. Make sure to put a header in each file of your code that gives a description of the program or object, your name, the date, and instructions on how it is used.