/* Handle user input */ void myKeyHandler(unsigned char ch, int x, int y) { switch(ch) { case 'c': resetCamera(); printf("Camera reset.\n"); break; case 's': case 'S': if (disp_style == DS_SOLID) { disp_style = DS_WIRE; } else { disp_style = DS_SOLID; } print_disp_style(); break; case 'd': /* Cycle through the various display modes */ disp_mode = (disp_mode + 1) % DM_MAX; print_disp_mode(); break; case 'D': /* Cycle through the various display modes backwards */ /* By adding DM_MAX, the args to "%" wil never be negative */ disp_mode = (disp_mode + DM_MAX - 1) % DM_MAX; print_disp_mode(); break; case ',': rotateCamera(5, X_AXIS); break; case '<': rotateCamera(-5, X_AXIS); break; case '.': rotateCamera(5, Y_AXIS); break; case '>': rotateCamera(-5, Y_AXIS); break; case '/': rotateCamera(5, Z_AXIS); break; case '?': rotateCamera(-5, Z_AXIS); break; case '+': /* Zoom in */ zoomCamera(-0.1); break; case '=': /* Zoom out */ zoomCamera(0.1); break; case 'z': myResize(win_width, win_height); printf("Window set to default size.\n"); break; case 't': performanceTest(); break; case 'q': /* Quit with exit code 0 */ endCanvas(0); break; /*********************************************/ /* ADD ADDITIONAL KEYS HERE */ /*********************************************/ case 'i': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if // Increases the radius of triangles in draw_cone_tri_calc r += 0.1; printf("Radius increased by 0.1\n"); break; case 'I': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if r -= 0.1; if (r < 0.1) { r = 0.1; } // if else { printf("Radius decreased by 0.1\n"); } // else break; case 'o': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if // Increase the height of triangles in draw_cone_tri_calc h += 0.1; printf("Height increased by 0.1\n"); break; case 'O': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if h -= 0.1; if (h < 0.1) { h = 0.1; } // if else { printf("Height decreased by 0.1\n"); } // else break; case 'p': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if // Increase number of triangles in draw_cone_tri_calc n += 1; printf("Number of triangles increased by 1\n"); break; case 'P': // If disp mode is not in cone_tri_calc, don't change variable if (disp_mode != DM_CONE_TRI_CALC) { break; } // if n -= 1; if (n < 3) { n = 3; } // if else { printf("Number of triangles decreased by 1\n"); } // else break; case 'v': if (disp_mode != DM_VRML) { break; } // if vr_object = (vr_object + 1) % VR_MAX; print_vrml_object(); break; default: /* Unrecognized key press, just return */ return; break; } /* * If control reaches here, the key press was recognized. Refresh * the screen, since most key presses change the display in some way. */ myDisplay(); return; }
/* Handle user input */ void myKeyHandler(unsigned char ch, int x, int y) { switch(ch) { case 'c': resetCamera(); printf("Camera reset.\n"); break; case 's': case 'S': if (disp_style == DS_SOLID) { disp_style = DS_WIRE; } else { disp_style = DS_SOLID; } print_disp_style(); break; case 'd': /* Cycle through the various display modes */ disp_mode = (disp_mode + 1) % DM_MAX; print_disp_mode(); break; case 'D': /* Cycle through the various display modes backwards */ /* By adding DM_MAX, the args to "%" wil never be negative */ disp_mode = (disp_mode + DM_MAX - 1) % DM_MAX; print_disp_mode(); break; case ',': rotateCamera(5, X_AXIS); break; case '<': rotateCamera(-5, X_AXIS); break; case '.': rotateCamera(5, Y_AXIS); break; case '>': rotateCamera(-5, Y_AXIS); break; case '/': rotateCamera(5, Z_AXIS); break; case '?': rotateCamera(-5, Z_AXIS); break; case '+': /* Zoom in */ zoomCamera(-0.1); break; case '=': /* Zoom out */ zoomCamera(0.1); break; case 'z': myResize(win_width, win_height); printf("Window set to default size.\n"); break; case 't': performanceTest(); break; case 'q': /* Quit with exit code 0 */ endCanvas(0); break; /*********************************************/ /* ADD ADDITIONAL KEYS HERE */ /*********************************************/ //Controls for cone triangle calculation case 'I': radius += 0.1; printf("Radius increased to %.1f.\n", radius); break; case 'i': if(radius > 0.1) { radius -= 0.1; } printf("Radius decreased to %.1f.\n", radius); break; case 'O': height += 0.1; printf("Height increased to %.1f.\n", height); break; case 'o': if(height > 0.1) { height -= 0.1; } printf("Height decreased to %.1f.\n", height); break; case 'P': sides += 1; printf("Sides increased to %d.\n", sides); break; case 'p': if(sides > 3) { sides -= 1; } printf("Sides decreased to %d.\n", sides); break; //Controls for switching between vrml objects case 'v': vr_object++; if(vr_object >= VR_MAX) { vr_object = 0; } print_vrml_object(); break; /* Switching between free scene modes */ case 'f': free_scene_mode++; break; case 'F': free_scene_mode--; case 'a': animate = !animate; if(animate) { printf("Animation engaged.\n"); } else { printf("Animation disengaged.\n"); } break; /* Allows mathematical shading on display mode 7 */ case 'y': color_change = !color_change; if(color_change) { printf("Mathematical shading for Display Mode 7.\n"); } else { printf("Regular displace in Display Mode 7.\n"); } break; case 'l': lighting = !lighting; if(lighting) { printf("Lighting Engaged. \n"); light_me_up(); glutPostRedisplay(); } else { printf("Lighting Disengaged. \n"); turn_out_lights(); glutPostRedisplay(); } default: /* Unrecognized key press, just return */ return; break; } /* * If control reaches here, the key press was recognized. Refresh * the screen, since most key presses change the display in some way. */ myDisplay(); return; }