Fall 2011 CS5310 Computer Graphics Assignment 3

This assignment was originally prepared by Professor Marsette (Marty) Vona.

Goals

Assignment

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

The coordinates of vertex are and the RGB color is .

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 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

or

java HW4_Sample < triangles.tri

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

Part I: Rasterizing Triangles in 2D

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

Part II: 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.

Part III: 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 .

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

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

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

Example Files

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

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

Follow the usual turn in instructions.

Be sure to document in your README file

Grading

Out of 100 total possible points, 60 will be assigned based on the organization, functionality, clarity, and documentation of your code. 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 #202WVH
Boston, MA 02115

Phone: (617) 373-2198 / Fax: (617) 373-5121

Last Updated:
The URL for this document is: http://www.ccs.neu.edu/home/fell/CS5310/Assignments/CS5310F2011prog2.html
hit counter