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));
    }
  }
Exemplo n.º 2
0
  @Override
  public void run() {
    init();

    int fps = 0;
    long frameCounter = 0;

    long lastTime = Time.getTime();
    float unproccessedTime = 0;

    while (!Window.isCloseRequested()) {
      boolean render = false;

      long startTime = Time.getTime();
      long passed = startTime - lastTime;
      lastTime = startTime;

      unproccessedTime += passed / (float) Time.SECOND;
      frameCounter += passed;

      while (unproccessedTime > frameTime) {
        render = true;

        unproccessedTime -= frameTime;

        Time.setDelta((float) frameTime);

        game.fixedUpdate();
        renderingEngine.fixedUpdate();

        if (frameCounter >= Time.SECOND) {
          System.out.println(fps);
          fps = 0;
          frameCounter = 0;
        }

        update();
      }

      if (render) {
        renderingEngine.render(game.getRootObject());
        Window.render();
        fps++;
      } else {
        try {
          Thread.sleep(1);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }
Exemplo n.º 3
0
  private void init() {
    try {
      Window.createWindow(width, height, title);
    } catch (Exception e) {
      e.printStackTrace();
    }

    this.renderingEngine = new RenderingEngine();

    game.init();
  }