Exemplo n.º 1
0
  public void input() {
    float sensitivity = 0.5f;
    float movAmt = (float) (10 * Time.getDelta());
    //		float rotAmt = (float)(100 * Time.getDelta());

    if (Input.getKey(GLFW.GLFW_KEY_ESCAPE)) {
      Input.showCursor(true);
      mouseLocked = false;
    }
    if (Input.getMouseDown(0)) {
      Input.setMousePosition(Window.getCenterPoint());
      Input.showCursor(false);
      mouseLocked = true;
    }

    if (Input.getKey(GLFW.GLFW_KEY_W)) move(getForward(), movAmt);
    if (Input.getKey(GLFW.GLFW_KEY_S)) move(getForward(), -movAmt);
    if (Input.getKey(GLFW.GLFW_KEY_A)) move(getLeft(), movAmt);
    if (Input.getKey(GLFW.GLFW_KEY_D)) move(getRight(), movAmt);

    if (mouseLocked) {
      Vector2f deltaPos = Input.getMousePosition().sub(Window.getCenterPoint());

      boolean rotY = deltaPos.getX() != 0;
      boolean rotX = deltaPos.getY() != 0;

      if (rotY) rotateY(deltaPos.getX() * sensitivity);
      if (rotX) rotateX(-deltaPos.getY() * sensitivity);

      if (rotY || rotX)
        Input.setMousePosition(new Vector2f(Window.getWidth() / 2, Window.getHeight() / 2));
    }
  }