CS 351: Assignment #5

2-D Transformations and Viewing

Due midnight 7 October 2008 (yes, Tuesday night)

In this assignment you'll implement a library of 2-D transformations and then make use of them to build an object and a simple imaging pipeline.


  1. The first part of the assignment is to build a matrix library as outlined in the C and C++. While all of the transforms we will be using this week will be 2D transformations, we will still use full 4x4 matrices to represent them, exactly as outlined in class. To test your library, compile and run the C source file or the C++ source file. To help you debug, here is a listing of the output of the C code.
  2. For part two of this assignment, you will use your transformation library to create a model of a spaceship out of a circle centered at the origin of radius 1, and the points (0,0), (1, 0), (1, 1), (0, 1) that form a unit box. (The Enterprise works well as a model). You will need to create multiple instantiations of the unit box (and possibly the circle) in order to create the various parts the spaceship. Your spaceship should be aligned so that it faces to the left and the approximate middle of the ship is in the center of the image. You will use transformation matrices to scale, translate, and rotate all the pieces to the right place.

    The basic procedure you will use to draw the picture is as follows.

    1. Initialize a set of four points to the unit box,
    2. Build a set of transformation matrices that modify the unit box so it appears the correct size and in the correct location in the image for the various parts of the ship.
    3. Multiply the four unit box points by your resulting transformation matrices.
    4. Call one of your polygon routines (filled or unfilled) with the transformed boxes.
  3. Note that you can simulate the effect of translations and scales on the unit radius circle by applying the transformations to the circle's center and to one other point on the circle (like the point (1, 0)). Once you have completed the transformations, the transformed circle should be drawn at the new center point with a radius equal to the distance between the two transformed points. This will force the scaling to be uniform in x and y, unless you use two points on the circle (1, 0) and (0, 1) and then call your ellipse function with the appropriate radii. If you want the circle to scale non-uniformly and rotate arbitrarily, then you will need to generate a polygonal representation of the circle and transform the individual points (which is not that hard to do).

    Create one picture of your spaceship

  4. For part III of this assignment you will make your spaceship rotate around a planet. In order to accomplish this, you should undertake the following steps.

    1. In your code creating the spaceship from part II, add in a circle of reasonable radius such that the circle is situated below the ship with the center of the circle in the horizontal middle of the image. Your spaceship should now appear to be orbiting beside a planet (the added circle). Make sure your circle and the ship do not overlap (crashing into a planet is bad). Note: you may want to shrink your spaceship model from the previous step if it takes up most of the image.
    2. Create a new macro-rotation matrix that is simply a rotation around the center of the planet.
    3. Now, modify each part's transformation matrix by premultiplying it by the macro-rotation matrix. By modifying the angle of rotation in the macro-rotation matrix you should be able to make the spaceship rotate about the planet in a series of images. You can either turn in two pictures of your spaceship in two different locations around the planet, or you can create a movie using an animated gif.
    4. If you wish to create a movie, first write out a series of PPMs, one per frame of the animation. Then use convert to create the animated gif: convert *.ppm animation.gif
  5. For part IV (the last part) of this assignment you will create a simple viewing pipeline and add it to the code you have developed in parts I to III.
  6. The viewing parameters you should use for this assignment are the lower left and upper right corners of the view window (in world coordinates) and then the number of rows and columns in the output image. Alternatively, you can just provide the number of rows and then compute the number of columns based on the view rectangle aspect ratio.

    Your model coordinates should be in a standard orientation with the x-axis increasing to the right and the y-axis increasing up. Screen coordinates will be different.

    In order to create the viewing pipeline, you want to translate the view window to the origin and then scale it to the number of rows and columns in the output image.

    V = S(Cols / (view window Width), Rows / (view window Height)) T(-viewWindowLL)

    Make a transformation matrix VTM that holds this information.

    Before drawing any points, the transformation matrix for each component needs to be premultiplied by the VTM (both your spaceship and the two characteristic points of the planet). Make sure this is the last matrix in the sequence (furthest left) as shown below.

    Xt = [Viewing][Global][Model]

    The Model transformation will be individual to each part of your spaceship. The Global transformation would be the macro-rotation matrix from part III. The Viewing transformation is as defined above for task IV.

    Now you should be able to create a series of images where the view window slides across the scene as the spaceship rotates around the planet. As with the previous step, you can either turn in two images, or convert a series of them to gifs and create an animated gif showing a movie.



All writeups should suggest the format of a lab report. They do not have to be long, but need to provide enough information that I have some idea you knew what you were doing.

  1. Abstract: 200 word description (at most) of what you did and a picture to go along with it.
  2. Description of the task, in your own words. Be brief, but write it as though explaining it to a fellow student not in the course.
  3. Description of how you solved the task, including any key equations or algorithms. You should also include algorithms or descriptions of what you did for any extensions. Include pictures here.
  4. More pictures. Please put a caption on each picture explaining something about it. If you have nothing else, give it a name and indicate whose picture it is.
  5. Summary of what you learned.


Put your code files in your handin folder. Send the prof an email with the URL for your writeup (wiki or standard web page) when it's done. In either case, please edit the assignment handin page on the wiki so there is a link to your assignment.