X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=53b3187a3be73e42ab2cd155a3970da326a1a22a;hb=9166122b3c6a85c235df749e2a9aba0fa8e1c20e;hp=19df5d3252870eccd2dbed0b7a651ec962ef29d8;hpb=509cc867cc03c678702153807a22d0e02b397359;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index 19df5d3..53b3187 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,71 +246,80 @@ void processLightEvents(int id) { } -void makeMenu() { - //int main, object, objectsize, material, texture, gtexture, light; - - glutCreateMenu(processMainEvents); - +int makeSubmenuFromArray( const char *menuEntries[], unsigned int menuEntriesSize, void *callback ) { + if ( menuEntriesSize == 0 ) return -1; - /*int objectSize = sizeof(objectMenuEntries) / sizeof(objectMenuEntries[0]); - int numMenus = objectSize/10 + 1; - int objectSubmenu[numMenus]; + int menuNumber = menuEntriesSize / 10 + 1; + int submenuObjects[menuNumber-1]; - for( int i = 0; objectSubmenu[i]; i++ ) { - objectSubmenu[i] = 0; + 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 ); + } } - // Create the n-(n+10) menus - for ( int i = 0; i < numMenus; i++ ) { - - objectSubmenu[i] = glutCreateMenu(processObjectEvents); - - for ( int j = 0; j < (i + 1) * 10; j++ ) { - - if ( objectMenuEntries[j] ) { - glutAddMenuEntry( objectMenuEntries[j], j + 1 ); - } else { - break; - } - + 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] ); } - // 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] ); - }*/ - - //glutAddSubMenu("Objects", objectMenu); - glutAddMenuEntry("Exit", 99); - - - + 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 object menu + int objectMenuEntriesSize = sizeof(objectMenuEntries) / sizeof(objectMenuEntries[0]); + 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", 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); - } - -/*void createGLUTMenus() { - - int menu,submenu; - - submenu = glutCreateMenu(processMenuEvents); - glutAddMenuEntry("Red",RED); - glutAddMenuEntry("Blue",BLUE); - glutAddMenuEntry("Green",GREEN); - - menu = glutCreateMenu(processMenuEvents); - glutAddMenuEntry("White",WHITE); - glutAddSubMenu("RGB Menu",submenu); - glutAttachMenu(GLUT_RIGHT_BUTTON); -*/ - void display() { // You probably want to change both of the following. glClear(GL_COLOR_BUFFER_BIT);