copyWithViewport method

Camera copyWithViewport({
  1. required double newWidth,
  2. required double newHeight,
})

Returns a new camera that preserves the current horizontal FOV while changing the viewport size.

Implementation

Camera copyWithViewport({
  required double newWidth,
  required double newHeight,
}) {
  final currentHFovDeg = 2 * math.atan((width / 2) / fx) * (180 / math.pi);
  final newFx = _focalPixels(newWidth, currentHFovDeg);
  final newFy = newFx; // square pixels
  return copyWith(
    width: newWidth.toInt(),
    height: newHeight.toInt(),
    fx: newFx,
    fy: newFy,
  );
}