-#define MAXOBJECTS 256\r
-SceneObject sceneObjs[MAXOBJECTS]; // An array with details of the objects in a scene\r
-int nObjects=0; // How many objects there are in the scene currently.\r
-\r
-// Directories containing models\r
-char *dirDefault1 = "models-textures";\r
-char *dirDefault2 = "/cslinux/examples/CITS2231/project-files/models-textures";\r
-\r
-char dataDir[200]; // Stores the directory name for the meshes and textures.\r
-\r
-/**\r
- * Prints out error message when file cannot be read\r
- * @param fileName Name of file that could not be read\r
- */\r
-void fileErr(char* fileName) {\r
- printf("Error reading file: %s\n", fileName);\r
- printf("If not in the CSSE labs, you will need to include the directory containing\n");\r
- printf("the models on the command line, or put it in the same folder as the exectutable.");\r
- exit(EXIT_FAILURE);\r
-} \r
-\r
-/**\r
- * Reads .bmp texture files and converts them to a texture object\r
- * @param fileName .bmp texture file\r
- * @return texture object\r
- */\r
-texture* loadTexture(char *fileName) {\r
- texture* t = malloc(sizeof (texture));\r
- BITMAPINFO *info;\r
-\r
- t->rgbData = LoadDIBitmap(fileName, &info);\r
- t->height=info->bmiHeader.biHeight;\r
- t->width=info->bmiHeader.biWidth;\r
-\r
- return t;\r
-}\r
-\r
-/**\r
- * Reads .x files and converts them to a mesh object\r
- * @param fileName .x mesh file\r
- * @return mesh object\r
- */\r
-mesh* loadMesh(char* fileName) {\r
- mesh* m = malloc(sizeof (mesh));\r
- FILE* fp = fopen(fileName, "r");\r
- char line[256] = "";\r
- int lineBuffSize = 256;\r
-\r
- if(fp == NULL) fileErr(fileName);\r
-\r
- while(strcmp(line,"Mesh {\r\n") != 0 && strcmp(line,"Mesh {\n") != 0 )\r
- fgets(line, lineBuffSize, fp);\r
-\r
- fscanf(fp, "%d;\n", &(m->nVertices));\r
- m->vertices = malloc(m->nVertices * sizeof(vertex));\r
- for(int i=0; i < m->nVertices; i++)\r
- fscanf(fp, "%f; %f; %f;%*[,;]\n", &(m->vertices[i][0]), &(m->vertices[i][1]), &(m->vertices[i][2]) );\r
-\r
- fscanf(fp, "%d;\n", &(m->nTriangles));\r
- m->triangles = malloc(m->nTriangles * sizeof(triangle));\r
- for(int i=0; i < m->nTriangles; i++)\r
- fscanf(fp, "%*d; %d, %d, %d;%*[;,]", m->triangles[i], m->triangles[i]+1, m->triangles[i]+2);\r
-\r
- while(strcmp(line," MeshNormals {\r\n") != 0 && strcmp(line," MeshNormals {\n") != 0)\r
- fgets(line, lineBuffSize, fp);\r
-\r
- fgets(line, lineBuffSize, fp);\r
- m->normals = malloc(m->nVertices * sizeof(normal));\r
- for(int i=0; i < m->nVertices; i++)\r
- fscanf(fp, "%f; %f; %f;%*[;,]\n",\r
- &(m->normals[i][0]), &(m->normals[i][1]), &(m->normals[i][2]));\r
-\r
- while(strcmp(line,"MeshTextureCoords {\r\n") != 0 && strcmp(line,"MeshTextureCoords {\n") != 0)\r
- fgets(line, lineBuffSize, fp);\r
-\r
- fgets(line, lineBuffSize, fp);\r
- m->texCoords = malloc(m->nVertices * sizeof(texCoord));\r
- for(int i=0; i < m->nVertices; i++)\r
- fscanf(fp, "%f;%f;%*[,;]\n", &(m->texCoords[i][0]), &(m->texCoords[i][1]) );\r
- fclose(fp);\r
- \r
- return m;\r
-}\r
-\r
-// [You may want to add to this function.]\r
-/**\r
- * Loads mesh[i] if it isn't already loaded.\r
- * You must call getMesh(i) at least once before using mesh[i].\r
- *\r
- * @param i Mesh ID\r
- */\r
-void getMesh(int i) { // getMesh(i) loads mesh[i] if it isn't already loaded. \r
- char fileName[220];\r
- if(i>=NMESH || i<0) {\r
- printf("Error in getMesh - wrong model number");\r
- exit(1);\r
- }\r
- if(meshes[i] != NULL)\r
- return;\r
- sprintf(fileName, "%s/model%d.x", dataDir, i+1);\r
- meshes[i] = loadMesh(fileName);\r
-}\r