lookingAt method

FreeCameraOptions lookingAt(
  1. Point target, {
  2. double altitude = 0,
  3. FreeCameraPosition up = const FreeCameraPosition(x: 0, y: 0, z: 1),
})

Returns options with the camera turned to look at target. The position does not change.

altitude is the altitude of the target in meters. The helper does not read terrain, so to look at the ground on terrain, pass the elevation of the target.

up is the up direction of the camera, as a vector in mercator coordinates. Its length has no effect. Use it when the view direction alone does not give a bearing, for example when the camera looks straight down. The default points straight up. An up that points down is flipped to point up.

The orientation of the result is null if FreeCameraOptions.position is null, or if no orientation with only a pitch and a bearing can look at target.

Implementation

FreeCameraOptions lookingAt(
  Point target, {
  double altitude = 0,
  FreeCameraPosition up = const FreeCameraPosition(x: 0, y: 0, z: 1),
}) {
  final position = this.position;
  if (position == null) {
    return const FreeCameraOptions();
  }

  final targetPosition = _toMercator(target, altitude);
  final forward = (
    x: targetPosition.x - position.x,
    y: targetPosition.y - position.y,
    z: targetPosition.z - position.z,
  );

  return FreeCameraOptions(
    position: position,
    orientation: _orientationFromFrame(forward, (
      x: up.x,
      y: up.y,
      z: up.z.abs(),
    )),
  );
}