mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
The camera ground guard reads the eye from the camera port's pose, the flight state from the port, and the surface under it from the query port's heights, and lifts through the port. Place and landmark flights read the terrain height from the query port and build their targets with geo. Framing ranges read the field of view from the pose (the frustum's wider-side angle, as it read before). An imported file's flight frames its footprint, plain lon/lat/height points, with geo's bounding sphere and the port's flyToBounds; walking the file's Cesium data source for those points moves into the file importer, which stays on the Cesium allow-list. The Cesium query port answers terrain heights without depth textures, as the height service always has: only the drawn surface needs them. cameraGroundGuard, locations, cameraFraming and flyToDataSource leave the allow-list. The annotation resolver, still listed, loads the camera factory for the application operations entry, which reached it through locations before.
35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
import { toRadians } from '../geo/index.js';
|
|
import { findCamera } from '../render/rendererOf.js';
|
|
|
|
/** The camera port's pose, or null when there is none to read. */
|
|
function poseOf(viewer) {
|
|
try {
|
|
return findCamera(viewer)?.pose() ?? null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/** Camera range with breathing room in both viewport dimensions. */
|
|
export function rangeForBoundingSphere(viewer, radius) {
|
|
const pose = poseOf(viewer);
|
|
const fovy = Number(pose?.fovy);
|
|
const aspect = Number(pose?.aspectRatio);
|
|
// The frustum's field of view: along its wider side.
|
|
const fov =
|
|
fovy > 0 && aspect > 1
|
|
? 2 * Math.atan(Math.tan(fovy / 2) * aspect)
|
|
: fovy > 0
|
|
? fovy
|
|
: NaN;
|
|
const verticalFov = fov || toRadians(60);
|
|
const aspectRatio = Math.max(0.5, aspect || 1);
|
|
const horizontalFov = 2 * Math.atan(Math.tan(verticalFov / 2) * aspectRatio);
|
|
const limitingFov = Math.min(verticalFov, horizontalFov);
|
|
// Target 57% sphere occupancy so perspective still leaves at least 40%
|
|
// measured roof-to-base breathing room in ordinary oblique building views.
|
|
const occupiedViewportFraction = 0.57;
|
|
const desiredAngularRadius = (limitingFov * occupiedViewportFraction) / 2;
|
|
return (radius / Math.sin(desiredAngularRadius)) * 1.05;
|
|
}
|