Skip to end of metadata
Go to start of metadata

CS 351 - Assignment 5:Transformations and Viewing

Titobiloluwa Awe and Elena Kirillova


In this project, we created a set of functions and fields for our graphic display to implement 2D and 3D transformations. We created a matrix object, a vector object and different transformations in the 2D and 3D plane. We then used these objects and transformations to implement a simple imaging pipeline.

Problem Description

Our task for this project was to create a matrix library as specified in the lecture notes. We had to create a host of functions for scale, translation and rotation around the x, y and z - axes. We had to create two major functions : Matrix_view2D and Matrix_view3D. These were the functions that implemented the the imaging pipeline in 2D and 3D. 


To create the matrix library, we had to create a new file called matrix.c that held all of the functions that we were going to create and we followed the exact specifications inside of the lecture notes. To create the matrix_view3D function, we had to use a view3D object that had separate fields for the view of an object in a 3D image. These included the vrp, vpn and vup, which we used to calculate the u vector which we then normalize. We also took note not to modify the view object so as not to have any side-effects inside of our image.

Matrix library

Test of the non-view parts of our library (spaceship firing a lazer):

2D view matrix function

Demonstration (lines translated across the image and rotated along z axis):

3D view matrix function

Demonstration (cube rotating along the z and x axes):

Our 2D scene

In our scene we drew a star made of line objects and translated those lines across the scene with an input image on the background.

Make a thousand wishes scene:

Here we added the 2D scaling for the lines:

Our 3D scene

A pyramid leaving the image:


Over this project we build a matrix library of 2-D and 3-D transformations.  Simple imaging pipeline were created in both dimensions, which examples were presented in the above examples.

Most of the project we spent debugging our library files with the functions created in previous projects. We learned:

  • We have to be very careful in C with managing space.  Small error with allocation, sizeof() can completely destroy the image.
  • Homogeneous for vectors and points has to be set to 1.0, not to 0.0 and must not be reassigned to 0.0 at any point.

So when writing bigger libraries where files get built on top of each other, it is really useful to test everything straight away when your right it, so that you will not end up having no idea which among all these files could have caused a problem you are having at the moment.