void keyboard(unsigned char key, int x, int y) { Vector3 origin = Vector3::ZERO; Vector3 direction_to_origin; switch (key) { case 27: // on [ESC] exit(0); // normal exit break; case ' ': camera.moveForward(0.5); break; case 'w': camera.moveUp(0.5); break; case 'a': camera.moveLeft(0.5); break; case 's': camera.moveDown(0.5); break; case 'd': camera.moveRight(0.5); break; case 'h': direction_to_origin = origin - camera.getPosition(); camera.rotateToVector(direction_to_origin, 0.1); break; case ',': camera.setRoll(0.1); break; case '.': camera.setRoll(-0.1); break; case '/': camera.moveBackward(0.5); break; } }
void update() { if (key_pressed[' ']) { camera.moveForward(MOVE_SPEED); } if (key_pressed['w'] || key_pressed['W']) { camera.moveUp(MOVE_SPEED); } if (key_pressed['a'] || key_pressed['A']) { camera.moveLeft(MOVE_SPEED); } if (key_pressed['s'] || key_pressed['S']) { camera.moveDown(MOVE_SPEED); } if (key_pressed['d'] || key_pressed['D']) { camera.moveRight(MOVE_SPEED); } if (key_pressed['h']) { Vector3 origin = Vector3::ZERO; Vector3 direction_to_origin; direction_to_origin = origin - camera.getPosition(); camera.rotateToVector(direction_to_origin, THETA); } if (key_pressed[','] || key_pressed['<']) { camera.setRoll(THETA); } if (key_pressed['.'] || key_pressed['>']) { camera.setRoll(-THETA); } if (key_pressed['/'] || key_pressed['?']) { camera.moveBackward(MOVE_SPEED); } if (special_key_pressed[GLUT_KEY_RIGHT]) { camera.setYaw(-THETA); } if (special_key_pressed[GLUT_KEY_LEFT]) { camera.setYaw(THETA); } if (special_key_pressed[GLUT_KEY_UP]) { camera.setPitch(THETA); } if (special_key_pressed[GLUT_KEY_DOWN]) { camera.setPitch(-THETA); } sleep(1.0 / 60.0); glutPostRedisplay(); }