(no commit message)
[atyndall/cits2231.git] / scene.c
diff --git a/scene.c b/scene.c
index 2a5ab65..c7d5318 100644 (file)
--- a/scene.c
+++ b/scene.c
@@ -268,19 +268,29 @@ void makeMenu() {
   glutAddMenuEntry("R/G/B/All Light 2", LIGHT_RGBALL_LIGHT_2);\r
 \r
   // Construct add object submenus\r
-  int addObjectSubmenu[6];\r
+  int objectMenuEntriesSize = sizeof(objectMenuEntries) / sizeof(objectMenuEntries[0]);\r
+  int menuNumber = objectMenuEntriesSize / 10 + 1;\r
+  int addObjectSubmenu[menuNumber-1];\r
 \r
-  for( int i = 0; i < 6; i++ ) {\r
+  for( int i = 0; i < menuNumber; i++ ) {\r
     addObjectSubmenu[i] = glutCreateMenu(processObjectEvents);\r
-    for ( int j = i; j < (i+9); j++ ) {\r
+    int startNum = i*11 - (i-1);\r
+    for ( int j = startNum - 1; j < (startNum+9); j++ ) {\r
+      if ( j == objectMenuEntriesSize ) break; // Detect if we've reached the end of the array\r
       glutAddMenuEntry( objectMenuEntries[j], j );\r
     }\r
   }\r
 \r
   // Construct add object menu\r
   int addObjectMenu = glutCreateMenu(processObjectEvents);\r
-  for ( int i = 0; addObjectSubmenu[i]; i++ ) {\r
-    char * name = { (char)i };\r
+  for ( int i = 0; i < menuNumber; i++ ) {\r
+    char name[10]; // buffer to hold name\r
+    int startNum = i*11 - (i-1);\r
+    int endNum = startNum + 9;\r
+    if ( i == menuNumber - 1 ) { // We're on the last one\r
+      endNum = startNum + 4;\r
+    }\r
+    sprintf(name, "%d-%d", startNum, endNum);\r
     glutAddSubMenu( name, addObjectSubmenu[i] );\r
   }\r
 \r
@@ -288,7 +298,7 @@ void makeMenu() {
   int mainMenu = glutCreateMenu(processMainEvents);\r
 \r
   glutAddMenuEntry("Rotate/Move Camera", ROTATE_MOVE_CAMERA);\r
-  //Add object\r
+  glutAddSubMenu("Add object", addObjectMenu);\r
   glutAddMenuEntry("Position/Scale", POSITION_SCALE);\r
   glutAddMenuEntry("Rotation/Texture Scale", ROTATION_TEXTURE_SCALE);\r
   //material\r

UCC git Repository :: git.ucc.asn.au