X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=002fadc3a7e22505b7a3aa50a9602b6c27109002;hb=19fa399bf0c4b47f6f23a320627533f0c902bca8;hp=9f29cc0ae90cd84bbef9df835fe840f6dda0ed5e;hpb=59ed896916f5a6e79b004534dcc5b988acd7dcf6;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index 9f29cc0..002fadc 100644 --- a/scene.c +++ b/scene.c @@ -52,6 +52,55 @@ typedef struct { float x,y,z; } SceneObject; +// Menu enum +enum menu { + // Main menu + ROTATE_MOVE_CAMERA, + POSITION_SCALE, + ROTATION_TEXTURE_SCALE, + EXIT, + + // Material submenu + MATERIAL_ALL_RGB, + MATERIAL_AMBIENT_RGB, + MATERIAL_DIFFUSE_RGB, + MATERIAL_SPECULAR_RGB, + MATERIAL_ALL_ADSS, + MATERIAL_RED_ADSS, + MATERIAL_GREEN_ADSS, + MATERIAL_BLUE_ADSS, + + // Light submenu + LIGHT_MOVE_LIGHT_1, + LIGHT_RGBALL_LIGHT_1, + LIGHT_MOVE_LIGHT_2, + LIGHT_RGBALL_LIGHT_2 +}; + +// Menu arrays +const char *textureMenuEntries[NTEXTURE] = { + "1 Plain", "2 Rust", "3 Concrete", "4 Carpet", "5 Beach Sand", + "6 Rocky", "7 Brick", "8 Water", "9 Paper", "10 Marble", + "11 Wood", "12 Scales", "13 Fur", "14 Denim", "15 Hessian", + "16 Orange Peel", "17 Ice Crystals", "18 Grass", "19 Corrugated Iron", "20 Styrofoam", + "21 Bubble Wrap", "22 Leather", "23 Camouflage", "24 Asphalt", "25 Scratched Ice", + "26 Rattan", "27 Snow", "28 Dry Mud", "29 Old Concrete", "30 Leopard Skin" +}; + +const char *objectMenuEntries[NMESH] = { + "1 Thin Dinosaur","2 Big Dog","3 Saddle Dinosaur", "4 Dragon", "5 Cleopatra", + "6 Bone I", "7 Bone II", "8 Rabbit", "9 Long Dragon", "10 Buddha", + "11 Sitting Rabbit", "12 Frog", "13 Cow", "14 Monster", "15 Sea Horse", + "16 Head", "17 Pelican", "18 Horse", "19 Kneeling Angel", "20 Porsche I", + "21 Truck", "22 Statue of Liberty", "23 Sitting Angel", "24 Metal Part", "25 Car", + "26 Apatosaurus", "27 Airliner", "28 Motorbike", "29 Dolphin", "30 Spaceman", + "31 Winnie the Pooh", "32 Shark", "33 Crocodile", "34 Toddler", "35 Fat Dinosaur", + "36 Chihuahua", "37 Sabre-toothed Tiger", "38 Lioness", "39 Fish", "40 Horse (head down)", + "41 Horse (head up)", "42 Skull", "43 Fighter Jet I", "44 Toad", "45 Convertible", + "46 Porsche II", "47 Hare", "48 Vintage Car", "49 Fighter Jet II", "50 Winged Monkey", + "51 Chef", "52 Parasaurolophus", "53 Rooster", "54 T-rex" +}; + #define MAXOBJECTS 256 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. @@ -167,61 +216,22 @@ void getTexture(int i) { // getTexture(i) loads texture i if it isn't already lo glBindTexture(GL_TEXTURE_2D, 0); // Back to default texture } -// Menu enum -enum menu { - // Main menu - ROTATE_MOVE_CAMERA, - POSITION_SCALE, - ROTATION_TEXTURE_SCALE, - EXIT, - - // Material submenu - MATERIAL_ALL_RGB, - MATERIAL_AMBIENT_RGB, - MATERIAL_DIFFUSE_RGB, - MATERIAL_SPECULAR_RGB, - MATERIAL_ALL_ADSS, - MATERIAL_RED_ADSS, - MATERIAL_GREEN_ADSS, - MATERIAL_BLUE_ADSS, - - // Light submenu - LIGHT_MOVE_LIGHT_1, - LIGHT_RGBALL_LIGHT_1, - LIGHT_MOVE_LIGHT_2, - LIGHT_RGBALL_LIGHT_2 -}; - -// Menu arrays -const char *textureMenuEntries[NTEXTURE] = { - "1 Plain", "2 Rust", "3 Concrete", "4 Carpet", "5 Beach Sand", - "6 Rocky", "7 Brick", "8 Water", "9 Paper", "10 Marble", - "11 Wood", "12 Scales", "13 Fur", "14 Denim", "15 Hessian", - "16 Orange Peel", "17 Ice Crystals", "18 Grass", "19 Corrugated Iron", "20 Styrofoam", - "21 Bubble Wrap", "22 Leather", "23 Camouflage", "24 Asphalt", "25 Scratched Ice", - "26 Rattan", "27 Snow", "28 Dry Mud", "29 Old Concrete", "30 Leopard Skin" -}; - -const char *objectMenuEntries[NMESH] = { - "1 Thin Dinosaur","2 Big Dog","3 Saddle Dinosaur", "4 Dragon", "5 Cleopatra", - "6 Bone I", "7 Bone II", "8 Rabbit", "9 Long Dragon", "10 Buddha", - "11 Sitting Rabbit", "12 Frog", "13 Cow", "14 Monster", "15 Sea Horse", - "16 Head", "17 Pelican", "18 Horse", "19 Kneeling Angel", "20 Porsche I", - "21 Truck", "22 Statue of Liberty", "23 Sitting Angel", "24 Metal Part", "25 Car", - "26 Apatosaurus", "27 Airliner", "28 Motorbike", "29 Dolphin", "30 Spaceman", - "31 Winnie the Pooh", "32 Shark", "33 Crocodile", "34 Toddler", "35 Fat Dinosaur", - "36 Chihuahua", "37 Sabre-toothed Tiger", "38 Lioness", "39 Fish", "40 Horse (head down)", - "41 Horse (head up)", "42 Skull", "43 Fighter Jet I", "44 Toad", "45 Convertible", - "46 Porsche II", "47 Hare", "48 Vintage Car", "49 Fighter Jet II", "50 Winged Monkey", - "51 Chef", "52 Parasaurolophus", "53 Rooster", "54 T-rex" -}; +void processMainEvents(int id) { + switch (id) { + case ROTATE_MOVE_CAMERA: + // Do stuff + break; + case POSITION_SCALE: + // Do stuff + break; + case ROTATION_TEXTURE_SCALE: + // Do stuff + break; -void processMainEvents(int id) { - switch (id) { case EXIT: - exit(0); + exit(EXIT_SUCCESS); } } @@ -231,7 +241,40 @@ void processObjectEvents(int id) { } void processMaterialEvents(int id) { + switch (id) { + case MATERIAL_ALL_RGB: + // Do stuff + break; + + case MATERIAL_AMBIENT_RGB: + // Do stuff + break; + + case MATERIAL_DIFFUSE_RGB: + // Do stuff + break; + + case MATERIAL_SPECULAR_RGB: + // Do stuff + break; + + case MATERIAL_ALL_ADSS: + // Do stuff + break; + case MATERIAL_RED_ADSS: + // Do stuff + break; + + case MATERIAL_GREEN_ADSS: + // Do stuff + break; + + case MATERIAL_BLUE_ADSS: + // Do stuff + break; + + } } void processTextureEvents(int id) { @@ -243,10 +286,80 @@ void processGTextureEvents(int id) { } void processLightEvents(int id) { + switch (id) { + case LIGHT_MOVE_LIGHT_1: + // Do stuff + break; + + case LIGHT_RGBALL_LIGHT_1: + // Do stuff + break; + + case LIGHT_MOVE_LIGHT_2: + // Do stuff + break; + + case LIGHT_RGBALL_LIGHT_2: + // Do stuff + break; + } +} + +/** + * Rounds up numbers, from http://stackoverflow.com/questions/3407012/c-rounding-up-to-the-nearest-multiple-of-a-number + * @param numToRound Number to round + * @param multiple Multiple to round up to + * @return Rounded number + */ +int roundUp(int numToRound, int multiple) { + if(multiple == 0) { + return numToRound; + } + + int remainder = numToRound % multiple; + if (remainder == 0) + return numToRound; + return numToRound + multiple - remainder; } +/** + * Makes a submenu from an array of items, splitting the list into subsubmenus + * of only 10 items. + * @param menuEntries Array of menu items + * @param menuEntriesSize Size of menuEntries + * @param callback Callback function for this array of menu items + * @return Reference to menu created + */ +int makeSubmenuFromArray( const char *menuEntries[], unsigned int menuEntriesSize, void *callback ) { + if ( menuEntriesSize == 0 ) return -1; + int menuNumber = roundUp(menuEntriesSize, 10) / 10; + int submenuObjects[menuNumber-1]; + + for( int i = 0; i < menuNumber; i++ ) { + submenuObjects[i] = glutCreateMenu(callback); + int startNum = i*11 - (i-1); + for ( int j = startNum - 1; j < (startNum+9); j++ ) { + if ( j == menuEntriesSize ) break; // Detect if we've reached the end of the array + glutAddMenuEntry( menuEntries[j], j + 1 ); + } + } + + int mainMenu = glutCreateMenu(callback); + for ( int i = 0; i < menuNumber; i++ ) { + char name[10]; // buffer to hold name + int startNum = i*11 - (i-1); + int endNum = startNum + 9; + if ( i == menuNumber - 1 ) { // We're on the last one + endNum = startNum + (menuEntriesSize - startNum); // Work out final number + } + sprintf(name, "%d-%d", startNum, endNum); + glutAddSubMenu( name, submenuObjects[i] ); + } + + return mainMenu; +} void makeMenu() { // Construct material menu @@ -267,54 +380,28 @@ void makeMenu() { glutAddMenuEntry("Move Light 2", LIGHT_MOVE_LIGHT_2); glutAddMenuEntry("R/G/B/All Light 2", LIGHT_RGBALL_LIGHT_2); - // Construct add object submenus + // Construct object menu int objectMenuEntriesSize = sizeof(objectMenuEntries) / sizeof(objectMenuEntries[0]); - int menuNumber = objectMenuEntriesSize / 10 + 1; - int addObjectSubmenu[menuNumber-1]; - - for( int i = 0; i < menuNumber; i++ ) { - addObjectSubmenu[i] = glutCreateMenu(processObjectEvents); - int startNum = i*11 - (i-1); - for ( int j = startNum - 1; j < (startNum+9); j++ ) { - if ( j == objectMenuEntriesSize ) break; // Detect if we've reached the end of the array - glutAddMenuEntry( objectMenuEntries[j], j ); - } - } - - // Construct add object menu - int addObjectMenu = glutCreateMenu(processObjectEvents); - for ( int i = 0; i < menuNumber; i++ ) { - char name[10]; // buffer to hold name - int startNum = i*11 - (i-1); - int endNum = startNum + 9; - if ( i == menuNumber - 1 ) { // We're on the last one - endNum = startNum + 3; - } - sprintf(name, "%d-%d", startNum, endNum); - glutAddSubMenu( name, addObjectSubmenu[i] ); - } + int objectMenu = makeSubmenuFromArray( objectMenuEntries, objectMenuEntriesSize, processObjectEvents ); + // Construct texture / ground texture menus + int textureMenuEntriesSize = sizeof(textureMenuEntries) / sizeof(textureMenuEntries[0]); + int textureMenu = makeSubmenuFromArray( textureMenuEntries, textureMenuEntriesSize, processTextureEvents ); + int gTextureMenu = makeSubmenuFromArray( textureMenuEntries, textureMenuEntriesSize, processGTextureEvents ); + // Construct main menu int mainMenu = glutCreateMenu(processMainEvents); - glutAddMenuEntry("Rotate/Move Camera", ROTATE_MOVE_CAMERA); - glutAddSubMenu("Add object", addObjectMenu); + glutAddSubMenu("Add object", objectMenu); glutAddMenuEntry("Position/Scale", POSITION_SCALE); glutAddMenuEntry("Rotation/Texture Scale", ROTATION_TEXTURE_SCALE); - //material - - - - glutSetMenu(mainMenu); glutAddSubMenu("Material", materialMenu); - - //texture - //ground texture - //lights - - + glutAddSubMenu("Texture", textureMenu); + glutAddSubMenu("Ground texture", gTextureMenu); + glutAddSubMenu("Lights", lightMenu); glutAddMenuEntry("Exit", EXIT); + // Bind to right mouse button glutAttachMenu(GLUT_RIGHT_BUTTON); }