From 1974078227af3b4da18ff6813f9cf5ed231d9205 Mon Sep 17 00:00:00 2001 From: Ash Tyndall Date: Sun, 9 Oct 2011 13:36:23 +0800 Subject: [PATCH] --- scene.c | 134 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 98 insertions(+), 36 deletions(-) diff --git a/scene.c b/scene.c index f9ab89f..c546975 100644 --- a/scene.c +++ b/scene.c @@ -105,13 +105,28 @@ const char *objectMenuEntries[NMESH] = { SceneObject sceneObjs[MAXOBJECTS]; // An array with details of the objects in a scene int nObjects=0; // How many objects there are in the scene currently. +// Directories containing models +char *dirDefault1 = "models-textures"; +char *dirDefault2 = "/cslinux/examples/CITS2231/project-files/models-textures"; + +char dataDir[200]; // Stores the directory name for the meshes and textures. + +/** + * Prints out error message when file cannot be read + * @param fileName Name of file that could not be read + */ void fileErr(char* fileName) { printf("Error reading file: %s\n", fileName); printf("If not in the CSSE labs, you will need to include the directory containing\n"); printf("the models on the command line, or put it in the same folder as the exectutable."); - exit(1); + exit(EXIT_FAILURE); } +/** + * Reads .bmp texture files and converts them to a texture object + * @param fileName .bmp texture file + * @return texture object + */ texture* loadTexture(char *fileName) { texture* t = malloc(sizeof (texture)); BITMAPINFO *info; @@ -123,8 +138,11 @@ texture* loadTexture(char *fileName) { return t; } -// The following works for the supplied .x files -// but probably not for .x files from other sources. +/** + * Reads .x files and converts them to a mesh object + * @param fileName .x mesh file + * @return mesh object + */ mesh* loadMesh(char* fileName) { mesh* m = malloc(sizeof (mesh)); FILE* fp = fopen(fileName, "r"); @@ -167,11 +185,13 @@ mesh* loadMesh(char* fileName) { return m; } -char dataDir[200]; // Stores the directory name for the meshes and textures. - -// getMesh(i) loads mesh[i] if it isn't already loaded. -// You must call getMesh(i) at least once before using mesh[i]. // [You may want to add to this function.] +/** + * Loads mesh[i] if it isn't already loaded. + * You must call getMesh(i) at least once before using mesh[i]. + * + * @param i Mesh ID + */ void getMesh(int i) { // getMesh(i) loads mesh[i] if it isn't already loaded. char fileName[220]; if(i>=NMESH || i<0) { @@ -184,13 +204,21 @@ void getMesh(int i) { // getMesh(i) loads mesh[i] if it isn't already loaded. meshes[i] = loadMesh(fileName); } -// getTexture(i) loads texture i if it isn't already loaded. -// After calling getTexture(i), you can make texture i the current texture using -// glBindTexture(GL_TEXTURE_2D, i); (Use i=0 to return to the default plain texture.) -// You can then scale the texture via: (See the textbook, section 8.8.3.) -// glMatrixMode(GL_TEXTURE); -// You must call getTexture(i) at least once before using texture i. -void getTexture(int i) { // getTexture(i) loads texture i if it isn't already loaded. +/** + * Loads texture i if it isn't already loaded + * + * After calling getTexture(i), you can make texture i the current texture using + * glBindTexture(GL_TEXTURE_2D, i); + * Use i=0 to return to the default plain texture. + * + * You can then scale the texture via: + * glMatrixMode(GL_TEXTURE); + * See the textbook, section 8.8.3. + * + * You must call getTexture(i) at least once before using texture i. + * @param i Texture ID + */ +void getTexture(int i) { char fileName[220]; if(i<1 || i>NTEXTURE) { printf("Error in getTexture - wrong texture number"); @@ -216,6 +244,10 @@ void getTexture(int i) { // getTexture(i) loads texture i if it isn't already lo glBindTexture(GL_TEXTURE_2D, 0); // Back to default texture } +/** + * Event hander for main menu events + * @param id ID of menu item selected + */ void processMainEvents(int id) { switch (id) { case ROTATE_MOVE_CAMERA: @@ -236,10 +268,10 @@ void processMainEvents(int id) { } } -void processObjectEvents(int id) { - -} - +/** + * Event hander for materials menu events + * @param id ID of menu item selected + */ void processMaterialEvents(int id) { switch (id) { case MATERIAL_ALL_RGB: @@ -277,14 +309,10 @@ void processMaterialEvents(int id) { } } -void processTextureEvents(int id) { - -} - -void processGTextureEvents(int id) { - -} - +/** + * Event hander for light menu events + * @param id ID of menu item selected + */ void processLightEvents(int id) { switch (id) { case LIGHT_MOVE_LIGHT_1: @@ -306,6 +334,30 @@ void processLightEvents(int id) { } } +/** + * Event hander for object menu events + * @param id ID of object selected + */ +void processObjectEvents(int id) { + +} + +/** + * Event hander for texture menu events + * @param id ID of texutre selected + */ +void processTextureEvents(int id) { + +} + +/** + * Event hander for ground texture menu events + * @param id ID of ground texture selected + */ +void processGTextureEvents(int id) { + +} + /** * Rounds up numbers, from http://stackoverflow.com/questions/3407012/c-rounding-up-to-the-nearest-multiple-of-a-number * @param numToRound Number to round @@ -361,6 +413,9 @@ int makeSubmenuFromArray( const char *menuEntries[], unsigned int menuEntriesSiz return mainMenu; } +/** + * Creates menu for program + */ void makeMenu() { // Construct material menu int materialMenu = glutCreateMenu(processMaterialEvents); @@ -391,28 +446,35 @@ void makeMenu() { // Construct main menu glutCreateMenu(processMainEvents); - glutAddMenuEntry("Rotate/Move Camera", ROTATE_MOVE_CAMERA); - glutAddSubMenu("Add object", objectMenu); - glutAddMenuEntry("Position/Scale", POSITION_SCALE); - glutAddMenuEntry("Rotation/Texture Scale", ROTATION_TEXTURE_SCALE); - glutAddSubMenu("Material", materialMenu); - glutAddSubMenu("Texture", textureMenu); - glutAddSubMenu("Ground texture", gTextureMenu); - glutAddSubMenu("Lights", lightMenu); + //glutAddMenuEntry("Rotate/Move Camera", ROTATE_MOVE_CAMERA); + //glutAddSubMenu("Add object", objectMenu); + //glutAddMenuEntry("Position/Scale", POSITION_SCALE); + //glutAddMenuEntry("Rotation/Texture Scale", ROTATION_TEXTURE_SCALE); + //glutAddSubMenu("Material", materialMenu); + //glutAddSubMenu("Texture", textureMenu); + //glutAddSubMenu("Ground texture", gTextureMenu); + //glutAddSubMenu("Lights", lightMenu); glutAddMenuEntry("Exit", EXIT); // Bind to right mouse button glutAttachMenu(GLUT_RIGHT_BUTTON); } +/** + * Display function + */ void display() { // You probably want to change both of the following. glClear(GL_COLOR_BUFFER_BIT); glFlush(); } -char *dirDefault1 = "models-textures"; -char *dirDefault2 = "/cslinux/examples/CITS2231/project-files/models-textures"; +/** + * Main function + * @param argc Number of arguments + * @param argv Array of arguments + * @return Program exit code + */ int main(int argc, char **argv) { if(argc>1) -- 2.20.1