|
04/05/03: Progress Report #9Plan The goal of this iteration is to program the museum to read in a text file that contains all the available wall spaces in each room and the file names of each exhibit and then to place each exhibit in its proper room in the proper wing in an organized and somewhat aesthetic manner. This goal will be split up into two smaller tasks. The first of these tasks is to read in all of the available wall spaces in each room of each wing from a text file and create the organizational structure discussed in the previous progress report. The second task is to read in the file names of each exhibit picture, input them into an array of textures while assigning them a position in the correct room. As you can probably tell, this is going to be a very complicated iteration and may take a while. Design The first task of this iteration was to read in the text file created in the previous iteration and fill out the organizational structure initialized in the previous iteration. This occurs in a function called void exhibitInit(). The function consists of several nested for- and do-while-loops. The first for-loop inputs the four characters that are unique to each section and goes through the array of section structs and assigns a four-character array to each struct. Also for each section struct, the program moves down a level into a nested for-loop to fill in the names of each subsection into each subsection struct as well. The number of subsection structs in the array is set to an arbitrary 10. Finally, the program moves down to the third level to a do-while loop, inputting the four floating-point numbers that are the x- and z-coordinates of the two endpoints of each wall space and assigning them to a wall space struct. I ran into a little trouble because I forgot to initialize the struct pointer to NULL, but the bug was discovered and fixed. While the four floating-point numbers did not equal zero, the program stayed in the do-while-loop, adding wall space structs to the linked list. When the numbers equalled zero, the do-while-loop broke and continued on to the next subsection or section. The second task proved to be much more complicated than the first. First, a text file of all the file names of the exhibit textures had to be created for the program to read in. Then, several arrays had to be created. The first array was an array of GLuints to contain the texture information of each exhibit. The second array was an array of arrays--a matrix--that contained the position of the exhibits as well as whether they were along the x-axis or the z-axis (0 if the exhibit was along the x-axis, 1 if the exhibit was along the z-axis). The elements of the first array corresponded with the elements of the second array; for example, element [0] of the texture array was the picture that went on the position detailed by element [0] of the position array. The function that initializes and inputs values into these arrays is named void placeExhibits(). The first value in the text file of exhibits is the number of exhibits contained in the file. The program inputs this number and initializes the arrays to have this number of elements. (The pointers to the arrays are global variables, but the arrays themselves are not initialized until this program.) Then, there are two for-loops in a row whose purposes are to match the exhibit to its correct section and subsection. The final part of the program takes the first element of the linked list out of the linked list, connecting the pointer of the subsection struct to the second element of the linked list. The program then splits the wall space of the first element into two equal halves, leaving out 3 units for the exhibit. The position of the exhibit is placed into the proper elements of the position array (named exhibits) with the first element being the x-coordinate, the second element being the y-coordinate, and the third element being 0 if the exhibit is along the x-axis and 1 if the exhibit is along the z-axis. After assigning the exhibit a position, the function creates two new wall space structs with wall spaces on either side of the new exhibit and goes down through the linked list until it reaches where the two new wall space structs should go, inserts them in and re-connects the linked list. I had a little bug at this point in the program because I forgot to account for if the struct was supposed to go at the end of the linked list, but the problem is fixed now. After this is accomplished, the program reads in the next exhibit file name and repeats the process until there are no more exhibits. After the previous two functions, this one was a snap: its purpose is to display the exhibits in the museum, so it's called (surprisingly enough) void drawExhibits(). Basically, it goes through the exhibit position array and draws the textures on the walls. I did come across a slight problem in this function--the program didn't really know which side of the wall on which to draw the exhibit picture frame. I solved this problem by having the program draw the exhibit on both sides of the wall. Coding Download the code for this iteration: report09-museum.cpp This iteration of the code requires textures and text files to run. These files can be found here. Testing Okay, well, after waiting almost a month, here is the animated gif you've been waiting for. I know it's a little jerky, but look at how beautifully the exhibits are spaced!
|