### Abstract

The goal of this assignment was to implement 2-dimensional transformation matrices, and then use these transformations to draw images. In particular, we drew an image of a spaceship using these transformations, then drew the space ship rotating around a planet. The final goal was to create a viewing pipeline for our code.

*On the image, the Spaceship Enterprise is presented, the required image #1.*

### Description of Task

Our first goal was to set up the functions for the transformation matrixes. To do this we had to define two new structures: Matrix and Vector. The matrix is a two dimensional array, and is used to do transformations based on matrix multiplication. The vector is an array that holds the four integer values, the first three are the x, y, and z coordinates (the z-value is default to zero, as we are working in only two dimensions). The fourth value is the homogenous coordinate.

### How we accomplished the task

After defining the two new structures, we had to code their corresponding functions. The Matrix_multiply function set up the algorithm for general multiplication of two matrices, which is used in several other functions to multiply a transformation matrix by a vector.

In our code, we implemented four transformation matrices, Matrix_scale2D, Matrix_rotateZ, Matrix_translate2D, and Matrix_shear2D. These functions each take in a Matrix which is going to undergo the specific transformation, and two doubles which affect how it is transformed.

- The scale function takes in the doubles "sx" and "sy", which represent the factor by which to scale the matrix (i.e. sx = 2 makes the matrix twice as large in the x direction).
- The rotate function takes in cth and sth, the cosine and sine of the angle the matrix will be rotated along the z-axis.
- The translate function takes in tx and ty, which represent the distance in the x and y directions by which the matrix will be translated.
- The shear function takes in shx and shy, which represent how much the matrix will be sheared in the x and y directions. The larger the value, the more the image will be sheared. A value of 1 represents a 45 degree sheer. (i.e. a line orthogonal to the x axis will have a 45 degree angle with the x axis after a shear of 1 in the x direction).

These functions place the two doubles into a transformation matrix, and multiply the transformation matrix by the matrix being transformed. The locations of the doubles in the transformation matrix determine the way in which the matrix is transformed. For brevity, I will omit a detailed explanation of the specifics of these changes. A very good explanation to matrix math and 2D transformations can be found in Fundamentals of Computer Graphics, 2nd edition, on pages 135-146.

The next step was to draw an image of a space ship by doing transformations on "unit shapes", i.e. a 1x1 square, or a circle of radius 1. Through a series of translations, scales, rotations, and shears, an image of a space ship was generated. *You can see the skyPod (it's an iPod in the skies...) with fire coming out of the engines on the neighboring image.*

The next step was to have this space ship rotate around a planet. This was accomplished by using placing this spaceship into an image containing a planet, and applying a rotation matrix which rotated the space ship around the center of the planet.

The final part of this assignment was to set up a viewing coordinates pipeline. This was done by creating a view transformation matrix (VTM). We scaled the VTM to the size of the image and translated to the origin of the image. Then, we used the VTM to transform each part of the scene before finally drawing it.

### What we learned

We learned how to use matrix multiplication to transform two dimensional images, as well as how to use apply a view transformation matrix to an image to change where we view it from. This is nice, because instead of having to completely change the way we code an image to get a different perspective, we can simply change the VTM to look at a different part of the image. It was also cool to see our images start to come to life through animation.

### Images

On the backdrop. Starry, starry sky... (you can notice we stick to the same motif as last time )

Orbiting the planet from a stationary reference point.

Orbiting the planet with the pipeline.

Battlestar Galactica-like crazy-camera sequence with a spaceship departing from the planet. Accomplished while messing with different zoom values for the General Transformation Matrix.

It's spacequake! Ruuuuuuuuun!