示例#1
0
  @Override
  public void update(float interval, MouseInput mouseInput) {
    // Update camera based on mouse
    if (mouseInput.isRightButtonPressed()) {
      Vector2f rotVec = mouseInput.getDisplVec();
      camera.moveRotation(rotVec.x * MOUSE_SENSITIVITY, rotVec.y * MOUSE_SENSITIVITY, 0);
    }

    // Update camera position
    Vector3f prevPos = new Vector3f(camera.getPosition());
    camera.movePosition(
        cameraInc.x * CAMERA_POS_STEP,
        cameraInc.y * CAMERA_POS_STEP,
        cameraInc.z * CAMERA_POS_STEP);
    // Check if there has been a collision. If true, set the y position to
    // the maximum height
    float height = terrain != null ? terrain.getHeight(camera.getPosition()) : -Float.MAX_VALUE;
    if (camera.getPosition().y <= height) {
      camera.setPosition(prevPos.x, prevPos.y, prevPos.z);
    }

    lightAngle += angleInc;
    if (lightAngle < 0) {
      lightAngle = 0;
    } else if (lightAngle > 180) {
      lightAngle = 180;
    }
    float zValue = (float) Math.cos(Math.toRadians(lightAngle));
    float yValue = (float) Math.sin(Math.toRadians(lightAngle));
    Vector3f lightDirection = this.scene.getSceneLight().getDirectionalLight().getDirection();
    lightDirection.x = 0;
    lightDirection.y = yValue;
    lightDirection.z = zValue;
    lightDirection.normalize();
  }