Computer Graphics Lab 4: 2-D Transforms and Pipeline

Ben Mitchell and Zach Pezzementi

Vectors and Transform Matricies

Rather than use simple data types, we decided to implement our vectors and transforms as C++ classes. This allows us to do many nice things. First of all, we can hide the implementation of all the messy matrix math from the user; in fact, the user couldn't touch the matrix data if they wanted to. Rather, the matricies are manipulated by applying transforms to an identity matrix. When you instanciate a tranform object, it contains the identity matrix; you then give it commands like xform.rotateZ() or xform.translate(). This applies the relevant transform to the current matrix stored by the object, so that a sequence of transformations can be put into one object.

At this point we need a vector, which we decided to just go ahead and implement as 4-vectors so that we could easilly extend our code to 3-D. With the magic of operator overloading, we can then say things like "V2 = VTM * GTM * LTM * V1" and wind up with the intuitive result (assuming, of course, that all these variables are correctly defined before the calculation).

This is very powerful, as it means that the VTM, GTM, and LTM are simply instances of the transform class, and all the points in our model are vectors. In fact, we also have a class which is a list of these vectors, so that we can apply a transform to an entire list of vectors with a single operation.

Given this transformed list of vectors, we can then assign a point list to be equal to the vector list, and then call our good old drawPolygon routine to create the appropriate image.

With this setup, it was very easy to create LTMs for the various pieces of our enterprise model, a GTM to transform the entire model, and a VTM to take things into screen space. The individual parts of the model are lists of vectors, except for the planet and the saucer section, which each consist of two points, one in the center of a circle, and the other on the radius. Since we only scale proportionally for this application, this is enough to transform a circle. It was quite easy to then set up some simple for loops to iteratively change the LTM, GTM, or VTM and write out images at each step, which allowed us to create frames for animation. This means that we can easily change each of these things independantly, which makes it simple to change the motion of models with respect to one another, or the motion of the viewing window with respect to the model space, independantly of one another. It's also very easy to do things like make extra copies of a model, or flip them around and put them different places (see the last animation).

Since our library generates PPMs, we then used convert to get gifs, and gifsicle to animate our collections of frames. We used this process to create several different animated gifs. Here they are. They represent several extensions.


The Enterprise: a still frame of our model:


A small animation:


And a medium one:


One with a moving camera:


And one with two copies of the ship: