Ejemplo n.º 1
0
  private void calculateCameraPosition(float horizontalDistance, float verticalDistance) {

    float theta = player.getRotY() + angleAroundPlayer;
    float offsetX = (float) (horizontalDistance * Math.sin(Math.toRadians(theta)));
    float offsetZ = (float) (horizontalDistance * Math.cos(Math.toRadians(theta)));
    position.x = player.getPosition().x - offsetX;
    position.z = player.getPosition().z - offsetZ;
    position.y = player.getPosition().y + 1 + verticalDistance;

    yaw = 180.0f - theta;
  }
Ejemplo n.º 2
0
 private void prepareInstance(Entity entity) {
   Matrix4f transformationMatrix =
       Maths.createTransformationMatrix(
           entity.getPosition(),
           entity.getRotX(),
           entity.getRotY(),
           entity.getRotZ(),
           entity.getScale());
   shader.loadTransformationMatrix(transformationMatrix);
   shader.loadOffset(entity.getTextureXOffset(), entity.getTextureYOffset());
 }
Ejemplo n.º 3
0
  public void move() {
    if (cameraMode == CameraMode.OVERHEAD) {
      if (KeyboardHelper.isKeyDown(Keyboard.KEY_LEFT)) {
        this.position.x -= OVERHEAD_CAMERA_MOVE_SPEED * DisplayManager.getFrameTimeSeconds();
      }
      if (KeyboardHelper.isKeyDown(Keyboard.KEY_RIGHT)) {
        this.position.x += OVERHEAD_CAMERA_MOVE_SPEED * DisplayManager.getFrameTimeSeconds();
      }
      if (KeyboardHelper.isKeyDown(Keyboard.KEY_UP)) {
        this.position.z -= OVERHEAD_CAMERA_MOVE_SPEED * DisplayManager.getFrameTimeSeconds();
      }
      if (KeyboardHelper.isKeyDown(Keyboard.KEY_DOWN)) {
        this.position.z += OVERHEAD_CAMERA_MOVE_SPEED * DisplayManager.getFrameTimeSeconds();
      }

      this.yaw = 0;
      this.pitch = 70;
      this.position.y = world.getTerrain().getTerrainHeight(position.x, position.z) + cameraHeight;

    } else if (cameraMode == CameraMode.FIRST_PERSON) {
      Vector3f viewPos = player.getHardpointWorldPos("HP_VIEW");
      if (viewPos == null) viewPos = player.getPosition();

      this.position.x = viewPos.x;
      this.position.y = viewPos.y;
      this.position.z = viewPos.z;
      this.pitch = player.rotX;
      this.yaw = 180.0f - player.rotY;
    } else if (cameraMode == CameraMode.THIRD_PERSON) {
      calculateZoom();
      calculatePitch();
      calculateAngleAroundPlayer();

      float horizontalDistance = calculateHorizontalDistance();
      float verticalDistance = calculateVerticalDistance();
      calculateCameraPosition(horizontalDistance, verticalDistance);
    }
  }