GaussianCamera.createDefault constructor

GaussianCamera.createDefault({
  1. required double width,
  2. required double height,
  3. double horizontalFovDegrees = 45.0,
  4. Vector3? position,
  5. Matrix3? rotation,
  6. int id = 0,
})

Creates a default camera with reasonable FOV-based parameters.

This factory constructor provides defaults,

Parameters:

  • width: Image width in pixels
  • height: Image height in pixels
  • horizontalFovDegrees: Horizontal field of view in deg (default: 45°)
  • position: Camera position in world space (default: from orbit)
  • rotation: Camera rotation matrix (default: from orbit)
  • id: Camera identifier (default: 0)

Implementation

factory GaussianCamera.createDefault({
  required double width,
  required double height,
  double horizontalFovDegrees = 45.0,
  Vector3? position,
  Matrix3? rotation,
  int id = 0,
}) {
  final fx = _focalPixels(width, horizontalFovDegrees);
  final fy = fx; // Square pixels - keep them equal

  // If position/rotation not provided, calculate using orbit camera logic
  Vector3 finalPosition;
  Matrix3 finalRotation;

  if (position != null && rotation != null) {
    finalPosition = position;
    finalRotation = rotation;
  } else {
    // Use same initial values as widget: distance=5, theta=0, phi=π/2
    const orbitDistance = 2.0;
    const double theta = 0;
    const phi = math.pi / 2.0;

    // Calculate position using spherical coordinates (matching widget)
    final x = orbitDistance * math.sin(phi) * math.sin(theta);
    final y = orbitDistance * math.cos(phi);
    final z = orbitDistance * math.sin(phi) * math.cos(theta);
    finalPosition = Vector3(x, y, z);

    // Calculate rotation using same logic as widget's _orbitCamera
    final forward = (-finalPosition).normalized();
    final up = Vector3(0, -1, 0);  // Match widget's up vector
    final right = up.cross(forward).normalized();
    final trueUp = forward.cross(right).normalized();
    finalRotation = Matrix3.columns(right, trueUp, forward);
  }

  return GaussianCamera(
    id: id,
    width: width.toInt(),
    height: height.toInt(),
    position: finalPosition,
    rotation: finalRotation,
    fx: fx,
    fy: fy,
  );
}