void keyboard(unsigned char key, int x, int y) //------------------------------------------------------------------------------ // GLUT 'keyboard' Callback. User pressed an alphanumeric keyboard key. // (x,y, give current mouse position). // ('special' keys such as return, function keys, arrow keys? keyboardspecial) { int curMatl; int junk; // to stop compiler warnings junk = x; junk = y; // stops warnings of 'unused parameters' x,y switch(key) { case 27: // Esc case 'Q': case 'q': case ' ': exit(0); // Quit application break; case 'H': case 'h': cout << "\nHELP MENU FOR PROJECT C/D (PROGRAMMABLE SHADERS)" << "\n------------------------------------------------" << "\nDrag the mouse to adjust the movable 3D camera" << "\nUse the arrow keys to move the camera/lighting around" << "\nUse R (capital for model, lowercase for camera) to reset" << "\nUse M to change the color of one of the teapots (shading mix)" << "\nUse + and - to zoom in and out of the picture" << "\nUse L to turn lamps on and off" << "\nQ, ENTER or SPACE BAR will quit the program" << endl << endl; break; case 'l': case 'L': if (lamp1On) { lamps[0].removeLamp(); lamp1On = !lamp1On; } else { lamps[0].applyLamp(); lamp1On = !lamp1On; } break; case 'k': case 'K': if(lamp2On) { lamps[1].removeLamp(); lamp2On = !lamp2On; } else { lamps[1].applyLamp(); lamp2On = !lamp2On; } break; case 'r': setCam.reset(); // reset camera coord system, break; case 'R': setModel.reset(); // reset model coord system. break; case 'm': case 'M': // Cycle through all materials for stuff[0]; curMatl = stuff[0].matlType; // get ID# for current material curMatl += 1; // go to next material, but stay within if(curMatl > MATL_MAX) curMatl = MATL_RED_PLASTIC; // defined ones. stuff[0].createMatl(curMatl); // change the material. break; case 'O': // -Z Translation for model coord system setModel.z_pos -= 0.3; break; case 'P': // +Z Translation for model coord system setModel.z_pos += 0.3; break; case '+': // PhotoShop-like move in/out with +/- keys case '=': setCam.z_pos += 0.1; break; case '-': setCam.z_pos -= 0.1; break; default: printf("unknown key %c: Try arrow keys, r, R, s, S, <, >, or q",key); break; } // We might have changed something. Force a re-display glutPostRedisplay(); }
void myKeyboard(unsigned char key, int x, int y) //------------------------------------------------------------------------------ // GLUT CALLBACK: Don't call this function in your program--GLUT does it every // time user presses an alphanumeric key on the keyboard. // xw,yw == mouse position in window-system pixels (origin at UPPER left) { int curMatl; int junk; // to stop compiler warnings junk = x; junk = y; // stops warnings of 'unused parameters' x,y switch(key) { case 27: // Esc case 'Q': case 'q': case ' ': exit(0); // Quit application break; case 'r': setCam.reset(); // reset camera coord system, break; case 'R': setModel.reset(); // reset model coord system. break; case 'm': case 'M': // Cycle through all materials for stuff[0]; break; case '<': // -Z Translation for model coord system setModel.z_pos -= 0.3; break; case '>': // +Z Translation for model coord system setModel.z_pos += 0.3; break; case 's': if(material_changeflag==0) material_changeflag=1; else material_changeflag = 0; case '+': // PhotoShop-like move in/out with +/- keys case '=': setCam.z_pos += 0.1; break; case 'h': printHelp(); case '-': setCam.z_pos -= 0.1; break; case '1': if(light1==0) light1=1; else light1 = 0; cout<<light1<<endl; break; case 't': //apply textures if(texdraw==0) texdraw = 1; else texdraw = 0; break; case '2' : if(light2==0) light2=1; else light2 = 0; break; case '0': if(light0==0) light0=1; else light0 = 0; default: printf("unknown key %c: Try arrow keys, r, R, s, S, <, >, or q",key); break; } }