Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

COMP4610/8610

Computer Graphics

Homework Assignment #2,  S2 2023

Topic: Drawing triangles and Z-buffer

Weighting:  10%

Instruction:

All homework assignments must be completed individually.  We encourage you to discuss the assignments with other students. However, you should not share any of your codes with anyone else.  Each student is responsible for implementing the assignment on their own.  You may assist other in debugging their codes, but you should not copy and paste.  ANU is using TurnItIn to detect possible duplications.  Consulting with previous year students who enrolled in this course on specific assignment is also not allowed.    You  may  use the  internet  as a resource for  learning the  materials,  but you should  not  borrow any existing codes found online.

The homework assignments involve a significant amount of C++ programming.  However, for most cases, a skeletal code base is provided, and you only need to fill in the missing parts, and/or fix bugs if any.

You will submit a single ZIP file as your submission,  which must contain the following files:

(1) All source codes (ending in .h, or .hpp, or .cpp), and your Makefile, CMakeLists.txt. Please  include  all  needed  source  codes  for  successful  compilation.        Please  also remove all intermediate files (such as ./vs. . /build.   )   that are  not needed for the compilation –  Failing to do so will lead to penalty to the marks.

(2) A written HW2 Report  (minimum 10-point font size, single column,  in PDF format, with task statement, methods used, any new features that you have implemented, any known bugs in your code,  answer any questions that have been asked in the task, instruction for the tutor to use your code,  example experiment results. )


Your ZIP file must be named as “COMPX610_2023_HW2_UID.zip” .    Replace ‘X’ with 4 or 8. Replace the UID with your Uxxxxxxxx;      Please  submit  your ZIP file to Wattle  before the deadline. Late submission will lead to penalty as per the ANU policy.     Later-than-one-week submission will not be accepted, which may result zero mark, unless a pre-approval for special consideration is obtained in written before the submission deadline.

Task for Hw2:

In the previous assignment (HW1),  you have drawn a wireframe triangle on screen.     In this assignment, we will paint the interiors of triangles with solid colour.   In other words, we are going to rasterize triangles.

Specifically,  you  will  write   a  function   rasterize_triangle(const  Triangle  &t)     to   replace rasterize_wireframe (const Triangle &t) .   In addition,   this function must works as follows:

.    Manually create two triangles.

.    Compute a 2D bounding box for each triangle on the screen.

.    Traverse all interior pixels inside the bounding box (using integer index).   Then, use the center point of each pixel to test whether this center point is inside the triangle or not.

.    If  it   is  inside  the  triangle,  apply  depth  value   interpolation  using  its   barycentric coordinates, and compare its depth with the corresponding value in the depth-buffer.

.    Use Z-buffer algorithm to refresh the Z value in the depth-buffer.

.    [Advanced   feature]   Arbitrarily   select   one   triangle,   if   you   press   A   or   D,   the corresponding  triangle  will   rotate  accordingly,  and  all  the  two  triangles  will   be displayed correctly.

Note:  When you read the provided skeleton code, you may find that we have provided some code for performing depth value interpolation.   Please check if the code works properly.  If it does, please explain how it does it;   If not, please fix it.    In short, your final submission must be running well without major bugs.

The following two functions are largely empty, and you need to complete them:

rasterize_triangle(),   and

static bool insideTriangle().

Note also that,  contrary to the standard convention where camera is pointing to the minus Z direction,     here we assume that all depth values are greater than zero, and the larger Z is the farther away the point is.

Inside the main.cpp, you may notice that the get_projection_matrix()   function   has  been implemented already.

How to compile and run your codes ?

Library dependencies:   Eigen, and OpenCV ;

Please use the following commands in order, to compile and test your code. (1)  mkdir build

(2) cd build

(3) cmake ..

(4)  make -j4

(5)  ./Rasterizer.