CS 3451, Spring 2012

Homework 1: Transformations and Projection

Due: 11:55pm, Monday, February 6, 2012

Objective

The goal of this assignment is to write the routines that allow a user to transform and view 3D graphical objects. In particular, you will write the routines for creating line drawings of both orthographic and perspective scenes. You will use Processing to write all of this code. The transformation routines that you create will implement a matrix stack and will allow you to arbitrarily rotate, translate and scale an object. To make this assignment easier, routines will be provided for you that implement line clipping and line drawing. The images that you create for this exercise will be three dimensional line drawings of scenes with no hidden surfaces or filled polygons. All of the lines will be uniformly white so that you will not need to perform color interpolation.

Routines You Will Create

In this assignment you will be creating routines that mimic the behavior of several OpenGL library routines. Below is the list of routines that you will create for this assignment.


Code Provided

Two routines will be provided for you that will perform the necessary clipping and drawing of lines. This means that there is no need for you to write any clipping or line drawing code. These routines are:


What You Will Write

You will write code ONLY in the file matlib.pde. All of your routines should be contained in matlib.pde. We have provided a "dummy" version of matlib.pde that you can use as a starting point for creating your own complete version.

All test samples have already been contained in the provided code. Pressing keyboard keys 1-9 and 0 calls the 10 test samples respectively.


Suggested Approach

First, become familiar with using the draw_line routine. Second, implement the matrix stack and the gtTranslate and gtScale commands. Test them out by applying the current transformation matrix to the line endpoints and then just draw lines by ignoring the z-values. Third, write the gtOrtho command. This should be fairly straightforward once you have already drawn some lines by ignoring the z-values of the transformed vertices. Fourth, implement the gtPerspective command. The best way to test out this routine is to carefully work out some simple test cases on paper and match the execution of your code with these worked-out examples. Finish by implementing the gtRotate command. Logically this command should be implemented together with gtScale and gtTranslate, but it is a little tricker. You will need to create and manipulate matrices and vertices in order to implement the transformation routines. Here are possible definitions:
class gtMatrix {
  float[][] m;
  gtMatrix() {m = new float[4][4];}
}

class gtVertex {
  float[] v;
  gtVertex() {v = new float[4];}
}
Because the last row of a typical transformation matrix is 0 0 0 1, you may instead choose to use 4 by 3 matrices. You may also decide not to store the implicit 1 that is the fourth element of a homogeneous coordinate of a vertex. Two important routines that you will need to write are matrix-matrix multiplication and matrix-vector multiplication. Your choices of data structures will affect the details of these routines.

You will probably write routines that perform operations such as matrix multiply and vector cross-product. It is easy to accidentally write a routine that clobbers some of the results if the routine is called using the same matrix more than once. For example, the invocation "mult_matrices (a, b, b)" is meant to multiply a time b and put the result in b. If you are not careful, however, you will overwrite part of b before you use all of the values in that matrix. The best way to avoid this is to place all your results in a temporary matrix and then copy the results to the final destination when you are finished.


Authorship Rules

The code that you turn in entirely your own. You are allowed to talk to other members of the class and to the Professor and the TA about general implementation of the assignment. It is, for example, perfectly fine to discuss how one might organize the data for a matrix stack. It is also fine to seek the help of others for general Processing/Java programming questions. You may not, however, use code that anyone other than yourself has written. Code that is explicitly not allowed includes code taken from the Web, from books, from previous assignments or from any source other than yourself. The only exception to this rule is that you should use the GT Graphics Library routines and the test code that we provide. You may NOT use other library routines for matrices and stacks. You should not show your code to other students. Feel free to seek the help of the Professor and the TA's for suggestions about debugging your code.


Development Environment

You must use the Processing language which is built on Java. The best resource for Processing language questions is the online or offline Processing language API (found in the "reference" subdirectory of the Processing release).


Sample Results

pic01.jpg pic02.jpg pic03.jpg pic04.jpg pic05.jpg pic06.jpg pic07.jpg pic08.jpg pic09.jpg pic10.jpg
All 10 results zipped: hw1_results_png.zip


What To Turn In

Compress the whole folder (not merely the files within the folder) into a zip archive and submit it in T-square for Project 1. The zip archive should be included as an attachment. The filename should be "lastname_firstname_project_1.zip". For example, Greg Turk would create "turk_greg_project_1.zip" for his homework 1. When unzipped, it will produce the folder "ldraw" containing the files "ldraw.pde", "gtGraphics.pde", "lines.pde", and "matlib.pde".