Computer Graphics (CS4300) 2012F:
Assignments 4 and 5

Assignment 4 is DUE: 9pm, October 25, 2012
Assignment 5 is DUE: 9pm, November 7, 2012

Assignment 4 is Worth: 5% of your final grade
Assignment 5 is Worth: 10% of your final grade



This assignment is separated into three parts. Your handin will need be able to run each part as specified, but some parts will likely be best implemented by re-using code you wrote in prior parts. For full credit, you must organize your work so that code shared between parts is not copied and pasted. For example, in Java you could write the code for the earlier part as a class C and then extend that class for the later part. [It is ok to update the implementation of C as you work on the later part as long as it also still works correctly for the earlier part. It is also ok to write a single program that you can run with different options to enable the features needed for each part.]

Many aspects of this assignment, such as triangle rasterization with barycentric interpolation and coordinate transformations, may be available as functions in various 2D and 3D graphics libraries. You are allowed to use any such library you like, subject to the course policies on third-party code. Of course, it will be up to you to make sure the library you choose is actually capable of performing exactly the required functions, and that you are using it correctly. For this relatively basic 3D assignment it is likely to be nearly as easy to write all the required code on your own as it will be to learn and correctly use a library.

Input File Format

All parts of this assignment will require your program to read an ASCII text input file that describes a list of triangles. Each line of the file specifies the vertex coordinates and vertex colors of one 3D triangle in the order

symbol symbol symbol symbol symbol symbol symbol symbol symbol symbol symbol symbol symbol symbol symbol symbol symbol symbol

The coordinates of vertex symbol are symbol and the RGB color is symbol.

All values are whitespace separated (one or more spaces or tabs) and given in ASCII floating point in the following format: (a) an optional leading + or - symbol; (b) between 1 and 4 decimal digits; (c) an optional fractional part consisting of a decimal point and between 1 and 4 decimal digits.

Your program must ignore any lines that begin with the # character.

All vertex coordinates are in units of floating point pixels. For rasterizing, you can round fractional pixels in the input to the nearest integer.

The symbol color components range from 0.0 (none of that color) to 1.0 (full brightness of that color). Any color component that is (incorrectly) specified in the input as less than 0.0 should be treated as 0.0; any color component that is specified as greater than 1.0 should be treated as 1.0.

Some example input files are given below.

You may either

For example, if the input file is named “triangles.tri”, either of the following implementations is acceptable (these lines also assume a Java program called HW4_Sample, but the form is similar for other languages):

java HW4_Sample triangles.tri


java HW4_Sample < triangles.tri

(or just bring up a filechooser when your program starts).

Assignment 4: Rasterizing Triangles in 2D

Write a program to display a list of colored triangles in 2D with barycentric interpolation.

Here are some individual triangles that were generated by such a program.
RGB at the verticesOther RGB Colors at the Vertices

Assignment 5 - Part I: Wireframe Rendering in 3D; Backface Culling; 3D Rotation and Zoom

Write a program to display a list of triangles in 3D with wireframe rendering, backface culling, and interactive rotation and scaling.


Assignment 5 - Part II: Flat Shading

Write a program to display a list of triangles in 3D with flat shading, barycentric interpolation, backface culling, and interactive rotation and scaling.

All of the requirements of part II also apply to this part, except that instead of wireframe rendering, you will perform flat shading with respect to a directional light source producing parallel rays of white light in the direction symbol.


  1. Let the vertices of a triangle be symbol and let the corresponding specified vertex colors be symbol.

  2. Compute symbol (not ignoring symbol coordinates). The triangle is degenerate iff symbol, and you may ignore it. Otherwise, compute symbol.

  3. Compute symbol. The triangle is backfacing iff symbol. Otherwise, compute symbol for each of the original vertex colors and rasterize the triangle using barycentric interpolation of symbol.

Example Files

The following two were converted from original models found on the web, first with MeshLab and then with

NOTE: since these models are not convex, do not expect them to render with correct occlusion, even with backface culling. For example, in this view of the duck, the tail is occluded (behind) the head. But the triangles on the front side of the tail are not backfacing, and are not culled. And they happen to be drawn after the triangles in the head, which results in an image that does not look right. Do not worry about this problem for this assignment (if you really want, you can try to fix it for extra credit, e.g. by implementing the painter’s algorithm to always render triangles back-to front, also called depth sorting).


Turn In

Make sure your README file contains your name and the date and documents:

Follow these instructions for packing up your project and submitting it.


Out of 100 total possible points, 60 will be assigned based on the organization, functionality, clarity, and documentation of your code. For Assignment 4, 40 will be assigned based on the graphic output of your program. For Assignment 5, 20 will be assigned based on the graphic output of your program, and the remaining 20 will be based on the interactive features, including object rotation and zoom.

Harriet Fell
College of Computer Science, Northeastern University
360 Huntington Avenue #WVH-446,
Boston, MA 02115

The URL for this document is: