Lab 4: 2D Transformations and the 2D Pipeline

Alex Benn and Andrew Frampton

The Task and Our Approach

Our first goal was to implement a matrix struct along with a series of associated functions often used in image structure manipulation, such as multiply, scale, rotate, transform point, and transform polygon. All matrices are 4x4, to allow for 3 dimensional manipulation in the future along with translation factors. Prof. Bruce Maxwell provided some test code; here is the output image from that test code.


Figure 1: Output of Test Code

The second goal was to apply these matrix transformations to a set of polygons, and then display the polygons using the previously-developed drawing code. The model we chose to create was the Starship Enterprise E from Star Trek. We used fan-made schematics found online to come up with appropriate size ratios, which we then used to stretch and scale the elements of the ship. Here's a picture of the output:


Figure 2: Enterprise E

The third element of this project involved animating the rotation of the ship around a planet. This can be done by maintaining a global transformation matrix, which is repeatedly premultiplied by further rotations, and is then applied to the polygons making up the ship. The output images are then concatenated together into a single animated GIF file, shown below.


Figure 3: Animation of Revolution of Spaceship

The fourth and final step involved pipelining the manipulation of the view in such a way that the view is completely independent of the elements of the scene. This allows for arbitrary manipulation of the view, for example panning across our scene from before. Figure 4 demonstrates just such a pan.


Figure 4: Pipelining of View Transformation

Lab Questions

  1. Alexander Benn and Andrew Frampton worked on this project jointly. Frampton focused on developing and implementing Matrix manipulation code, such as multiplication, copying, and transposing. He also made some important modifications to the enterprise design. Benn focused on adapting Prof. Maxwell's code to work with the newly-developed Enterprise model, along with animation and pipelining code.
  2. The global transformation matrix is used to animate the movement of the ship around the planet. In order to keep the planet in the center of the frame, we only applied the GTM to the polygons and lines of the ship itself. To manipulate the GTM, we first initialized it to the identity matrix, followed by a translation and rotation; the amount of rotation increased at each frame of animation. Since the GTM was different at each frame of animation, the polygons were copied before being transformed, so that the polygons themselves could be re-used for the next frame.
  3. Since all motion of the viewframe was relative, we set up the VTM size and orientation once, at the beginning of the program, and then premultiplied it by a constant translation.
  4. Once the code was in place, all that was necessary was a repeated application of the transforms on the GTM and VTM. This allowed us to assemble the models once and manipulate them arbitrarily without destroying the models themselves.
  5. We extended the project by making two spaceships orbiting the same planet. This was accomplished by applying a 180° rotation to the GTM and drawing the spaceship again. Here's the picture:


    Figure 5: Animation of Two Ships