Lab 14

Write a program that draws polygon mesh models. Start with your program to draw wireframe models and these changes:

Global Variables

In the worldType declaration, change the title on the graphics window from "Wireframe Model" to "Mesh Model".

The main Function

In main, change the first output from "Wireframe Model Viewer" to "Polygon Mesh Model Viewer".

Command Line Interpreter (the execute Function)

The file extension for polygon mesh models is "MSH". Change the code that executes the "list" command from:

 system("dir *.wf /b");


 system("dir *.msh /b");

Model Data Structure

Replace the "edgeType" structure with a "faceType" structure. A faceType structure should store the vertex indices for a given face. This is complicated by the fact that the number of vertex indices is not fixed. Consequently, the faceType data structure should also store the number of vertex indices. You may assume that no face has more than 5 vertices (which also means it has no more than 5 edges).

Replace the "wireframe" structure with a "wiremesh" structure. Instead of an array of edgeType structures, a wiremesh structure will include an array of faceType structures. You may assume that no model will have more than 3,000 faces.

The maximum number of vertices is unchanged. No model will have more than 1,500 vertices.

Polygon Mesh Data Files

Log on to the Asbury University network and navigate to my public classes folder (Q:\SEARLS). Copy any or all of the files in the "PolygonMeshData" folder to the folder that contains your polygon mesh viewer project.

The first line in a polygon mesh data file contains the number of vertices. This is followed by the list of vertex coordinates where each vertex is stored as a list of three space-delimited floating-point numbers. Following the vertices is the number of faces in the model. This is followed by a list of faces where each face is stored as a space-delimited list of 3 to 5 integer values. Each of these integer values represents the position of the corresponding vertex in the vertex list. Here is the data file for a cube centered at the origin (where the text is not part of the file):

8             Number of vertices
1 1 1         Vertex 1
-1 1 1        Vertex 2
-1 -1 1
1 -1 1
1 1 -1
-1 1 -1
-1 -1 -1
1 -1 -1       Vertex 8
6             Number of faces
5 8 7 6       Face 1
1 2 3 4       Face 2
4 3 7 8
5 6 2 1
1 4 8 5
6 7 3 2       Face 6

Face one has four vertices as follows:

  1. Vertex 5 in the list of vertices: (1, 1, -1)
  2. Vertex 8 in the list of vertices: (1, -1, -1)
  3. Vertex 7 in the list of vertices: (-1, -1, -1)
  4. Vertex 6 in the list of vertices: (-1, 1, -1)

The readModel Function

You'll need to modify your readModel function to read the polygon mesh model data into a wiremesh data structure. The number of vertices is determined by the number of vertex indices listed in the corresponding line of text in the data file. You might consider reading each line of indices into a string and using a stringstream object to read the indices from the string.

The viewModel Function

You'll need to modify your viewModel function to traverse the face list. For each face, you will need to draw a line from each vertex to the next and from the last vertex back to the first.

File Submission

Submit your Lab14.cpp file and your project file as attachments to an email message.