CPSC 324, Spring 2001 Fourth Programming Assignment ----------------------------------------------------------------------- The final programming assignment for CS324 is to add support for indexed face sets to the GObject system. If you like, you can work with my "lit" GObjects. To do this, copy the directory /home/cs324/GObjects-lit into your home directory. (THIS DIRECTORY WILL BE AVAILABLE BY FRIDAY, APRIL 20). In the GObjects.cc file from this directory, at the very top, you'll find an unfinished method, GDisplayList::GDisplayList(const char *fileName). All you have to do is fill in this method so that it will read the data for an indexed face set, in the format described below, from the specified file and build a display list that draws the indexed face set. We will discuss what this means in class. Alternatively, you could use your own GObject files. Your program must be able to read the data for an indexed face set from a file. The file contains numbers, with no constraints about how they are organized into lines. (This means you can read them from a C++ ifstream without worrying about where the line breaks are.) The data in the file has the following form: A) An integer that gives the number of vertices for the indexed face set. B) An integer that gives the number of items in the data for the faces of the indexed face set. C) An integer that specifies how normal vectors are treated: 0 means that no normal vectors are included in the file; 1 means that there is one normal vector for each face; 2 means that there is one normal vector for each vertex. D) An integer that specifies how color is treated. You are not required to handle color! You can do so for extra credit. If you don't want to handle color, you can ignore this number (after reading it, of course). The meaning of the number is 0 means that there is no color data included in the file; 1 means that there is one color value for each face; 2 means that there is one color value for each vertex. E) The vertex data: 3*V floating point numbers, where V is the number of vertices specified above. These are the x, y, and z coordinates of each vertex. You can think of the vertices as being indexed: Vertex 0, vertex 1, vertex 2, ... vertex V-1. F) The face data: Each face is represented by a list of integers These integers give the indices of the vertices of the face. The list is followed by a -1 to mark the end of the list. (You have to count the -1's to find out how many faces there are.) G) The normal data, if any: 3*N floating point numbers, giving the x, y, and z components of the normal vectors. If the number from C), above, is 0, then N = 0. If the number from C) is 1, then N is equal to the number of faces. If the number from C) is 2, then N is equal to the number of vertices. H) The color data, if any: 3*N floating point numbers, giving the r, g, and b components of the colors. If the number from D), above, is 0, then N = 0. If the number from D) is 1, then N is equal to the number of faces. If the number from D) is 2, then N is equal to the number of vertices. You can ignore this data if you decide not to handle colors. I) There might some extra data at the end of the file, such as comments. This should be ignored by your program. You don't have to write a very robust program. You can assume that the data file is correct. You will have to read the data into arrays. The arrays can be local to the subroutine that creates the display list, since once the display list has been created, the data in the arrays is no longer needed. There are two sample data files, beveledCube.dat and bentTube.dat. The first example is a cube with its edges shaved off. The other sample file, bentTube.dat, is a 1/4 section of a torus. Note that beveledCube.dat uses normal-per-face while bentTube.dat uses normal-per-vertex. As for color, beveledCube.dat uses color-per-side, while bentTube has no color data. There are two sample programs that can be used with indexed face sets. The first, viewIFS, just lets you look at the indexed face set and rotate it using the arrow keys. It takes the name of the data file for the indexed face set as a parameter. So, you can say viewIFS beveledCube.dat and viewIFS bentTube.dat to see the two examples. The second sample program, pipes, is similar to the famous pipes screensaver. It uses the bentTube for bends in the pipes. You can test your own work by compiling it against the main programs viewIFS.cc and pipes.cc. My code for this assignment is less than 100 lines long. The assignment is due on Tuesday, May 1. Please turn in a printout of just the code that you write. Write the location of your code on the printout so that I can test it.