Controller.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  1. #include "client/input/Controller.h"
  2. Controller::Controller(Buttons& b)
  3. : buttons(b), list(b.get()), left(b.add(GLFW_KEY_A, "Left")),
  4. right(b.add(GLFW_KEY_D, "Right")), up(b.add(GLFW_KEY_W, "X")),
  5. down(b.add(GLFW_KEY_S, "Y")), jump(b.add(GLFW_KEY_SPACE, "L")),
  6. sneak(b.add(GLFW_KEY_LEFT_SHIFT, "R")),
  7. camLeft(b.add(GLFW_KEY_LEFT, "Start")),
  8. camRight(b.add(GLFW_KEY_RIGHT, "Select")),
  9. camUp(b.add(GLFW_KEY_UP, "Left")), camDown(b.add(GLFW_KEY_DOWN, "Right")),
  10. mouseList(b.getMouse()),
  11. leftClick(b.addMouse(GLFW_MOUSE_BUTTON_LEFT, "Left Click")),
  12. rightClick(b.addMouse(GLFW_MOUSE_BUTTON_RIGHT, "Right Click")) {
  13. b.mapGamepadAxis(left, -0.5f, GLFW_GAMEPAD_AXIS_LEFT_X);
  14. b.mapGamepadAxis(right, 0.5f, GLFW_GAMEPAD_AXIS_LEFT_X);
  15. b.mapGamepadAxis(up, -0.5f, GLFW_GAMEPAD_AXIS_LEFT_Y);
  16. b.mapGamepadAxis(down, 0.5f, GLFW_GAMEPAD_AXIS_LEFT_Y);
  17. b.mapGamepadAxis(camUp, -0.5f, GLFW_GAMEPAD_AXIS_RIGHT_Y);
  18. b.mapGamepadAxis(camDown, 0.5f, GLFW_GAMEPAD_AXIS_RIGHT_Y);
  19. b.mapGamepadAxis(camLeft, -0.5f, GLFW_GAMEPAD_AXIS_RIGHT_X);
  20. b.mapGamepadAxis(camRight, 0.5f, GLFW_GAMEPAD_AXIS_RIGHT_X);
  21. }
  22. Vector2 Controller::getMouse() const {
  23. return Vector2(static_cast<float>(buttons.getMouseX()),
  24. static_cast<float>(buttons.getMouseY()));
  25. }
  26. Vector2 Controller::getMouseChange() const {
  27. return Vector2(
  28. static_cast<float>(buttons.getMouseX() - buttons.getLastMouseX()),
  29. static_cast<float>(buttons.getMouseY() - buttons.getLastMouseY()));
  30. }