ECE 4680L/6680L : Write a C Program That Triangle Rendering - IT Assignment Help

Download Solution Order New Solution
Assignment Task:

Task:

In this lab you are to write a C program that renders triangles. The program should read a PLY object filename and 3 rotation angles (degrees) as command line arguments. It should then set a camera position using the 3 rotation angles and render a 256 x 256 pixel image saving it in PPM format.

At the course website are several PLY object files that can be used. The program may be written under linux using gcc or under Windows using Visual C++.
 

The specific rendering steps include:
1. Parse the PLY file header to determine the number of vertices and faces. All other header info is irrelevant for this lab.
2. Read the PLY file vertices and faces.
3. Calculate the bounding box on the vertices. This will include the following:
(a) Minimum and maximum X, Y and Z (two vectors denoted hmini and hmaxi).
(b) Center X, Y and Z (vector denoted hcenteri).
(c) Maximum extent of bounding box E = scalar that is largest component of hmax− mini, i.e. largest extent of the three axes.

4. Calculate the camera position and orientation using two vectors hcamerai and hupi as follows.
(a) By default assume hcamerai is h1, 0, 0i (positioned on the X axis) with hupi oriented as h0, 0, 1i (positive on the Z axis).
(b) Rotate both the camera vector and up vector by X degrees about the X-axis, Y degrees about the Y-axis, and Z degrees about the Z-axis, where X, Y and Z were supplied as command line arguments. Rotations are calculated using equations 2-3.

Rx(θ) = 1 0 0
0 cosθ −sinθ 0 sinθ cosθ
 

Ry(θ) =  cosθ 0 sinθ 0 1 0 −sinθ 0 cosθ
 

Rz(θ) = cosθ −sinθ 0
sinθ cosθ 0 0 0 1
 

(c) Move and scale the camera vector according to equation 4.

hcamerai = 1.5Ehcamerai + hcenteri (4)

 

5. Determine the 3D coordinates bounding the image using equations 5-12.

hlef ti = hupi × hcenter − camerai (5)
a = khlef tik (6)

hlef ti = E 2a
hlef ti + hcenteri (7)
hrighti = (hcenter − camerai × hupi (8)
hrighti = E 2a
hrighti + hcenteri (9)

htopi = E 2
hupi + hcenteri (10)

hbottomi = −E 2
hupi + hcenteri (11)

htoplef ti = E 2 hupi + hlef ti (12)

6. For each pixel r, c in the image:
(a) Default image color is black (greyscale=0).
(b) Default z-buffer depth is very far (for example, 999999). Note the z-buffer image must be floats or doubles. Recall it stores the distance to the closest triangle for each pixel so that only the color for that triangle is drawn.
(c) Calculate vector coordinates himagei for the image pixel using equation 13, where COLS and ROW S are the width and height of the image in pixels and it is assumed c and r index from 0 to COLS − 1 and ROW S − 1 respectively.

himagei = htoplef ti + c COLS − 1

hright − lef ti + r ROW S − 1 hbottom − topi (13)

(d) For each triangle having coordinates v0, v1 and v2:

i. Find the plane equation hA, B, C, Di that contains the triangle using equa- tions 14-15.

hA, B, Ci = hv1 − v0i × hv2 − v0i (14)
D = −hA, B, Ci · hv0i (15)
ii. Find the distance along the image pixel ray to the triangle, denoted n d , using equations 16-17. Test if ray is parallel to triangle (if d is near zero), and if so skip this triangle for this pixel.

n = −hA, B, Ci · hcamerai − D (16) d = hA, B, Ci · himage − camerai (17)

 

iii. Find the 3D coordinates hintersecti of ray and plane using equation 18.

hintersecti = hcamerai + n d himage − camerai (18)

iv. Determine if intersection point lies within triangle by calculating the three dot products in equations 19-21.
dot1 = hv2 − v0i × hv1 − v0i · hintersect − v0i × hv1 − v0i (19)
dot2 = hv0 − v1i × hv2 − v1i · hintersect − v1i × hv2 − v1i (20)
dot3 = hv1 − v2i × hv0 − v2i · hintersect − v2i × hv0 − v2i (21)
v. If any of the dot products is less than zero (if dot1 < 0 or dot2 < 0 or dot3 < 0), then the intersection point lies outside the triangle and it can be skipped.
vi. If the distance to the triangle n/d is greater than the current z-buffer value for this pixel, then the triangle lies behind a closer triangle and it can be skipped.
vii. Set pixel color to 155 + (i%100) where i is the index of the triangle. This provides some variation in colors making the object easier to see.

7. Write PPM image.
Test the program using several different rotations (e.g. 90, 45, −135) on several of the given PLY files. You may want to compile with optimization to speed up program execution. All students are to complete the lab individually.

 

This ECE 4680L/6680L IT Assignment has been solved by our IT Experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.

Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.