All files / components/screens/combat/helpers combatCameraFraming.ts

100% Statements 4/4
100% Branches 2/2
100% Functions 1/1
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19                  267x 267x 267x 267x            
export type WorldPoint = readonly [number, number, number];
 
/** Fits both fighters inside the part of the screen not occupied by the HUD. */
export function getCombatFraming(
  first: WorldPoint,
  second: WorldPoint,
  aspect: number,
  fov: number,
): { readonly x: number; readonly z: number; readonly distance: number } {
  const horizontalFov = Math.tan(fov * Math.PI / 360) * Math.max(aspect, 0.01);
  const halfWidth = Math.abs(first[0] - second[0]) * 0.5 + 0.95;
  const halfDepth = Math.abs(first[2] - second[2]) * 0.5;
  return {
    x: (first[0] + second[0]) * 0.5,
    z: (first[2] + second[2]) * 0.5,
    distance: Math.max(4.5, halfWidth / (horizontalFov * (aspect < 1 ? 0.86 : 0.65))) + halfDepth,
  };
}