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
.
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.
#include
them from the appropriate
directory/folder.
Rasterizer3D
object will need to construct and
use (and then destruct) a Rasterizer2D
object.
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.)
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):
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.
.pdf
files containing the images generated
by your implementation for all of the files mentioned above
using Canvas.
Copyright 2020