Assignment 1 - 3D Wireframe Renderer
Due Wednesday Oct. 16, 2019 at 3:00 PM
Overview
In this assignment, you will extend the code from Assignment 0 to write a program in C++ that reads in a description of a scene and rasterizes one or more wireframe models based on the objects in the scene as a PPM image output. The graphics pipeline for the rasterization process proceeds as follows. First, geometric, camera, and perspective transformations are applied to the points in our scene to transform them from world space into normalized device coordinates (NDC). The points in NDC are then mapped onto a pixel grid as screen coordinates. From there, Bresenham’s line drawing algorithm is used to outline the triangular faces of each object in the scene to produce an image of the desired wireframe models. You will implement this entire pipeline in the assignment.
Before you begin, you may want to review the assignment material with these lecture notes. The files for this assignment can be downloaded here. More in-depth details for the assignment will be given in the sections below.
Note! A new small extra credit component of the assignment has been added.
Your Assignment
As we said above, your task for this assignment is to implement the graphics pipeline for rendering scenes of wireframe models. The scenes for this assignment are described with an extension of the file format that you worked with in Part 3 of Assignment 0. Let us explain the additions to the file format with the following example file:
What makes this example file different from the files that you worked with before are the camera and perspective parameters that are stated at the top of the file:
The position and orientation lines together give you the information needed to compute the matrix that transforms points in the scene from world coordinates to camera coordinates. The perspective parameters allow us to form the perspective projection matrix that converts our points from camera coordinates to normalized device coordinates (NDC).
The objects: token marks an end to the camera and perspective parameters, and the rest of the file follows the format of the files from Part 3 of Assignment 0. We see that the above example file specifies two .obj files to be parsed: cube.obj and cube2.obj. And these two .obj files are associated with the labels cube and cube2 respectively. The rest of the file specifies sets of transformation data that are to be applied to copies of our objects. In particular, this example file asks for two copies of cube and two copies of cube2, each copy getting its own set of transformations to be applied.
Your task is to write a program in C++ that takes as input a file with the above format and outputs a PPM image of the specified scene (with desired and resolutions). The input of your program should be read from standard input as so:
xres and yres are integers that specify the and resolutions of the output image.
To help guide you, we have broken the task of writing this program into 6 parts:
Once you have successfully implemented Bresenham’s line algorithm for all line slopes, you can use it to outline every face in each object-copy to draw the wireframe models. You can fill in the pixels of your output with whatever colors you like as long as the output looks appropriate.
The essence of the algorithm is to trade intensity/color information for the limited spatial resolution. Not counting the starting pixel, which would always be set at full intensity, you would always set two pixels, one pixel above the other, to different intensities. To compute the intensity, as you step horizontally in the first octant, the floating point value for the slope, “m,” (also in the first octant) is added to the previous “y” value, and the new “y” is separated into an integer part “yi,” and a remainder, “f,” which is a floating point value less than 1.
Then the two pixel intensities (one above the line and one below) are set at intensity “f” and “1-f”, assuming the intensity range goes from 0 to 1.
This uses intensity information instead of spatial information to more “smoothly” represent the line. If “y” is a perfect integer, then the remainder “f” is zero, so one might not need to draw the pixel that is above the line. This is what was done for the starting pixel.
The following code fragments may be useful, for use in strategic parts of the code.
Within the hw1 folder should be a folder called data. Inside the data folder are various scene description files in .txt format (plus the necessary .obj files) that you can use to test your program. The correct image outputs for each scene description file are also in the folder as 800x800 .png files. You can use these images to verify whether your program is working correctly.
Please do your work for this assignment in the hw1 folder of hw1.zip.
What to Submit
Before submitting, please comment your code clearly and appropriately, making sure to give details regarding any non-trivial parts of your program.
Submit a .zip or .tar.gz file containing all the files that we would need to compile, run, and test your program. In addition, please submit in the .zip or .tar.gz a README with instructions on how to compile and execute your program as well as any comments and information that you would like us to know.
We ask that you name your .zip or .tar.gz file lastname_firstname_hw1.zip or lastname_firstname_hw1.tar.gz respectively, where you replace the “firstname” and “lastname” fields with your actual first and last name.
Please submit your zip or tar.gz to moodle in the area for Assignment 1.
Written by Kevin (Kevli) Li (Class of 2016).
Links: Home Assignments Contacts Policies Resources