withUpdatedViewport method

GaussianCamera withUpdatedViewport({
  1. required double newWidth,
  2. required double newHeight,
})

Creates a new camera with updated dimensions while preserving FOV.

This method maintains the current horizontal field of view when changing the viewport dimensions, recalculating focal lengths accordingly.

Parameters:

  • newWidth: New image width in pixels
  • newHeight: New image height in pixels

Returns a new GaussianCamera with updated dimensions.

Implementation

GaussianCamera withUpdatedViewport({
  required double newWidth,
  required double newHeight,
}) {
  // Calculate current horizontal FOV
  final currentHorizontalFov =
      2 * math.atan((width / 2) / fx) * (180 / math.pi);

  // Calculate new focal lengths based on preserved FOV
  final newFx = _focalPixels(newWidth, currentHorizontalFov);
  final newFy = newFx; // Keep square pixels

  return GaussianCamera(
    id: id,
    width: newWidth.toInt(),
    height: newHeight.toInt(),
    position: position,
    rotation: rotation,
    fx: newFx,
    fy: newFy,
  );
}