JMU
Programming Assignment 4


1 Overview: For this assignment you must use your Matrix and Vector classes/templates from programming assignment 2 and your 2-D rasterizer from programming assignment 3 in a rudimentary 3-D rasterizer. Specifically, you must write some utility functions for working with triangular meshes and a Rasterizer3D class that can render wireframes.

This assignment is about 3-D computer graphics. The only new aspect of C++ that you need to use is a list.

2 Getting Started: You should not have to make any changes to your earlier classes/templates. Hence, you should not have to copy them -- you should just be able to #include them from the appropriate directory/folder.
3 Existing Classes/Templates/structs: A simple struct that encapsulates a triangle has already been created for you. It should be self-explanatory.

Triangle ( Header )

4 Detailed Specification: The detailed specifications/designs for the functions in meshUtilities and Rasterizer3D class are available on-line:

meshUtilities ( Header , Implementation )

Rasterizer3D ( Header )

5 Hints: You might find the following hints helpful.
  1. A Rasterizer3D object will need to construct and use (and then destruct) a Rasterizer2D object.
  2. The drawTriangle method in the Rasterizer2D class must be passed a 2x3 matrix. The triangular mesh contains 4x3 triangles. So, they will need to be pre-multiplied by a 2x4 matrix before being passed. (You should be able to figure out what the 2x4 matrix must look like.)
6 Integration Testing: You must perform integration testing with the following data files:

The output from these tests should look like the following (when not rotated):

teapot.gif
ball.gif
fighter.gif

Your driver should be something like the following:

#define PI 3.14159265358979323846

Color             GRAY  = {102,102,102};
Color             WHITE = {255,255,255};
Color             YELLOW = {255,255,0};   
int               view;
list<Triangle*>   triangles;
Rasterizer3D*     rasterizer;   


int main(int argc, char* argv[])
{
   FrameBuffer*      frameBuffer;
   GraphicsWindow*   window;
   int               depth, height, width;   

   view = 0;
   
   width  = 801;   
   height = 801;
   depth  = 801;   
   
   window      = new GraphicsWindow(width, height);
   frameBuffer = window->getFrameBuffer();
   rasterizer = new Rasterizer3D(frameBuffer);


   // Read and scale the triangular mesh
   // (In an IDE you may need to hard-code the path to the file)
   if (argc == 1) read("teapot.txt", triangles);
   else           read(argv[1],      triangles);

   scaleAndTranslate(triangles, width, height, depth);


   // Setup the rasterizer
   rasterizer->useTrimetricView(-view*(PI/4.0),0.0);
   rasterizer->clear(GRAY);   

   // Draw the triangles
   rasterizer->draw(triangles);
   frameBuffer->show();
   
   
   // Delete the triangles pointed to by the elements of the list
   for (list<Triangle*>::iterator i=triangles.begin(); i!=triangles.end(); i++)
   {
      delete (*i);      
   }
   
   delete rasterizer;   
   delete window; // The window will delete the FrameBuffer
}
  

Remember to test different projections and different rotations.

7 Submission: In addition to the normal materials, your submission must include hardcopies (of screenshots) of the integration tests.
8 Grading: Your implementation must work correctly for you to receive credit for this assignment.

Copyright 2014