X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=882b7ccb256d583ec317195149413c404c540544;hb=eb5b2a18c2e9de277fd913619afaf971e4401463;hp=cffbd54e6f6b6fd87eda893905f0564df39e9a98;hpb=1b02ad4420ea898233356a4680a551c39e388a1e;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index cffbd54..882b7cc 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,70 +246,73 @@ 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]; - - for( int i = 0; objectSubmenu[i]; i++ ) { - objectSubmenu[i] = 0; - } - - // 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; - } +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 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); + sprintf(name, "%d-%d", startNum, startNum + 9); + glutAddSubMenu( name, addObjectSubmenu[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); + int mainMenu = glutCreateMenu(processMainEvents); + + 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.