Assignment 1 - 3D Wireframe Renderer

Due Wednesday Oct. 16, 2019 at 3:00 PM

pict

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:

camera:  
position 0 0 5  
orientation 0 1 0 0  
near 1  
far 10  
left -1  
right 1  
top 1  
bottom -1  
 
objects:  
cube cube.obj  
cube2 cube2.obj  
 
cube  
s 1 1 1  
r 0 0 1 0  
t -3 -3 -1  
 
cube2  
s 2 -2 2  
r 0 0 1 0  
t -3 3 -1  
 
cube2  
s 1 1 1  
r 0 0 1 0  
t -1.5 -1.5 -0.5  
s -2 -2 2  
r 0 0 1 0  
t 0 0 0  
 
cube  
s 1 1 1  
r 0 0 1 0  
t -3 -3 -1  
s -1 1 1  
r 0 0 1 0  
t 0 0 0

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 x and y resolutions). The input of your program should be read from standard input as so:

./wireframe_renderer [scene_description_file.txt] [xres] [yres]

xres and yres are integers that specify the x and y resolutions of the output image.

To help guide you, we have broken the task of writing this program into 6 parts:

1.
(10 Points) Parse the scene description file and put the data into appropriate C++ data structures. We recommend simply extending the code that you already wrote for Part 3 of Assignment 0.

2.
(10 Points) Create the transformation matrix for converting between world coordinates and camera coordinates; also create the perspective projection matrix.

3.
(25 Points) For each “object-copy” in the scene, transform each of its points by all the geometric transformations that are to be applied to the object-copy. From there, transform all the points into normalized device coordinates (NDC). Remember to scale by the homogeneous (w) component to convert the resultant, homogeneous NDC to Cartesian NDC!

4.
(20 Points) Devise an appropriate mapping from points in NDC to screen coordinates in a yres-by-xres pixel grid. Remember to discard any points that were mapped to the outside of the perspective cube when you were converting from camera coordinates to NDC. Ignore the z-coordinates of the points during your mapping. We will cover the use of the z-coordinate for rendering in the next assignment.

5.
(30 Points) Generalize Bresenham’s line algorithm to draw lines in all octants. In class and the lecture notes, we introduced Bresenham’s line algorithm for rasterizing lines with slopes between 0 and 1. You need to generalize this algorithm so that it can rasterize lines of all slopes. Please explain how you generalize and implement Bresenham’s line algorithm in your README or code comments. (Hint: the algorithm does not change much for the other slopes. You just need to do some clever “swapping”.)

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.

6.
(5 Points) Output the pixel grid to standard output as a .ppm image file.

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