X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=c9820a20543e304884e45bcfd13857a2a3ccf3b0;hb=1b0087ae8ca179df3a55922c92670c80a891b3b9;hp=a1b52b356853fc9d60dcd74023e866e6e999029c;hpb=3f5c658ec863c5e3f6e3cdceff0017fa6092d38c;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index a1b52b3..c9820a2 100644 --- a/scene.c +++ b/scene.c @@ -167,6 +167,31 @@ 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", @@ -191,13 +216,14 @@ const char *objectMenuEntries[NMESH] = { "51 Chef", "52 Parasaurolophus", "53 Rooster", "54 T-rex" }; -const char *materialMenuEntries[8] = { - "All R/G/B", "Ambient R/G/B", "Diffuse R/G/B", "Specular R/G/B", - "All Amb/Diff/Spec/Shine", "Red Amb/Diff/Spec/Shine", "Green Amb/Diff/Spec/Shine", "Blue Amb/Diff/Spec/Shine" -}; + void processMainEvents(int id) { - if(id == 99) exit(0); + switch (id) { + case EXIT: + exit(0); + + } } void processObjectEvents(int id) { @@ -220,66 +246,94 @@ void processLightEvents(int id) { } -void makeMenu() { - //int main, object, objectsize, material, texture, gtexture, light; - - glutCreateMenu(processMainEvents); - - - int objectSize = sizeof(objectMenuEntries) / sizeof(objectMenuEntries[0]); - int numMenus = objectSize/10 + 1; - int objectSubmenu[numMenus]; - - // Create the n-(n+10) menus - for ( int i = 0; i < numMenus; i++ ) { - - objectSubmenu[i] = glutCreateMenu(processObjectEvents); +int makeSubmenuFromArray( const char *menuEntries, void *callback ) { + int menuEntriesSize = sizeof(menuEntries) / sizeof(menuEntries[0]); + int menuNumber = menuEntriesSize / 10 + 1; + 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 ); + } + } - for ( int j = 0; j < (i + 1) * 10; j++ ) { + 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 + 3; + } + sprintf(name, "%d-%d", startNum, endNum); + glutAddSubMenu( name, submenuObjects[i] ); + } - if ( objectMenuEntries[j] ) { - glutAddMenuEntry( objectMenuEntries[j], j + 1 ); - } else { - break; - } + return mainMenu; +} +void makeMenu() { + // Construct material menu + int materialMenu = glutCreateMenu(processMaterialEvents); + glutAddMenuEntry("All R/G/B", MATERIAL_ALL_RGB); + glutAddMenuEntry("Ambient R/G/B", MATERIAL_AMBIENT_RGB); + glutAddMenuEntry("Diffuse R/G/B", MATERIAL_DIFFUSE_RGB); + glutAddMenuEntry("Specular R/G/B", MATERIAL_SPECULAR_RGB); + glutAddMenuEntry("All Amb/Diff/Spec/Shine", MATERIAL_ALL_ADSS); + glutAddMenuEntry("Red Amb/Diff/Spec/Shine", MATERIAL_RED_ADSS); + glutAddMenuEntry("Green Amb/Diff/Spec/Shine", MATERIAL_GREEN_ADSS); + glutAddMenuEntry("Blue Amb/Diff/Spec/Shine", MATERIAL_BLUE_ADSS); + + // Construct light menu + int lightMenu = glutCreateMenu(processLightEvents); + glutAddMenuEntry("Move Light 1", LIGHT_MOVE_LIGHT_1); + glutAddMenuEntry("R/G/B/All Light 1", LIGHT_RGBALL_LIGHT_1); + glutAddMenuEntry("Move Light 2", LIGHT_MOVE_LIGHT_2); + glutAddMenuEntry("R/G/B/All Light 2", LIGHT_RGBALL_LIGHT_2); + + // Construct add object submenus + int addObjectMenu = makeSubmenuFromArray( objectMenuEntries, processObjectEvents ); + + // Construct texture/ground texture submenus +/* int textureMenuEntries = sizeof(textureMenuEntries) / sizeof(textureMenuEntries[0]); + int menuNumber = textureMenuEntries / 10 + 1; + int textureSubmenu[menuNumber-1]; + + for( int i = 0; i < menuNumber; i++ ) { + textureSubmenu[i] = glutCreateMenu(processTextureEvents); + 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 ); } + }*/ - } - // Create the overmenu - int objectMenu = glutCreateMenu(processObjectEvents); - for ( int i = 0; objectSubmenu[i]; i++ ) { - char name[10]; - sprintf(name,"%d",(i + 1) * 10); - glutAddSubMenu( name, objectSubmenu[i] ); - } + int mainMenu = glutCreateMenu(processMainEvents); - glutAddSubMenu("Objects", objectMenu); - glutAddMenuEntry("Exit", 99); + glutAddMenuEntry("Rotate/Move Camera", ROTATE_MOVE_CAMERA); + glutAddSubMenu("Add object", addObjectMenu); + glutAddMenuEntry("Position/Scale", POSITION_SCALE); + glutAddMenuEntry("Rotation/Texture Scale", ROTATION_TEXTURE_SCALE); + //material + glutSetMenu(mainMenu); + glutAddSubMenu("Material", materialMenu); + + //texture + //ground texture + //lights - glutAttachMenu(GLUT_RIGHT_BUTTON); - -} - - -/*void createGLUTMenus() { - - int menu,submenu; - submenu = glutCreateMenu(processMenuEvents); - glutAddMenuEntry("Red",RED); - glutAddMenuEntry("Blue",BLUE); - glutAddMenuEntry("Green",GREEN); + glutAddMenuEntry("Exit", EXIT); - menu = glutCreateMenu(processMenuEvents); - glutAddMenuEntry("White",WHITE); - glutAddSubMenu("RGB Menu",submenu); - glutAttachMenu(GLUT_RIGHT_BUTTON); -*/ + glutAttachMenu(GLUT_RIGHT_BUTTON); +} void display() { // You probably want to change both of the following.