static void Mouse(int button, int state, int x, int y) { int mods; if (state == GLUT_DOWN) ButtonState |= 1<<button; else if (state == GLUT_UP) ButtonState = 0; mods = glutGetModifiers(); if (mods & GLUT_ACTIVE_SHIFT) { ButtonState = 2; } else if (mods & GLUT_ACTIVE_CTRL) { ButtonState = 3; } MouseX = x; MouseY = y; glutPostRedisplay(); }
void mouse(int button, int state, int x, int y) { /* hack for 2 button mouse */ if (button == GLUT_LEFT_BUTTON && glutGetModifiers() & GLUT_ACTIVE_SHIFT) button = GLUT_MIDDLE_BUTTON; if(state == GLUT_DOWN) { switch(button) { case GLUT_LEFT_BUTTON: mot = PAN; motion(ox = x, oy = y); break; case GLUT_RIGHT_BUTTON: mot = ROT; motion(ox = x, oy = y); break; case GLUT_MIDDLE_BUTTON: break; } } else if (state == GLUT_UP) { mot = 0; } }
static void onKeyboard(unsigned char key, int x, int y) { int m = glutGetModifiers(); s_last_shift_mask = (m & GLUT_ACTIVE_SHIFT) != 0; s_last_ctrl_mask = (m & GLUT_ACTIVE_CTRL) != 0; s_last_alt_mask = (m & GLUT_ACTIVE_ALT) != 0; for (size_t i = 0; i < s_key_code_count; i++) if (s_key_code[i].key == key) { s_key = s_key_code[i].type; break; } if (s_key == fsInputMgr::KEY_NONE) { for (size_t i = 0; i < s_alpha_key_code_count; i++) if (s_alpha_key_code[i].keyL == key || s_alpha_key_code[i].keyC == key) { s_key = s_alpha_key_code[i].type; break; } } }
void mousebutton(int button, int state, int x, int y) { switch (button) { case GLUT_LEFT_BUTTON: g_iLeftMouseButton = (state==GLUT_DOWN); dragging=1; drag_x_origin = x; drag_y_origin = y; break; case GLUT_MIDDLE_BUTTON: g_iMiddleMouseButton = (state==GLUT_DOWN); break; case GLUT_RIGHT_BUTTON: g_iRightMouseButton = (state==GLUT_DOWN); break; } switch(glutGetModifiers()) { case GLUT_ACTIVE_CTRL: g_ControlState = TRANSLATE; break; case GLUT_ACTIVE_SHIFT: g_ControlState = SCALE; break; default: g_ControlState = ROTATE; break; } g_vMousePos[0] = x; g_vMousePos[1] = y; }
int Scene::mouseClicked( shared_ptr<ViewInterface> view, int button, int state, int x, int y ) { if (state) { drag_bone = false; clickx = 0; clicky = 0; return false; } if ((glutGetModifiers() & GLUT_ACTIVE_CTRL) == GLUT_ACTIVE_CTRL) { if (button == 0) { int bone = mouseSelect(x, y); selectedBone = (selectedBone == bone)? -1: bone; } return true; } else if (button == 0) { drag_bone = true; clickx = x; clicky = y; } else if (button == 2) { player.path->append( view->unProject(x, y) ); } return true; }
static void gfuiSpecial(int key, int /* x */, int /* y */) { tGfuiKey *curKey; int modifier; tGfuiObject *obj; modifier = glutGetModifiers(); /* user preempt key */ if (GfuiScreen->onSKeyAction && GfuiScreen->onSKeyAction(key, modifier, GFUI_KEY_DOWN)) { return; } /* now see the user's defined keys */ if (GfuiScreen->userSpecKeys != NULL) { curKey = GfuiScreen->userSpecKeys; do { curKey = curKey->next; if ((curKey->specialkey == key) && ((curKey->modifier == 0) || (curKey->modifier & modifier) != 0)) { if (curKey->onPress) curKey->onPress(curKey->userData); break; } } while (curKey != GfuiScreen->userSpecKeys); } obj = GfuiScreen->hasFocus; if (obj != NULL) { switch (obj->widget) { case GFUI_EDITBOX: gfuiEditboxKey(obj, key + 256, modifier); break; } } glutPostRedisplay(); }
static void glutMouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { if (glutGetModifiers() & GLUT_ACTIVE_SHIFT) { gIsScalingCamera = true; } else { gIsRotatingCamera = true; printf("rotating \n"); } gLastMouseX = x; gLastMouseY = y; } else { gIsRotatingCamera = false; gIsScalingCamera = false; } }
void rorelse(unsigned char key, int xx, int yy) { if (key == 65 || key == 97) mainPlayer.moveLeft(); if (key == 68 || key == 100) mainPlayer.moveRight(); if (key == 27) exit(0); if (key == 32) mainPlayer.jump(); int modifier = glutGetModifiers(); if (modifier == 1) { mainPlayer.setSpeed(0.3f); } else { mainPlayer.setSpeed(0.1f); } }
void GlutWindow::mouseClickFunc(int b, int s, int x, int y) { int m = glutGetModifiers(); #ifdef GLUT_WHEEL_UP if (b == GLUT_WHEEL_UP) { #else if (b == GLUT_WHEEL_UP_BUTTON) { if (s == 0) #endif INSTANCES[glutGetWindow()]->mouseWheel(WHEEL_UP, (modifier) m, x, y); return; } #ifdef GLUT_WHEEL_DOWN if (b == GLUT_WHEEL_DOWN) { #else if (b == GLUT_WHEEL_DOWN_BUTTON) { if (s == 0) #endif INSTANCES[glutGetWindow()]->mouseWheel(WHEEL_DOWN, (modifier) m, x, y); return; } INSTANCES[glutGetWindow()]->mouseClick((button) b, (state) s, (modifier) m, x, y); } void GlutWindow::mouseMotionFunc(int x, int y) { INSTANCES[glutGetWindow()]->mouseMotion(x, y); } void GlutWindow::mousePassiveMotionFunc(int x, int y) { INSTANCES[glutGetWindow()]->mousePassiveMotion(x, y); }
void respond_mouse(int button, int state, int x, int y) { if (button == GLUT_RIGHT_BUTTON) buttonState = 3; if (button == GLUT_LEFT_BUTTON) buttonState = 1; int mods = glutGetModifiers(); if (mods & GLUT_ACTIVE_CTRL) { buttonState = 2; } if(state == GLUT_UP) buttonState = 0; old_x=x; old_y=y; if (button == 3) // mouse wheel up { sc *= 1.1f; // Zoom in } if (button == 4) // mouse wheel down { sc /= 1.1f; // Zoom out } }
//-***************************************************************************** void mouse( int button, int state, int x, int y ) { g_state.last_x = x; g_state.last_y = y; if ( state == GLUT_DOWN ) { switch( button ) { case GLUT_LEFT_BUTTON: g_state.bMask += BMASK_LEFT; break; case GLUT_MIDDLE_BUTTON: g_state.bMask += BMASK_MIDDLE; break; case GLUT_RIGHT_BUTTON: g_state.bMask += BMASK_RIGHT; break; } } else { switch( button ) { case GLUT_LEFT_BUTTON: g_state.bMask -= BMASK_LEFT; break; case GLUT_MIDDLE_BUTTON: g_state.bMask -= BMASK_MIDDLE; break; case GLUT_RIGHT_BUTTON: g_state.bMask -= BMASK_RIGHT; break; } } g_state.mods = glutGetModifiers(); }
void GlutWindow::specialKeyUpFunc(int k, int x, int y) { int m = glutGetModifiers(); INSTANCES[glutGetWindow()]->specialKeyReleased((key) k, (modifier) m, x, y); }
void GlutWindow::keyboardUpFunc(unsigned char c, int x, int y) { int m = glutGetModifiers(); INSTANCES[glutGetWindow()]->keyReleased(c, (modifier) m, x, y); }
Key GLUTInput::convertSpecialCharacter(unsigned char key) { int value = 0; Key gcnKey; value = (int)key; switch(key) { case GLUT_KEY_UP: value = Key::UP; break; case GLUT_KEY_DOWN: value = Key::DOWN; break; case GLUT_KEY_RIGHT: value = Key::RIGHT; break; case GLUT_KEY_LEFT: value = Key::LEFT; break; case GLUT_KEY_F1: value = Key::F1; break; case GLUT_KEY_F2: value = Key::F2; break; case GLUT_KEY_F3: value = Key::F3; break; case GLUT_KEY_F4: value = Key::F4; break; case GLUT_KEY_F5: value = Key::F5; break; case GLUT_KEY_F6: value = Key::F6; break; case GLUT_KEY_F7: value = Key::F7; break; case GLUT_KEY_F8: value = Key::F8; break; case GLUT_KEY_F9: value = Key::F9; break; case GLUT_KEY_F10: value = Key::F10; break; case GLUT_KEY_F11: value = Key::F11; break; case GLUT_KEY_F12: value = Key::F12; break; case GLUT_KEY_PAGE_UP: value = Key::PAGE_UP; break; case GLUT_KEY_PAGE_DOWN: value = Key::PAGE_DOWN; break; case GLUT_KEY_HOME: value = Key::HOME; break; case GLUT_KEY_END: value = Key::END; break; case GLUT_KEY_INSERT: value = Key::INSERT; break; default: break; } int modifiers = glutGetModifiers(); #if 0 gcnKey.setShiftPressed(modifiers & GLUT_ACTIVE_SHIFT); gcnKey.setControlPressed(modifiers & GLUT_ACTIVE_CTRL); gcnKey.setAltPressed(modifiers & GLUT_ACTIVE_ALT); #endif gcnKey = (value); return gcnKey; }
static void KeyboardSpecial(int key, int x, int y) { B2_NOT_USED(x); B2_NOT_USED(y); int mod = glutGetModifiers(); switch (key) { // Press left to pan left. case GLUT_KEY_LEFT: if (mod == GLUT_ACTIVE_CTRL) { b2Vec2 newOrigin(2.0f, 0.0f); test->ShiftOrigin(newOrigin); } else { settings.viewCenter.x -= 0.5f; Resize(width, height); } break; // Press right to pan right. case GLUT_KEY_RIGHT: if (mod == GLUT_ACTIVE_CTRL) { b2Vec2 newOrigin(-2.0f, 0.0f); test->ShiftOrigin(newOrigin); } else { settings.viewCenter.x += 0.5f; Resize(width, height); } break; // Press down to pan down. case GLUT_KEY_DOWN: if (mod == GLUT_ACTIVE_CTRL) { b2Vec2 newOrigin(0.0f, 2.0f); test->ShiftOrigin(newOrigin); } else { settings.viewCenter.y -= 0.5f; Resize(width, height); } break; // Press up to pan up. case GLUT_KEY_UP: if (mod == GLUT_ACTIVE_CTRL) { b2Vec2 newOrigin(0.0f, -2.0f); test->ShiftOrigin(newOrigin); } else { settings.viewCenter.y += 0.5f; Resize(width, height); } break; // Press home to reset the view. case GLUT_KEY_HOME: viewZoom = 1.0f; settings.viewCenter.Set(0.0f, 20.0f); Resize(width, height); break; } }
void ForkLiftDemo::specialKeyboard(int key, int x, int y) { if (key==GLUT_KEY_END) return; // printf("key = %i x=%i y=%i\n",key,x,y); int state; state=glutGetModifiers(); if (state & GLUT_ACTIVE_SHIFT) { switch (key) { case GLUT_KEY_LEFT : { m_liftHinge->setLimit(-M_PI/16.0f, M_PI/8.0f); m_liftHinge->enableAngularMotor(true, -0.1, 10.0); break; } case GLUT_KEY_RIGHT : { m_liftHinge->setLimit(-M_PI/16.0f, M_PI/8.0f); m_liftHinge->enableAngularMotor(true, 0.1, 10.0); break; } case GLUT_KEY_UP : { m_forkSlider->setLowerLinLimit(0.1f); m_forkSlider->setUpperLinLimit(3.9f); m_forkSlider->setPoweredLinMotor(true); m_forkSlider->setMaxLinMotorForce(10.0); m_forkSlider->setTargetLinMotorVelocity(1.0); break; } case GLUT_KEY_DOWN : { m_forkSlider->setLowerLinLimit(0.1f); m_forkSlider->setUpperLinLimit(3.9f); m_forkSlider->setPoweredLinMotor(true); m_forkSlider->setMaxLinMotorForce(10.0); m_forkSlider->setTargetLinMotorVelocity(-1.0); break; } default: DemoApplication::specialKeyboard(key,x,y); break; } } else { switch (key) { case GLUT_KEY_LEFT : { gVehicleSteering += steeringIncrement; if ( gVehicleSteering > steeringClamp) gVehicleSteering = steeringClamp; break; } case GLUT_KEY_RIGHT : { gVehicleSteering -= steeringIncrement; if ( gVehicleSteering < -steeringClamp) gVehicleSteering = -steeringClamp; break; } case GLUT_KEY_UP : { gEngineForce = maxEngineForce; gBreakingForce = 0.f; break; } case GLUT_KEY_DOWN : { gEngineForce = -maxEngineForce; gBreakingForce = 0.f; break; } case GLUT_KEY_F5: m_useDefaultCamera = !m_useDefaultCamera; break; default: DemoApplication::specialKeyboard(key,x,y); break; } } // glutPostRedisplay(); }
void keyboard(unsigned char key, int u2, int u3) { int mod = glutGetModifiers(); switch(key) { case 'w': warpView = true; switch(currentWarp){ case 0: warbird->warp(planet[1]->getX(),planet[1]->getY(),planet[1]->getZ()); glutPostRedisplay(); break; case 1: warbird->warp(planet[5]->getX(),planet[5]->getY(),planet[5]->getZ()); glutPostRedisplay(); break; case 2: warbird->warp(planet[6]->getX(),planet[6]->getY(),planet[6]->getZ()); glutPostRedisplay(); break; case 3: warbird->warp(planet[12]->getX(),planet[12]->getY(),planet[12]->getZ()); glutPostRedisplay(); break; } currentWarp++; if(currentWarp>3) currentWarp=0; currentView=0; break; case 'p': warpView=true; currentWarp++; if(currentWarp>3) currentWarp=0; break; case 'v': warpView=false; currentView++; if(currentView>1) currentView=0; printf("view: %d\n",currentView); glutPostRedisplay(); break; case 't': timer++; if(timer>=4) timer=0; if(timer==0){ timerDelay=40; sprintf(levelName,"Ace"); }else if(timer==1){ timerDelay = 100; sprintf(levelName,"Pilot"); }else if(timer==2){ timerDelay = 250; sprintf(levelName,"Trainee"); }else if(timer == 3){ timerDelay = 500; sprintf(levelName,"Debug"); } break; case 'q': exit(EXIT_SUCCESS); break; default: break; } }
void Hinge2Vehicle::specialKeyboard(int key, int x, int y) { #if 0 if (key==GLUT_KEY_END) return; // printf("key = %i x=%i y=%i\n",key,x,y); int state; state=glutGetModifiers(); if (state & GLUT_ACTIVE_SHIFT) { switch (key) { case GLUT_KEY_LEFT : { m_liftHinge->setLimit(-M_PI/16.0f, M_PI/8.0f); m_liftHinge->enableAngularMotor(true, -0.1, maxMotorImpulse); break; } case GLUT_KEY_RIGHT : { m_liftHinge->setLimit(-M_PI/16.0f, M_PI/8.0f); m_liftHinge->enableAngularMotor(true, 0.1, maxMotorImpulse); break; } case GLUT_KEY_UP : { m_forkSlider->setLowerLinLimit(0.1f); m_forkSlider->setUpperLinLimit(3.9f); m_forkSlider->setPoweredLinMotor(true); m_forkSlider->setMaxLinMotorForce(maxMotorImpulse); m_forkSlider->setTargetLinMotorVelocity(1.0); break; } case GLUT_KEY_DOWN : { m_forkSlider->setLowerLinLimit(0.1f); m_forkSlider->setUpperLinLimit(3.9f); m_forkSlider->setPoweredLinMotor(true); m_forkSlider->setMaxLinMotorForce(maxMotorImpulse); m_forkSlider->setTargetLinMotorVelocity(-1.0); break; } default: DemoApplication::specialKeyboard(key,x,y); break; } } else { switch (key) { case GLUT_KEY_LEFT : { gVehicleSteering += steeringIncrement; if ( gVehicleSteering > steeringClamp) gVehicleSteering = steeringClamp; break; } case GLUT_KEY_RIGHT : { gVehicleSteering -= steeringIncrement; if ( gVehicleSteering < -steeringClamp) gVehicleSteering = -steeringClamp; break; } case GLUT_KEY_UP : { gEngineForce = maxEngineForce; gBreakingForce = 0.f; break; } case GLUT_KEY_DOWN : { gEngineForce = -maxEngineForce; gBreakingForce = 0.f; break; } case GLUT_KEY_F7: { btDiscreteDynamicsWorld* world = (btDiscreteDynamicsWorld*)m_dynamicsWorld; world->setLatencyMotionStateInterpolation(!world->getLatencyMotionStateInterpolation()); printf("world latencyMotionStateInterpolation = %d\n", world->getLatencyMotionStateInterpolation()); break; } case GLUT_KEY_F6: { //switch solver (needs demo restart) useMCLPSolver = !useMCLPSolver; printf("switching to useMLCPSolver = %d\n", useMCLPSolver); delete m_solver; if (useMCLPSolver) { btDantzigSolver* mlcp = new btDantzigSolver(); //btSolveProjectedGaussSeidel* mlcp = new btSolveProjectedGaussSeidel; btMLCPSolver* sol = new btMLCPSolver(mlcp); m_solver = sol; } else { m_solver = new btSequentialImpulseConstraintSolver(); } m_dynamicsWorld->setConstraintSolver(m_solver); //exitPhysics(); //initPhysics(); break; } case GLUT_KEY_F5: m_useDefaultCamera = !m_useDefaultCamera; break; default: DemoApplication::specialKeyboard(key,x,y); break; } } // glutPostRedisplay(); #endif }
/* ARGSUSED1 */ void gokey(unsigned char key, int x, int y) { char str[100]; int mods; mods = glutGetModifiers(); printf("key = %d, mods = 0x%x\n", key, mods); if (mods & GLUT_ACTIVE_ALT) { switch (key) { case '1': printf("Change to sub menu 1\n"); glutChangeToSubMenu(1, "sub 1", submenu); break; case '2': printf("Change to sub menu 2\n"); glutChangeToSubMenu(2, "sub 2", submenu); break; case '3': printf("Change to sub menu 3\n"); glutChangeToSubMenu(3, "sub 3", submenu); break; case '4': printf("Change to sub menu 4\n"); glutChangeToSubMenu(4, "sub 4", submenu); break; case '5': printf("Change to sub menu 5\n"); glutChangeToSubMenu(5, "sub 5", submenu); break; } } else { switch (key) { case '1': printf("Change to menu entry 1\n"); glutChangeToMenuEntry(1, "entry 1", 1); break; case '2': printf("Change to menu entry 2\n"); glutChangeToMenuEntry(2, "entry 2", 2); break; case '3': printf("Change to menu entry 3\n"); glutChangeToMenuEntry(3, "entry 3", 3); break; case '4': printf("Change to menu entry 4\n"); glutChangeToMenuEntry(4, "entry 4", 4); break; case '5': printf("Change to menu entry 5\n"); glutChangeToMenuEntry(5, "entry 5", 5); break; case 'a': case 'A': printf("Adding menu entry %d\n", item); sprintf(str, "added entry %d", item); glutAddMenuEntry(str, item); item++; break; case 's': case 'S': printf("Adding submenu %d\n", item); sprintf(str, "added submenu %d", item); glutAddSubMenu(str, submenu); item++; break; case 'q': printf("Remove 1\n"); glutRemoveMenuItem(1); break; case 'w': printf("Remove 2\n"); glutRemoveMenuItem(2); break; case 'e': printf("Remove 3\n"); glutRemoveMenuItem(3); break; case 'r': printf("Remove 4\n"); glutRemoveMenuItem(4); break; case 't': printf("Remove 5\n"); glutRemoveMenuItem(5); break; } } }
void keyboard(unsigned char key, int x, int y) { if (isTypingFile) { if (key == 127 || key == 8) { //backspace if (tempLocation.size() > 0) { tempLocation = tempLocation.erase(tempLocation.size()-1); } } else if (key == 27) { //escape key tempLocation = ""; isTypingFile = false; } else if (key == 13) { //enter key if (fileWillOpen) { if (canvas->openScene(tempLocation)) { location = tempLocation; tempLocation = ""; } isTypingFile = false; } else { canvas->saveScene(tempLocation); isTypingFile = false; location = tempLocation; tempLocation = ""; needsSaveAsImage = true; } } else { tempLocation += key; } glutPostRedisplay(); return; } bool controlKey = false; if (glutGetModifiers() & GLUT_ACTIVE_CTRL) { key += 'a'-1; controlKey = true; } switch (key) { case 27: //escape key canvas->cancelDrawing(); break; case 8: case 127: //backspace canvas->deleteSelected(); break; case 'a': canvas->toggleSelectedAntialiased(); break; case 'f': if (controlKey) { canvas->bringToFront(); } else { canvas->bringForward(); } break; case 'b': if (controlKey) { canvas->sendToBack(); } else { canvas->sendBackward(); } break; case 'g': gridOn = !gridOn; canvas->setGridOn(gridOn); break; case 'x': snapOn = !snapOn; canvas->setSnapOn(snapOn); break; case 'h': hardwareRender = !hardwareRender; canvas->setHardwareRender(hardwareRender); break; case 'n': if (controlKey) { canvas->newScene(); } break; case 'o': if (controlKey) { isTypingFile = true; tempLocation = ""; fileWillOpen = true; } break; case 's': if (controlKey) { if (location == "" || (glutGetModifiers() & GLUT_ACTIVE_SHIFT)) { isTypingFile = true; tempLocation = ""; fileWillOpen = false; } needsSaveAsImage = true; } break; case 19: isTypingFile = true; tempLocation = ""; fileWillOpen = false; break; case 'c': if (controlKey) { canvas->toggleIsDrawingClipped(); } else { canvas->startDrawingClipView(); } break; default: break; } glutPostRedisplay(); }
void Scene::onKey( unsigned char key ) { int modifier = glutGetModifiers(); bool shiftPressed = ( modifier & GLUT_ACTIVE_SHIFT )!=0; bool ctrlPressed = ( modifier & GLUT_ACTIVE_CTRL )!=0; bool altPressed = ( modifier & GLUT_ACTIVE_ALT )!=0; switch ( key ) { case 27: // Escape case 'q': case 'Q': { exit( EXIT_SUCCESS ); break; } case 'r': case 'R': { reset(false); glutPostRedisplay(); break; } case 'f': case 'F': { _fullScreen = !_fullScreen; if ( _fullScreen ) { // Remember window position and size _posX = glutGet( GLUT_WINDOW_X ); _posY = glutGet( GLUT_WINDOW_Y ); _width = glutGet( GLUT_WINDOW_WIDTH ); _height = glutGet( GLUT_WINDOW_HEIGHT ); // Switch to fullscreen mode glutFullScreen(); } else { // Position and size window to previous values glutPositionWindow( _posX, _posY ); glutReshapeWindow( _width, _height ); } break; } case 'a': case 'A': { _playerTank.setIncreasingAzimuth(true); break; } case 'd': case 'D': { _playerTank.setDecreasingAzimuth(true); break; } case 'w': case 'W': { _playerTank.setIncreasingElevation(true); break; } case 's': case 'S': { _playerTank.setDecreasingElevation(true); break; } case '+': { _playerTank.setIncreasingPower(true); break; } case '-': { _playerTank.setDecreasingPower(true); break; } case ' ': { _playerTank.setShootingMG(true); break; } case 'x': { _playerTank.setShootingGrenade(true); break; } case 'z': { _frozen = !_frozen; _firstUpdate = true; break; } case 'c': _freeCamera = !_freeCamera; break; case '.': _FCdist*=2.0; break; case ',': _FCdist*=0.5; break; case '8': _FCx+=5; break; case '2': _FCx-=5; break; case '4': _FCz+=5; break; case '6': _FCz-=5; break; // output maparray around player for debug case 'M': case 'm': { int maparoundwidth = 5; TerrainType** maparound = _landscape.getMap(_playerTank.getPosition(),maparoundwidth); for (int x = 0; x<2*maparoundwidth+1; ++x) { for (int z = 0; z<2*maparoundwidth+1; ++z) { std::cout << (int)maparound[x][z]; } std::cout << std::endl; delete[] maparound[x]; } std::cout << std::endl; delete[] maparound; } break; // case 'b': //{ // //_playerTank.enableGrenadeLauncher(); // _playerTank.setNextWeapon(); // break; //} default: break; } }
void KeyboardDownCallback(unsigned char key, int x, int y) { switch (key) { case 'i': case 'I': debugInfo = !debugInfo; break; case 27: // ESCAPE myGlutStop(); break; // animation controls case '1' : goto_triangle = 1; break; case '2' : goto_square = 1; break; case '3' : break; // light controls case 'a' : case 'A' : if (difflight_color[0] > 0) { difflight_color[0] -= 0.05; } else { difflight_color[0] = 0; } if (difflight_color[0] > 0) { difflight_color[1] -= 0.05; } else { difflight_color[1] = 0; } if (difflight_color[2] > 0) { difflight_color[2] -= 0.05; } else { difflight_color[2] = 0; } break; case 's' : case 'S' : if (difflight_color[0] < 1) { difflight_color[0] += 0.05; } else { difflight_color[0] = 1; } if (difflight_color[1] < 1) { difflight_color[1] += 0.05; } else { difflight_color[1] = 1; } if (difflight_color[2] < 1) { difflight_color[2] += 0.05; } else { difflight_color[2] = 1; } break; case 'd' : case 'D' : if (lightOn) { glDisable(GL_LIGHT0); } else { glEnable(GL_LIGHT0); } lightOn = !lightOn; break; } // Remember mouse position GLUTmouse[0] = x; GLUTmouse[1] = GLUTwindow_height - y; // Remember modifiers GLUTmodifiers = glutGetModifiers(); glutPostRedisplay(); }
void keyboardSpecial(int key, int x, int y) { bool isShift = ((glutGetModifiers() & GLUT_ACTIVE_SHIFT) != 0); bool changed = true; int target = -1; int target_index = -1; int step_target = -1; switch (key) { case GLUT_KEY_DOWN: win.setFOV(win.fov() * 1.05); break; case GLUT_KEY_UP: win.setFOV(win.fov() / 1.05); break; case GLUT_KEY_F1: target = 0; target_index = 0; break; case GLUT_KEY_F2: target = 0; target_index = 1; break; case GLUT_KEY_F3: target = 0; target_index = 2; break; case GLUT_KEY_F4: target = 0; target_index = 3; break; case GLUT_KEY_F5: target = 1; target_index = 0; break; case GLUT_KEY_F6: target = 1; target_index = 1; break; case GLUT_KEY_F7: target = 1; target_index = 2; break; case GLUT_KEY_F8: target = 1; target_index = 3; break; case GLUT_KEY_F9: step_target = 0; changed = false; break; case GLUT_KEY_F10: step_target = 1; changed = false; break; } if (target != -1) { if (settings_target == 0) { // Set user parameters float add; if (isShift) add = -user_params_steps[target]; else add = +user_params_steps[target]; user_params[target][target_index] += add; tellUserParams(); } else if (settings_target == 1 && target < 3) { // Set lights float add; if (isShift) add = -lights_step; else add = +lights_step; lights_diffuse[target][target_index] += add; // Clip if (lights_diffuse[target][target_index] > 1.0) lights_diffuse[target][target_index] = 1.0; else if (lights_diffuse[target][target_index] < 0.0) lights_diffuse[target][target_index] = 0.0; tellLights(); } } if (step_target != -1) { if (settings_target == 0) { // Set user_params step size if (isShift) user_params_steps[step_target] /= 1.1; else user_params_steps[step_target] *= 1.1; tellUserParams(); } else if (settings_target == 1) { // Set lights step size if (isShift) lights_step /= 1.1; else lights_step *= 1.1; tellLights(); } } if (changed) glutPostRedisplay(); }
void onKeyboard(unsigned char key, int x, int y) { int modifier = glutGetModifiers(); //printf("modifier = %d\n", modifier); //printf("key = %d\n", key); switch(modifier){ case GLUT_ACTIVE_CTRL:{ switch(key) { /* ctrl+q */ case 17: break; /* ctrl+a */ case 1: break; /* ctrl+w */ case 23: break; /* ctrl+s */ case 19: break; /* ctrl+e */ case 5: break; /* ctrl+d */ case 4: break; } break; } } // normal keys switch(key){ case 'r': case 'R': isAutoRotating = isAutoRotating ^ 1; break; case 'Z': case 'z': currentModel = (currentModel + NUM_OF_MODEL - 1) % NUM_OF_MODEL; loadModel(currentModel); printf("loading %s\n", filename[currentModel]); break; case 'X': case 'x': currentModel = (currentModel + 1) % NUM_OF_MODEL; loadModel(currentModel); printf("loading %s\n", filename[currentModel]); break; case 'H': case 'h': showHelp(); break; case 'P': case 'p': if(projectionMode != PROJECTION_PERS){ projectionMode = PROJECTION_PERS; printf("perspective projection\n"); }else if(projectionMode != PROJECTION_PARA){ projectionMode = PROJECTION_PARA; printf("parallel projection\n"); } break; case 'T': case 't': MAPPING = !MAPPING; printf("MAPPING = %d\n", MAPPING); break; case 'M': if(texture_mag_filter == GL_LINEAR){ texture_mag_filter = GL_NEAREST; printf("MAG NEAREST\n"); } else{ texture_mag_filter = GL_LINEAR; printf("MAG LINEAR\n"); } break; case 'm': if(texture_min_filter == GL_LINEAR){ texture_min_filter = GL_NEAREST; printf("MIN NEAREST\n"); } else{ texture_min_filter = GL_LINEAR; printf("MIN LINEAR\n"); } break; case 'W': case'w': if(texture_wrap_mode == GL_REPEAT){ texture_wrap_mode = GL_CLAMP_TO_EDGE; printf("WRAP REPEAT\n"); } else{ texture_wrap_mode = GL_REPEAT; printf("WRAP CLAMP\n"); } break; case 27: // esc key exit(0); } //glutPostRedisplay(); }
void special(int key, int x, int y) { if(sKey == TRANSLATE) { switch( key ) { case GLUT_KEY_RIGHT://x方向 pos[objNo][0] += 0.1; break; case GLUT_KEY_LEFT://-x方向 pos[objNo][0] -= 0.1; break; case GLUT_KEY_UP: if(glutGetModifiers() == 0) pos[objNo][1] += 0.1;//y方向 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) pos[objNo][2] -= 0.1; //z方向 break; case GLUT_KEY_DOWN: if(glutGetModifiers() == 0) pos[objNo][1] -= 0.1;//-y方向 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) pos[objNo][2] += 0.1; //-z方向 break; default: break; } } else if(sKey == ROTATE) { switch( key ) { case GLUT_KEY_RIGHT://x軸回転 angle[objNo][0] += 10.0; break; case GLUT_KEY_LEFT://-x軸回転 angle[objNo][0] -= 10.0; break; case GLUT_KEY_UP: if(glutGetModifiers() == 0) angle[objNo][1] += 10;//y方向 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) angle[objNo][2] += 10; //z方向 break; case GLUT_KEY_DOWN: if(glutGetModifiers() == 0) angle[objNo][1] -= 10;//-y方向 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) angle[objNo][2] -= 10; //-z方向 break; default: break; } } else if(sKey == SCALE) { switch( key ) { case GLUT_KEY_RIGHT://x方向拡大 scale[objNo][0] += 0.1; break; case GLUT_KEY_LEFT://x方向縮小 scale[objNo][0] -= 0.1; break; case GLUT_KEY_UP: if(glutGetModifiers() == 0) scale[objNo][1] += 0.1;//y方向拡大 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) scale[objNo][2] += 0.1; //z方向 break; case GLUT_KEY_DOWN: if(glutGetModifiers() == 0) scale[objNo][1] -= 0.1;//y方向縮小 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) scale[objNo][2] -= 0.1; //z方向 break; default: break; } } else if(sKey == LIGHT) { float d = 1.0; switch( key ) { case GLUT_KEY_RIGHT://x方向 lightPos[0] += d; break; case GLUT_KEY_LEFT: lightPos[0] -= d;//-x方向 break; case GLUT_KEY_UP: if(glutGetModifiers() == 0) lightPos[1] += d;//y方向 if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) lightPos[2] -= d;//z方向 break; case GLUT_KEY_DOWN: if(glutGetModifiers() == 0) lightPos[1] -= d;//-y方向 if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) lightPos[2] += d;//-z方向 break; default: break; } } if(key == GLUT_KEY_F1) { if(glutGetModifiers() == 0) scaleTex += 0.01; if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) scaleTex -= 0.01; printf("scaleTex = %f \n", scaleTex); } if(key == GLUT_KEY_F2) { if(coord == OBJECT) coord = VIEW; else coord = OBJECT; } if(key == GLUT_KEY_PAGE_UP) { dang += 0.1; } if(key == GLUT_KEY_PAGE_DOWN) { dang -= 0.1; } }
//callbacks void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit (0); break; //draw objects case 'y': insertObj(Cube); break; case 'u': insertObj(Sphere); break; case 'i': insertObj(Cone); break; case 'o': insertObj(Torus); break; case 'p': insertObj(Teapot); break; //transformations case 'a': //-x if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(-0.1, 0, 0); if (mode%3==1&&!currentObj->isLight) currentObj->scale(-0.1, 0,0); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(-5,0,0); } break; case 'd': //+x if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(0.1, 0, 0); if (mode%3==1&&!currentObj->isLight) currentObj->scale(0.1,0,0); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(5,0,0); } break; case 'q': //-z if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(0, 0, -0.1); if (mode%3==1&&!currentObj->isLight) currentObj->scale(0, 0,-0.1); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(0,0,-5); } break; case 'e': //+z if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(0, 0, 0.1); if (mode%3==1&&!currentObj->isLight) currentObj->scale(0, 0,0.1); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(0,0,5); } break; case 's': //-y if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(0, -0.1, 0); if (mode%3==1&&!currentObj->isLight) currentObj->scale(0, -0.1,0); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(0,-5,0); } break; case 'w': //+y if (sceneObjs->size()!=0) { if (mode%3==0) currentObj->translate(0, 0.1, 0); if (mode%3==1&&!currentObj->isLight) currentObj->scale(0, 0.1,0); if (mode%3==2&&!currentObj->isLight) currentObj->rotate(0,5,0); } break; case 't': //transform type toggle mode++; if (mode%3==0) transformMode = t; if (mode%3==1) transformMode = s; if (mode%3==2) transformMode = r; break; case 32: //load/save if (glutGetModifiers()==GLUT_ACTIVE_CTRL) { sceneObjs = SG->load(); nextChild = sceneObjs->size(); currentObj = sceneObjs->at(0); currentObj->select(); } else SG->save(); break; //toggle materials case '1': curMat = m1; break; case '2': curMat = m2; break; case '3': curMat = m3; break; case '4': curMat = m4; break; case '5': curMat = m5; break; //change selected object's material to current material case 'm': if (!currentObj->isLight) currentObj->changeMaterial(curMat); break; //delete selected object case 'x': if (sceneObjs->size()!=0) { deleteObj(currentObj->ID); } break; //reset scene case 'r': SG = new SceneGraph(); nextChild = 0; sceneObjs = new vector<SceneObj*>; insertLight(light_pos0, amb0, diff0, spec0, 0); insertLight(light_pos1, amb1, diff1, spec1, 1); break; case 9: // toggle selected object (was used before ray picking implemented, still useful anyway) currentObj->unselect(); currentObj = sceneObjs->at(currentObjIndex++%sceneObjs->size()); currentObj->select(); break; default: break; } glutPostRedisplay(); }
void g2LabelEdit::KeyEvent(unsigned char key, bool IsSpecial) { // In OSX the backspace maps to DEL while DEL maps to backspace, need to swap #if __APPLE__ if(key == 127) key = 8; else if(key == 8) key = 127; #endif // Ignore all inputs if disabled if(GetDisabled()) return; /*** User Movement / Editing ***/ // If system key (i.e. left/right) else if(IsSpecial) { // Move far left/right if(key == GLUT_KEY_LEFT && glutGetModifiers() == GLUT_ACTIVE_CTRL) { CursorIndex = 0; ViewIndex = 0; } else if(key == GLUT_KEY_RIGHT && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Move the cursor to the far right and calculate // what is the best position for the view buffer to be moved to CursorIndex = (int)strlen(TextBuffer); // When something is written on-screen, check to see where our // left-view limit should be ViewIndex = (int)strlen(TextBuffer) - RenderableLeftChars(CursorIndex); } // If left/right, move the cursor if(key == GLUT_KEY_LEFT && CursorIndex > 0) { // Move cursor to left CursorIndex--; // Move view left if we can if(CursorIndex < ViewIndex) ViewIndex--; } else if(key == GLUT_KEY_RIGHT && CursorIndex < (int)strlen(TextBuffer)) { // Move cursor to right CursorIndex++; // If the movement will cause us to be offsreen.. while(LengthToCursor() > Width) ViewIndex++; } } // Backspace else if(key == 8) { // Is there anything to delete? if(strlen(TextBuffer) <= 0) return; // Ignore if we are at the 0 position else if(CursorIndex <= 0) return; else { // Delete this character by shifting everything from right to left by 1 // Note that this copies the null terminator for(size_t i = CursorIndex; i <= strlen(TextBuffer); i++) TextBuffer[i - 1] = TextBuffer[i]; // Decrease the cursor position CursorIndex--; // Is the cursor now smaller than the current view index // Move view left if we can while(CursorIndex < ViewIndex) { ViewIndex -= 5; if(ViewIndex < 0) ViewIndex = 0; } } } // Delete else if(key == 127) { // Is there anything to delete? if(CursorIndex >= (int)strlen(TextBuffer)) return; else { // Delete this character by shifting everything from right to left by 1 // Note that this copies the null terminator for(size_t i = CursorIndex; i < strlen(TextBuffer); i++) TextBuffer[i] = TextBuffer[i + 1]; // Cursor does not move } } // Commit / enter else if(key == '\r') { DidUserReturn = true; } /*** Cut, Copy, or Paste ***/ // Note that when doing a ctrl+key event, the given number // is offset from 'a', meaning true ascii = 'a' - key + 1 // Cut text else if(key == ('x' - 'a' + 1) && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Copy into buffer, then set text to empty CopyBuffer(); SetText(""); } // Copy text else if(key == ('c' - 'a' + 1) && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Direct copy CopyBuffer(); } // Paste text else if(key == ('v' - 'a' + 1) && glutGetModifiers() == GLUT_ACTIVE_CTRL) { // Direct paste PasteBuffer(); } /*** Regular User Input ***/ // Standard keyboard input; add character else if(isprint(key) != 0) { // Can we actually add anything? if(strlen(TextBuffer) < g2LabelEdit_TextBufferLength - 1 && !IsSpecial) { // Ignore if it isn't a valid character if(!InFilter(key)) return; // If we are writing to the end, make sure to string-cap if(CursorIndex == (int)strlen(TextBuffer)) { // Write to the old string-end and move the terminator a little further TextBuffer[CursorIndex + 0] = key; TextBuffer[CursorIndex + 1] = '\0'; } // Offset one char to the right, then set else { // Null-terminate the end of the string int Length = (int)strlen(TextBuffer); for(int i = Length; i > CursorIndex; i--) TextBuffer[i] = TextBuffer[i - 1]; TextBuffer[CursorIndex] = key; TextBuffer[Length + 1] = '\0'; } // Grow cursor position to be after the current char CursorIndex++; } // If the movement will cause us to be offsreen.. while(LengthToCursor() > Width) ViewIndex++; } // All done for each type of event }
void cbMouseInput(int button, int state, int x, int y) { switch (button){ case GLUT_LEFT_BUTTON: if (state == GLUT_DOWN) {mouse_rotate = 1; mouse_x = x; mouse_y = y; is_ctrl = glutGetModifiers();} if (state == GLUT_UP) {mouse_rotate = 0;} break; case GLUT_MIDDLE_BUTTON: case GLUT_RIGHT_BUTTON: break; default: printf ("MouseInput: No action assigned for %d and %d.\n", button, state); break; } }
void special(int key, int x, int y) { if(sKey == TRANSLATE) { switch( key ) { case GLUT_KEY_RIGHT://x方向 pos[0] += 0.1; break; case GLUT_KEY_LEFT://-x方向 pos[0] -= 0.1; break; case GLUT_KEY_UP: if(glutGetModifiers() == 0) pos[1] += 0.1;//y方向 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) pos[2] -= 0.1; //z方向 break; case GLUT_KEY_DOWN: if(glutGetModifiers() == 0) pos[1] -= 0.1;//-y方向 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) pos[2] += 0.1; //-z方向 break; default: break; } } else if(sKey == ROTATE) { switch( key ) { case GLUT_KEY_RIGHT://x軸回転 angle[0] += 10.0; break; case GLUT_KEY_LEFT://-x軸回転 angle[0] -= 10.0; break; case GLUT_KEY_UP: if(glutGetModifiers() == 0) angle[1] += 10;//y方向 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) angle[2] += 10; //z方向 break; case GLUT_KEY_DOWN: if(glutGetModifiers() == 0) angle[1] -= 10;//-y方向 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) angle[2] -= 10; //-z方向 break; default: break; } } else if(sKey == SCALE) { switch( key ) { case GLUT_KEY_RIGHT://x方向拡大 scale[0] += 0.1; break; case GLUT_KEY_LEFT://x方向縮小 scale[0] -= 0.1; break; case GLUT_KEY_UP: if(glutGetModifiers() == 0) scale[1] += 0.1;//y方向拡大 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) scale[2] += 0.1; //z方向 break; case GLUT_KEY_DOWN: if(glutGetModifiers() == 0) scale[1] -= 0.1;//y方向縮小 else if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) scale[2] -= 0.1; //z方向 break; default: break; } } else if(sKey == LIGHT) { float d = 1.0; switch( key ) { case GLUT_KEY_RIGHT://x方向 lightPos[0] += d; break; case GLUT_KEY_LEFT: lightPos[0] -= d;//-x方向 break; case GLUT_KEY_UP: if(glutGetModifiers() == 0) lightPos[1] += d;//y方向 if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) lightPos[2] -= d;//z方向 break; case GLUT_KEY_DOWN: if(glutGetModifiers() == 0) lightPos[1] -= d;//-y方向 if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) lightPos[2] += d;//-z方向 break; default: break; } } if(key == GLUT_KEY_F1) { init();//アニメーションスタート } if(key == GLUT_KEY_F2) { if(glutGetModifiers() == 0) transparency0 += 0.1; if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) transparency0 -= 0.1; if(transparency0 < 0.0) transparency0 = 0.0; if(transparency0 > 1.0) transparency0 = 1.0; printf("透明度= %f \n", transparency0); } if(key == GLUT_KEY_F3) { if(glutGetModifiers() == 0) nRatio0 += 0.1; if(glutGetModifiers() == GLUT_ACTIVE_SHIFT) nRatio0 -= 0.1; printf("比屈折率= %f \n", nRatio0); } }
void mouse(int button, int state, int x, int y) { if(!clipping && glutGetModifiers() == GLUT_ACTIVE_ALT && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ) { currentX = x; currentY = y; rotating = true; return; } if(!clipping && button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) { windowSize.x = x; windowSize.y = y; clipping = true; return; } if(clipping && button == GLUT_LEFT_BUTTON &&state == GLUT_UP) { int newx = min(windowSize.x, windowSize.z); int newy = min(windowSize.y, windowSize.w); int newz = max(windowSize.x, windowSize.z); int neww = max(windowSize.y, windowSize.w); windowSize = glm::vec4(newx,newy, newz, neww); SetScissorWindow(windowSize); clipping = false; return; } if(button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN) { currentX = x; currentY = y; dragging = true; } if(button == GLUT_MIDDLE_BUTTON && state == GLUT_UP) { dragging = false; } if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) { currentX = x; currentY = y; zoom = true; } if(button == GLUT_RIGHT_BUTTON && state == GLUT_UP) { zoom = false; } rotating = false; }