Files
gods-eye-view/src/data/trackedCamera.js
T
Sameh Khamis e3a850bc9c Follow aircraft and satellites through the camera port
Flights and military follow their tracked aircraft with an
entityFollowTarget: framed in ENU from viewFrom, never closer than
150 m, presentation read from the drawn entity's record. Satellites
follow in Cesium's autodetect frame. The layers' own framing
(applyTrackedCameraFrame) goes; the port's follow has the same
close-range rules, and trackedCamera.js no longer imports Cesium.

The port's helper entity draws nothing: its point's outline is
transparent too, and click and voice picks of it count as picks of
the target's drawn entity. The fake camera binder follows when the
fake has Cesium's entity tracking.
2026-11-06 16:10:48 -08:00

49 lines
1.6 KiB
JavaScript

/**
* Closest a follow camera comes to a tracked aircraft, metres: the camera
* port's `minRange` for the aircraft layers' FollowTargets.
*/
export const FOLLOW_MIN_RANGE_M = 150;
/**
* Preserve real-world model scale except when a very close tracked camera
* would make the selected aircraft dominate the viewport.
*
* @param {object} options
* @param {number} options.baseScale Asset's calibrated real-world scale.
* @param {number} options.nativeRadiusM Asset bounding radius before scale.
* @param {number} options.rangeM Camera-to-aircraft range.
* @param {number} options.viewportHeightPx Rendered viewport height.
* @param {number} options.fovyRad Vertical field of view.
* @param {number} options.maximumPixelSize Maximum selected-model diameter.
* @returns {number} Scale to apply to the model.
*/
export function trackedModelScaleForPixelCap({
baseScale,
nativeRadiusM,
rangeM,
viewportHeightPx,
fovyRad,
maximumPixelSize,
}) {
if (
!Number.isFinite(baseScale) ||
baseScale <= 0 ||
!Number.isFinite(nativeRadiusM) ||
nativeRadiusM <= 0 ||
!Number.isFinite(rangeM) ||
rangeM <= 0 ||
!Number.isFinite(viewportHeightPx) ||
viewportHeightPx <= 0 ||
!Number.isFinite(fovyRad) ||
fovyRad <= 0 ||
!Number.isFinite(maximumPixelSize) ||
maximumPixelSize <= 0
)
return baseScale;
const focalLengthPx = viewportHeightPx / (2 * Math.tan(fovyRad / 2));
const projectedDiameterPx =
(2 * nativeRadiusM * baseScale * focalLengthPx) / rangeM;
if (projectedDiameterPx <= maximumPixelSize) return baseScale;
return baseScale * (maximumPixelSize / projectedDiameterPx);
}