[SOLVED] EE4730 Homework 1: Read and Draw a 3D Surface Mesh

35.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Programming-1-lr50id.zip (4.4 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
πŸ”’ Securely Powered by:
Secure Checkout
5/5 - (1 vote)

Β 

Write an OpenGL program to read and display a 3D mesh (in .obj format).

  1. Write a function, β€œbool ReadOBJFile(const char filename[])”, to read in an obj file and store the elements into a vertex list and face list.
  2. Implement a β€œComputeBoundingBox()” function, to compute the bounding box of the object, its diagonal axis length, and its center, then put the camera at:

x_cam = x_BCenter;Β  y_cam = y_BCenter;

z_cam = z_BCenter + 1.5 *BDiagonalAxisLength;

and look towards the bounding box center (x_BCenter, y_BCenter, z_BCenter).

Some more explanation about this computation is given in the next page.

  1. Implement the β€œRender_Mesh()” function to finish the OpenGL rendering. (See next page).
  2. Follow β€œEx8.cpp” to perform keyboard + mouse-controlled rotation (R, mouse left button), panning (T, mouse left button), and zooming (Z, mouse left button) functions.

Note 1: Please write all you codes in one β€œhw1.cpp” file. Test and make sure it compiles and renders correctly, then upload your β€œhw1.cpp” file only. I will compile and run it on my computer to see your result.

Note 2: You only need to consider the simplest OBJ format in this homework.

It contains a list of vertices (each row starts with a keyword β€œv”, e.g., v x y z), and a list of faces (each row starts with a keyword β€œf”, e.g., f vInd1 vInd2 vInd3). Note that the vertex index vInd starts at 1. So if you have store vertex positions in an array, the first vertex is at position 0, and each vertex’s location is vInd-1.

The homework is due: 11:59pm, Feb. 10th. If you are late for x days, each one more day you get 5% off. Namely, your homework score will be calculated as: (the score based on your codes) * (0.95^x) Computing Bounding Box (BB) of a 3D object

A bounding box (BB) of an object is defined as a minimal coordinate-axis-aligned box that completely contains this object.

BB can be simply defined by the minimal and maximal x, y, and z coordinate

values of the objects’ vertices:Β  𝐡𝐡 = [π‘₯π‘šπ‘–π‘›, π‘₯π‘šπ‘Žπ‘₯] Γ— [π‘¦π‘šπ‘–π‘›, π‘¦π‘šπ‘Žπ‘₯] Γ— [π‘§π‘šπ‘–π‘›, π‘§π‘šπ‘Žπ‘₯]

The center of a BB can be simply defined as the

The diagonal axis length of a BB roughly measures the size of the object:

𝑙 = √(π‘₯π‘šπ‘Žπ‘₯ βˆ’ π‘₯π‘šπ‘–π‘›)2 + (π‘¦π‘šπ‘Žπ‘₯ βˆ’ π‘¦π‘šπ‘–π‘›)2 + (π‘§π‘šπ‘Žπ‘₯ βˆ’ π‘§π‘šπ‘–π‘›)2

Rendering a Triangle Mesh

Each triangle mesh contains a list of faces. Each face 𝑓 has three points (𝑝𝑖, 𝑝𝑗, π‘π‘˜) where each point 𝑝𝑖 has three coordinates (π‘₯𝑖, 𝑦𝑖, 𝑧𝑖) .

Therefore, you can implement Render_Mesh() based on the following pseudo-code:

glBegin(GL_TRIANGLES);

//Let F denote the total number of faces

for (int ind=0; ind< F; ++ind) {Β  Β Β Β Β Β  let 𝑓 be the 𝑖𝑛𝑑-th face;

get 𝑓’s three points 𝑝𝑖, 𝑝𝑗, π‘π‘˜ using their vertex indices;Β  get 𝑝𝑖’s coordinates (π‘₯𝑖, 𝑦𝑖, 𝑧𝑖); same for 𝑝𝑗 and π‘π‘˜

glVertex3f(π‘₯𝑖, 𝑦𝑖, 𝑧𝑖);Β Β  glVertex3f(π‘₯𝑗, 𝑦𝑗, 𝑧𝑗); glVertex3f(π‘₯π‘˜, π‘¦π‘˜, π‘§π‘˜);

}

glEnd();

  • Programming-1-lr50id.zip