123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #include "client/input/Controller.h"
- #include "client/rendering/Engine.h"
- Controller::Controller()
- : left(GLFW_KEY_A, "Left"), right(GLFW_KEY_D, "Right"), up(GLFW_KEY_W, "X"),
- down(GLFW_KEY_S, "Y"), jump(GLFW_KEY_SPACE, "L"),
- sneak(GLFW_KEY_LEFT_SHIFT, "R"), camLeft(GLFW_KEY_LEFT, "Start"),
- camRight(GLFW_KEY_RIGHT, "Select"), camUp(GLFW_KEY_UP, "Left"),
- camDown(GLFW_KEY_DOWN, "Right"),
- leftClick(GLFW_MOUSE_BUTTON_LEFT, "Left Click"),
- rightClick(GLFW_MOUSE_BUTTON_RIGHT, "Right Click") {
- }
- void Controller::init() {
- Buttons& b = Engine::getButtons();
- b.add(left);
- b.add(right);
- b.add(up);
- b.add(down);
- b.add(jump);
- b.add(sneak);
- b.add(camLeft);
- b.add(camRight);
- b.add(camUp);
- b.add(camDown);
- b.addMouse(leftClick);
- b.addMouse(rightClick);
- b.mapGamepadAxis(left, -0.5f, GLFW_GAMEPAD_AXIS_LEFT_X);
- b.mapGamepadAxis(right, 0.5f, GLFW_GAMEPAD_AXIS_LEFT_X);
- b.mapGamepadAxis(up, -0.5f, GLFW_GAMEPAD_AXIS_LEFT_Y);
- b.mapGamepadAxis(down, 0.5f, GLFW_GAMEPAD_AXIS_LEFT_Y);
- b.mapGamepadAxis(camUp, -0.5f, GLFW_GAMEPAD_AXIS_RIGHT_Y);
- b.mapGamepadAxis(camDown, 0.5f, GLFW_GAMEPAD_AXIS_RIGHT_Y);
- b.mapGamepadAxis(camLeft, -0.5f, GLFW_GAMEPAD_AXIS_RIGHT_X);
- b.mapGamepadAxis(camRight, 0.5f, GLFW_GAMEPAD_AXIS_RIGHT_X);
- }
- Vector2 Controller::getMouse() const {
- Buttons& b = Engine::getButtons();
- return Vector2(static_cast<float>(b.getMouseX()),
- static_cast<float>(b.getMouseY()));
- }
- Vector2 Controller::getMouseChange() const {
- Buttons& b = Engine::getButtons();
- return Vector2(static_cast<float>(b.getMouseX() - b.getLastMouseX()),
- static_cast<float>(b.getMouseY() - b.getLastMouseY()));
- }
|