mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
The application shell keeps the page's globe engine and hands it to the navigation controller, location navigation (search, city and POI flights, orbit, globe reset), the tilt and north-up controls, share-link save and restore, share restoration's first-gesture listeners and the HUD. The viewer is passed only where entity tracking still lives on it (phase 1c) and to the HUD's basemap label context (voice); every such use is null-safe. Share links and captured shots write heading and roll as Cesium's camera reports them (src/cameraAngles.js): the contract's [0, 2π) pose maps an exact 0 back to Cesium's 2π, except the roll of a vertical view, so links stay byte-identical (heading=360, roll=360) on every engine. Source-reading tests follow the moved code with the same checks.
33 lines
1.5 KiB
JavaScript
33 lines
1.5 KiB
JavaScript
// Camera heading and roll as Cesium's camera reports them, from an engine pose.
|
|
//
|
|
// The globe contract keeps pose angles in [0, 2π) (src/globe/contract.js).
|
|
// Cesium's own Camera.heading and .roll lie in (0, 2π]: a view facing exactly
|
|
// north reports heading 2π, a level view reports roll 2π, and roll is exactly
|
|
// 0 only in Cesium's vertical branch (looking within 1e-3 of straight up or
|
|
// down). Share links and captured scene shots have always carried Cesium's
|
|
// numbers (`heading=360`, `roll=360`), so they are written from these, and a
|
|
// link or shot made on any engine reads as one made on Cesium. The contract
|
|
// folds Cesium's values within 1e-12 of 0 and 2π onto 0; a reading that was a
|
|
// hair above 0 therefore comes back as 2π here, the only case that differs.
|
|
|
|
import * as geo from './geo/index.js';
|
|
|
|
const { TWO_PI } = geo.math;
|
|
|
|
/** Whether a pose looks (nearly, within 1e-3) straight up or down, as Cesium tests it. */
|
|
export function poseIsVertical({ position, direction }) {
|
|
const up = geo.ellipsoid.WGS84.geodeticSurfaceNormal(
|
|
position,
|
|
geo.cartesian3.create(),
|
|
);
|
|
return Math.abs(1 - Math.abs(geo.cartesian3.dot(direction, up))) <= 1e-3;
|
|
}
|
|
|
|
/** The pose heading as Cesium reports it, in (0, 2π]. */
|
|
export const cesiumHeading = (pose) =>
|
|
pose.heading === 0 ? TWO_PI : pose.heading;
|
|
|
|
/** The pose roll as Cesium reports it: (0, 2π], or exactly 0 for a vertical view. */
|
|
export const cesiumRoll = (pose) =>
|
|
pose.roll === 0 && !poseIsVertical(pose) ? TWO_PI : pose.roll;
|