Lab 4: 2-D Transformations and the 2-D Viewing Pipeline
Andrew Cantino & Will Moss

This is lab 4 of Computer Graphics.

Sections:

3D Transformations

For this lab we created a series of 3D matrix transformations that we can apply to a new class created called a point3D, which is a 4-vector storing values for x, y, z, and h. These transformations and represented in a 4x4 matrix. All of the transformations are mutators, meaning that they take the current matrix and do the transformation on that matrix. Listed below are the functions we developed to do these transformations:

class matrix:
translate3D(double tx, double ty, double tz)Causes the matrix to translate by the specificed amount in x, y, and z.
  
scale3D(double s)Causes the matrix to scale by the specified amount in all directions
scale3D(double sx, double sy, double sz)Causes the matrix to scale by the specified amount in each direction
scale3D(point3D center, double s)Causes the matrix to scale by the specified amount in all directions, around the specified point
scale3D(point3D center, double sx, double sy, double sz)Causes the matrix to scale by the specified amount in each direction, around the specified point
scale3D(point3D center, double theta, double sx, double sy, double sz)Causes the matrix to scale by the specified amount in each direction, around the specified point, at the given angle
  
rotate3Dz(double theta)Causes the matrix to rotate by the specified amount
rotate3Dz(point3D center, double theta)Causes the matrix to rotate by the specified amount, around the specified point
  
sheer3Dx(double shx)Causes the matrix to sheer in the x direction
sheer3Dy(double shy)Causes the matrix to sheer in the y direction
Note: We also overloaded the multiplication (*) and inplace multiply (*=) operators for matrix so that matricies are correctly right-multiplied. Additionally, point3Ds know how to be multiplied by matrices.

Star Wars vs. Star Trek

For this lab we were asked to create a model of the Starship Enterprise or another cool (nerdy?) spaceship. Andrew did model the Enterprise and Will choose to model an X-Wing from Star Wars. Will's model required 9 instances of the unit box and 6 instances of the unit line. Andrew's model required a unit circle and 4 instances of a unit box.
Here are the models we developed:

Will's X-Wing

Andrew's Enterprise
(Rough version)

We were then asked to create a model of the spaceship orbiting a planet. Will made two images, one with it orbiting a simple circle (representing a planet) and then another of it orbiting the moon. Andrew made an image of his Enterprise, filled, with circular gradient shading, orbiting a nebula.

X-Wing orbiting a metaphorical planet
(Click image for animation)

X-Wing orbiting the moon over Cape Cod
(Click image for animation)

Enterprise orbiting
Click for larger version!

Andrew's Enterprise
(Filled w/ Background)

For the final part of this lab, we were asked to create an image that scrolled past the rotating ship, using our viewing pipeline. Below are the images we created:

X-Wing fly-by
(Click image for animation)

Enterprise Fly-by
(Click image for larger version!)

Questions
  1. Who did you work with on this assignment, and what tasks did each of you do?
    Will Moss and Andrew Cantino worked together on this lab. We developed the respresentation and the general process together, as well as helping eachohter out with the mathematical parts. In terms of coding, Andrew wrote the translate and scale, as well as some of the matrix methods, and will wrote the rotate and some matrix methods. Will also wrote the simple viewing pipeline.
  2. Describe the mechanicsm you developed for handling the global transformation parameters and matrix.
    We defined a matrix (GTM) for our global transformation parameters. Then, we defined our space ships using small local transformations of the unit box and unit circle in a model space of size about 10x10. Then, when drawing the ships to the screen, we simply had to do the matrix multiplication GTM * LTM (local transformation matrices) * point. This allowed us to easily translate, rotate, and scale the whole space ship by modifying only the single GTM matrix. This made it especially easy to make the ships orbit their planets/nebulae because we could simply apply to the GTM a translation to the edge of the image, then a rotation around the center of the image, causing the ship to rotate around the planet.
  3. Describe the mechanicsm you developed for handling the viewing pipeline parameters and transformation matrix.
    We defined a view transformation matrix that was premultiplied in every transformation in our code. We also defined a function that returned a VTM given a viewing window and a number of rows (the columns were just calculated to be proportional to the defined viewing window). This allowed us to call the getVTM function on every iteration of our code to generate a moving view frame that also scaled the model to the proper values for image space.
  4. Once you had the code in place, what was the process and how difficult was it to modify the view window and position of the Enterprise?
    Once the code was in place, it was resonably simple to modify the location and position of the enterprise. We had implemented a VTM and a GTM, the VTM took care of the viewing window and the GTM took care of the global positioning of the ship. Since we had overloaded the multiplication operator for our matrix class, we were able to then type VTM * GTM * LTM and use the output of that to transform all our points.

Extensions

General Extensions:
As extensions, Will and Andrew both made animated gif movie sequences of our space ships rotating around planets and scrolling off the screen while rotating. Additionally, we shaded our ships and Andrew used a circular gradient to fill the Enterprise's dish. We also put our ships over cool space backgrounds! Finally, we also had a creative use of multiple ships -- see below.

Space Warp!
Additionally, we added a new pen option: alpha. We could always do alpha blending, but now it's a pen option, called with image.setPenAlpha(unsigned char) and image.getPenAlpha(). Here is an example image using both alpha blending and multiple versions of the Enterprise made with some nested for-loops:


Andrew's Space Warp!
Click for large, full-quality version.

[Back to Lab Index]