X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=scene.c;h=602dc49d32203abd6c444e39b81bb16f98803289;hb=a80b904b2d8e211f02e0833183200cc3bebd40b7;hp=2733cf8820f58b9a163a8c063f6fdbd2569278ec;hpb=17cb701324fd442c5c9cc9ea6b662bf829d92ff2;p=atyndall%2Fcits2231.git diff --git a/scene.c b/scene.c index 2733cf8..602dc49 100644 --- a/scene.c +++ b/scene.c @@ -246,7 +246,46 @@ void processLightEvents(int id) { } +int roundUp(int numToRound, int multiple) { + if(multiple == 0) { + return numToRound; + } + + int remainder = numToRound % multiple; + if (remainder == 0) + return numToRound; + return numToRound + multiple - remainder; +} + +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,47 +306,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 - int addObjectSubmenu[6]; + // Construct object menu int objectMenuEntriesSize = sizeof(objectMenuEntries) / sizeof(objectMenuEntries[0]); - int menuNumber = objectMenuEntriesSize / 10 + 1; - - for( int i = 0; i < menuNumber; i++ ) { - addObjectSubmenu[i] = glutCreateMenu(processObjectEvents); - for ( int j = i; j < (i+9); j++ ) { - if ( !objectMenuEntries[j] ) break; // Detect if we've reached the end of the array - glutAddMenuEntry( objectMenuEntries[j], j ); - } - } - - // Construct add object menu - int addObjectMenu = glutCreateMenu(processObjectEvents); - glutAddSubMenu( "test", addObjectSubmenu[0] ); - /*for ( int i = 0; addObjectSubmenu[i]; i++ ) { - glutAddSubMenu( (char)i, 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); }