JMU CS488 - Computer Graphics Applications
Help Policies Solutions Study-Aids Syllabus Tools
Programming Assignment 7


1 Overview

For this assignment you must use your Matrix and Vector classes/templates from programming assignment 5 and your 2-D rasterizer from programming assignment 6 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 Existing Classes/Templates/structs

A simple struct that encapsulates a triangle has already been created for you. It should be self-explanatory.

In addition, part of meshUtilities has been implemented.

This implementation makes assumptions about the locations of various header files, but you can change them.

3 Detailed Specification

The specifications for the classes in this assignment are available in "documentation format". That is, you are being provided with the documentation for the classes, and your implementation must conform to the documentation.

4 A Development Strategy

You should not have to make any changes to your earlier classes/templates. You should decide whether your want to copy them to the directory/folder for this assignment or just #include them from the appropriate directory/folder.

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 Tests

You should probably perform initial integration tests with a simple 3D shape, like the following cube:

Note that, since we are only working with triangles, each face of the cube consists of two triangles. Note also that, since the cube will fill the entire window if it is scaled, I would omit the call to scaleAndTranslate() when working with the cube.

Also, recall that line segments that cross \(z = 0\) can be "torn" so you should be careful when creating your test cases. (You do not need to correct for "tearing".)

You must ultimately 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[]) {
   int               depth, height, width;   

   width  = 801;   
   height = 801;
   depth  = 401;   
   
   // Use a  PPMFrameBuffer
   //FrameBuffer* fb = new PPMFrameBuffer(width, height);
   // Use an SDLFrameBuffer
   FrameBuffer* fb = new SDLFrameBuffer(width, height);
   rasterizer = new Rasterizer3D(fb);


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

   scaleAndTranslate(triangles, width, height, depth);


   // Setup the rasterizer
   rasterizer->useTrimetricView(PI/6.0, PI/4.0);
   rasterizer->clear(GRAY);   

   // Draw the triangles
   rasterizer->draw(triangles);
   fb->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 fb;
}
  

Remember to test different projections and different rotations.

7 Submission

You must submit .pdf files containing the images generated by your implementation for all of the files mentioned above using Canvas.

8 Grading

Points will be awarded based on the correctness of the images generated by your implementation.

Copyright 2020