mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Move the scene-reading icon orientation helpers into the Cesium adapter
screenProjectedRotation, perspectiveProjectedRotation, horizonOccluder and cameraPoseSignature read a Cesium scene or camera, so they move unchanged to src/render/cesium/iconOrientation.js, where the CCTV, radio and transit rendering (still Cesium-bound) load them. src/data/iconOrientation.js keeps the label backdrop test and the rotation deadband, and leaves the Cesium allow-list. Local ADS-B computes its rotation from the camera port's axes with courseScreenRotation directly, the same answer without a stand-in scene. The ./aircraft package entry re-exports src/data/iconOrientation.js, so it no longer carries the four moved helpers or the PERSPECTIVE_* constants.
This commit is contained in:
1 parent
d8d6db4389
commit
b6e94b8d93
14 files changed
+224
-206
No files matched your search
@@ -542,7 +542,7 @@ src/
|
||||
├── voice/ # OpenAI Realtime session + 30 voice tools
|
||||
├── layers/ # Layer components — weather, wind, cyclones, transit, ALPR, …
|
||||
├── data/ # One module per layer + orchestration + context store
|
||||
│ ├── iconOrientation.js # Screen-projected headings + horizon cull
|
||||
│ ├── iconOrientation.js # Horizon backdrop for labels (headings: screenRotation.js)
|
||||
│ └── local_data/ # Bundled datasets (per-folder provenance)
|
||||
└── scenes/ # Cinematic scene director
|
||||
```
|
||||
|
||||
@@ -5028,7 +5028,7 @@ silently demoting every later lookup for the session.
|
||||
### Motion & Symbology Correctness (June 10, 2026)
|
||||
|
||||
- **Flights (commercial + military)** render one poll interval behind real time (30s/15s) and interpolate between two known feed-stamped fixes (OpenSky `time_position`; adsb.lol `receipt − seen_pos`). The display latency is an intentional product decision — do not "fix" it away. The whole fleet dead-reckons at ~12Hz (1m² write gating); aircraft get a 3-poll grace period (faded icon) before removal. When a position epoch pauses, both layers coast for at least 60 seconds of contact grace with an absolute five-minute ceiling. Source backoff marks each contact and the cockpit `STALE`; the cockpit then holds the exact layer position instead of continuing inertial flight. Repeated-position kinematic changes create a forward-only synthetic fix rather than mutating history, and grounded history is lifted only when no owned 3D model already controls its datum. A nominally successful worldwide OpenSky response whose own snapshot epoch is more than two minutes old prefers the existing 250-nm viewport-scoped adsb.lol fallback and labels the source/coverage accordingly when that upstream is available. If the fallback is also unavailable, the layer's freshness/error fields use the source epoch—never the cache receipt time—so the UI reports an old snapshot rather than “just now.”
|
||||
- **World-space headings at every angle** (`src/data/iconOrientation.js`): aircraft/vessel icon rotation uses the camera right/up basis per tick (alignedAxis always ZERO), which is exact at screen center and for orthographic/nadir views and remains stable through >180° tracked orbits. Perspective rays vary across the viewport, so off-center contacts at oblique pitch can diverge from an exact finite-difference window projection; a regression test pins that known regime, and field evidence decides whether to adopt exact projection with the basis method as fallback. Fleet rotations refresh on camera-pose change; tracked entities per frame. Billboards are horizon-culled via a shared EllipsoidalOccluder.
|
||||
- **World-space headings at every angle** (`src/data/screenRotation.js`; the scene-reading helpers in `src/render/cesium/iconOrientation.js`): aircraft/vessel icon rotation uses the camera right/up basis per tick (alignedAxis always ZERO), which is exact at screen center and for orthographic/nadir views and remains stable through >180° tracked orbits. Perspective rays vary across the viewport, so off-center contacts at oblique pitch can diverge from an exact finite-difference window projection; a regression test pins that known regime, and field evidence decides whether to adopt exact projection with the basis method as fallback. Fleet rotations refresh on camera-pose change; tracked entities per frame. Billboards are horizon-culled via a shared EllipsoidalOccluder.
|
||||
- **Military/OpenSky reconciliation** (`src/data/militaryRegistry.js`): known-military ICAOs render amber in the flights layer (60s self-poll of the cached mil endpoint when the military layer is off) and are suppressed there while the military layer renders them.
|
||||
- **Satellites**: 838-sat core catalog (stations/visual/GPS/GLONASS/Galileo/GEO), tracking lands ~726km out via `viewFrom` (tracked entity owns a point graphic so the tracking camera engages), rings realign via primitive modelMatrix (no per-second rebuild flicker), optional `setParams({catalog:'dense'})` Starlink mode.
|
||||
- **Satellite classes** (`src/data/satelliteClass.js`): every satellite is classified from the CelesTrak group it was ingested with — no extra fetch and no heuristics — into STATION (warm white), NAV (cyan; GPS/GLONASS/Galileo deliberately share one color so the GNSS family reads as one thing), GEO (violet), VISUAL (muted blue-gray catch-all), and COMMS (dim slate, dense Starlink shell only). That module is the single source of truth for class, label, and color, so the dot, the card, and the legend swatch cannot disagree. Two deliberate palette rules: no class may sit in the 40–48° amber band, which is the app-wide known-military convention; and COMMS stays far below VISUAL in Rec.601 luminance so the dense shell stays separable when NVG/FLIR collapse the scene to one channel. The ISS keeps its long-standing red hero dot rather than the STATION color — it carries a permanent name label and its card still reads `STATION · ISS`. `satelliteClassOf` is the single owner of that ISS rule, so the card label and the legend tally can never disagree: during a stations-feed outage the ISS is ingested as `visual`, and both surfaces still file it under STATION.
|
||||
|
||||
@@ -2539,6 +2539,7 @@
|
||||
"src/layers/cctv/projection.js",
|
||||
"src/layers/cctv/videoPlayback.js",
|
||||
"src/layers/cctv/rendering.js",
|
||||
"src/render/cesium/iconOrientation.js",
|
||||
"src/render/cesium/iconSetPrimitive.js",
|
||||
"src/data/iconSet.js",
|
||||
"src/geo/horizon.js",
|
||||
@@ -2827,6 +2828,7 @@
|
||||
"src/layers/radio/presentation.js",
|
||||
"src/layers/radio/queries.js",
|
||||
"src/layers/radio/rendering.js",
|
||||
"src/render/cesium/iconOrientation.js",
|
||||
"src/layers/radio/selection.js",
|
||||
"src/layers/radio/source.js",
|
||||
"src/layers/radio/state.js",
|
||||
@@ -3286,6 +3288,7 @@
|
||||
"src/layers/wind/source.js",
|
||||
"src/sources/windBody.js",
|
||||
"src/data/detection.js",
|
||||
"src/render/cesium/iconOrientation.js",
|
||||
"src/data/detectionCohort.js",
|
||||
"src/data/detectionDraw.js",
|
||||
"src/data/detectionPolicy.js",
|
||||
@@ -4406,6 +4409,7 @@
|
||||
"src/layers/cctv/projection.js",
|
||||
"src/layers/cctv/videoPlayback.js",
|
||||
"src/layers/cctv/rendering.js",
|
||||
"src/render/cesium/iconOrientation.js",
|
||||
"src/layers/cctv/selection.js",
|
||||
"src/layers/cctv/pickState.js",
|
||||
"src/layers/cctv/source.js",
|
||||
@@ -5636,6 +5640,7 @@
|
||||
"src/layers/transit/qaMetrics.js",
|
||||
"src/layers/transit/queries.js",
|
||||
"src/layers/transit/rendering.js",
|
||||
"src/render/cesium/iconOrientation.js",
|
||||
"src/layers/transit/selection.js",
|
||||
"src/layers/transit/state.js",
|
||||
"src/layers/transit/testing.js",
|
||||
@@ -5705,6 +5710,7 @@
|
||||
"src/layers/transit/policy.js",
|
||||
"src/layers/transit/queries.js",
|
||||
"src/layers/transit/rendering.js",
|
||||
"src/render/cesium/iconOrientation.js",
|
||||
"src/layers/transit/selection.js",
|
||||
"src/geo/index.js",
|
||||
"src/geo/julian.js",
|
||||
|
||||
@@ -2796,7 +2796,7 @@ async function main() {
|
||||
const arrival = await evalPage(async () => {
|
||||
const v = window.__godsEyeView.viewer;
|
||||
const dm = window.__godsEyeView.dataManager;
|
||||
const { screenProjectedRotation } = await import(`${window.__gevQaSourceBase || '/src'}/data/iconOrientation.js`);
|
||||
const { screenProjectedRotation } = await import(`${window.__gevQaSourceBase || '/src'}/render/cesium/iconOrientation.js`);
|
||||
const { observeArrivalRotationWithRetry } = await import(`${window.__gevQaSourceBase || '/src'}/tooling/trackArrivalObservation.mjs`);
|
||||
// 3D models OFF for this phase: a model-handed-off icon is hidden, and
|
||||
// the probes need shown icons (this is also the app's default state the
|
||||
|
||||
+9
-187
@@ -2,7 +2,11 @@
|
||||
* Shared icon-orientation + horizon helpers. Orientation and culling serve the
|
||||
* moving-entity layers (commercial flights, military flights, AIS vessels);
|
||||
* `skyBackdropFactor` serves the detection overlay, which needs the same
|
||||
* silhouette geometry to know what a label is being read against.
|
||||
* silhouette geometry to know what a label is being read against. The helpers
|
||||
* that read the default renderer's scene or camera (`screenProjectedRotation`,
|
||||
* `perspectiveProjectedRotation`, `horizonOccluder`, `cameraPoseSignature`)
|
||||
* live in `src/render/cesium/iconOrientation.js`; the camera-basis rotation
|
||||
* itself is `courseScreenRotation` in `screenRotation.js`.
|
||||
*
|
||||
* THE ORIENTATION PROBLEM (2026-06-10 playtest): billboards are camera-facing
|
||||
* quads, so "point along the real-world course" must be computed in SCREEN
|
||||
@@ -21,52 +25,11 @@
|
||||
* keeps rotation continuous through tracked orbits; field evidence, not an
|
||||
* unverified math swap, decides whether exact projection becomes preferred.
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
import { poseSignature } from '../render/camera/poseSignature.js';
|
||||
import {
|
||||
courseScreenRotation,
|
||||
stabilizeScreenRotation,
|
||||
} from './screenRotation.js';
|
||||
|
||||
const _scratchEnu = new Cesium.Matrix4();
|
||||
const _scratchForward = new Cesium.Cartesian3();
|
||||
const _scratchWorldForward = new Cesium.Cartesian3();
|
||||
|
||||
/**
|
||||
* Computes the billboard rotation (radians, CCW-positive, for
|
||||
* alignedAxis = Cartesian3.ZERO) that points an icon along its real-world
|
||||
* course in the stable camera-basis approximation described above; the
|
||||
* scene's camera axes in `screenRotation.js`'s `courseScreenRotation`.
|
||||
*
|
||||
* @param {Cesium.Scene} scene - The scene (projection source).
|
||||
* @param {Cesium.Cartesian3} position - Entity world position.
|
||||
* @param {number} courseDeg - Course/track in degrees clockwise from north.
|
||||
* @param {number|null} previous - Rotation to keep when projection is
|
||||
* unavailable (off-screen/behind camera/degenerate).
|
||||
* @returns {number|null} Rotation in radians, or `previous` when unknown.
|
||||
*/
|
||||
export function screenProjectedRotation(
|
||||
scene,
|
||||
position,
|
||||
courseDeg,
|
||||
previous = null,
|
||||
) {
|
||||
const camera = scene?.camera;
|
||||
return courseScreenRotation(
|
||||
camera && { right: camera.rightWC, up: camera.upWC },
|
||||
position,
|
||||
courseDeg,
|
||||
previous,
|
||||
);
|
||||
}
|
||||
import { WGS84 } from '../geo/ellipsoid.js';
|
||||
import { stabilizeScreenRotation } from './screenRotation.js';
|
||||
|
||||
export { stabilizeScreenRotation };
|
||||
|
||||
const _occluder = new Cesium.EllipsoidalOccluder(
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
|
||||
/**
|
||||
* Half-width of the crossfade band centred on the ellipsoid silhouette, in
|
||||
* radians. ~1.1° per side: at the product's default 60° frustum on a 1280×800
|
||||
@@ -76,7 +39,7 @@ const _occluder = new Cesium.EllipsoidalOccluder(
|
||||
*/
|
||||
export const HORIZON_FEATHER_RAD = 0.019;
|
||||
|
||||
const _wgs84OneOverRadii = Cesium.Ellipsoid.WGS84.oneOverRadii;
|
||||
const _wgs84OneOverRadii = WGS84.oneOverRadii;
|
||||
|
||||
/**
|
||||
* How much SKY sits behind a world point from this camera: 0 (planet behind)
|
||||
@@ -88,7 +51,7 @@ const _wgs84OneOverRadii = Cesium.Ellipsoid.WGS84.oneOverRadii;
|
||||
* ABOVE the ellipsoid the horizon is the tangent silhouette and the test is a
|
||||
* genuine ray/ellipsoid hit test: 1 means the view ray through the point misses
|
||||
* the planet entirely. Here the function is the exact complement of
|
||||
* {@link horizonOccluder} — the occluder asks whether the planet is in FRONT of
|
||||
* `horizonOccluder` (`src/render/cesium/iconOrientation.js`) — the occluder asks whether the planet is in FRONT of
|
||||
* a point (cull it), this asks whether it is BEHIND (what a screen-space label
|
||||
* anchored there is read against). For any point the occluder keeps, a ray that
|
||||
* hits the ellipsoid must hit it beyond the point, so the hit/miss test alone
|
||||
@@ -182,144 +145,3 @@ export function skyBackdropFactor(
|
||||
// than steps, and the fade has no visible corner at either edge of the band.
|
||||
return t * t * (3 - 2 * t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared horizon occluder, updated to the camera's position.
|
||||
* With the Cesium globe hidden (Google 3D tiles provide the planet) nothing
|
||||
* writes far-side depth, so billboards must be horizon-culled manually.
|
||||
* Call once per tick, then test points with occluder.isPointVisible(pos).
|
||||
*
|
||||
* @param {Cesium.Camera} camera - The scene camera.
|
||||
* @returns {Cesium.EllipsoidalOccluder}
|
||||
*/
|
||||
export function horizonOccluder(camera) {
|
||||
_occluder.cameraPosition = camera.positionWC;
|
||||
return _occluder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cheap camera pose signature for "did the camera move" gating of rotation
|
||||
* passes (position quantized to ~10m, angles to ~0.06 deg).
|
||||
* @param {Cesium.Camera} camera - The scene camera.
|
||||
* @returns {string}
|
||||
*/
|
||||
export function cameraPoseSignature(camera) {
|
||||
return poseSignature({
|
||||
position: camera.positionWC,
|
||||
heading: camera.heading,
|
||||
pitch: camera.pitch,
|
||||
roll: camera.roll,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Meters ahead used by the exact projection below. Short on purpose: the point
|
||||
* of a perspective projection is that it is LOCAL to the contact, and a two
|
||||
* kilometre probe on a bus at six hundred metres would sample a part of the
|
||||
* frustum the vehicle is nowhere near.
|
||||
*/
|
||||
const NEAR_PROBE_M = 30;
|
||||
const _scratchProbe = new Cesium.Cartesian3();
|
||||
const _scratchWindowAt = new Cesium.Cartesian2();
|
||||
const _scratchWindowAhead = new Cesium.Cartesian2();
|
||||
|
||||
/**
|
||||
* Billboard rotation for a SURFACE contact, projected exactly — perspective
|
||||
* division included — instead of through the camera-basis approximation.
|
||||
*
|
||||
* `screenProjectedRotation` above deliberately projects the course vector onto
|
||||
* the camera's right/up basis, which is orthographic: exact at the viewport
|
||||
* centre and an approximation away from it. That is the right trade for
|
||||
* aircraft, where the alternative loses continuity through a tracked orbit and
|
||||
* the contacts are far enough away for the error to be small.
|
||||
*
|
||||
* It is the wrong trade for street-level vehicles. A probe with a real Cesium
|
||||
* camera at 600 m and −45° pitch, on a northbound contact 350 m right of
|
||||
* centre, put the orthographic answer at 0° where the true screen direction of
|
||||
* travel was 22.5°. At that pitch and that range the vehicles fill the frame
|
||||
* away from the centre, and every one of them points visibly wrong.
|
||||
*
|
||||
* So this projects two nearby world points through the actual view-projection
|
||||
* and reads the angle between them on screen. When either point cannot be
|
||||
* projected — behind the camera, off the frustum, degenerate — it falls back to
|
||||
* the camera-basis answer rather than inventing one.
|
||||
*
|
||||
* @param {Cesium.Scene} scene The scene (projection source).
|
||||
* @param {Cesium.Cartesian3} position Entity world position.
|
||||
* @param {number} courseDeg Course in degrees clockwise from north.
|
||||
* @param {number|null} previous Rotation to keep when projection is unavailable.
|
||||
* @returns {number|null} Rotation in radians, or the fallback.
|
||||
*/
|
||||
export function perspectiveProjectedRotation(
|
||||
scene,
|
||||
position,
|
||||
courseDeg,
|
||||
previous = null,
|
||||
) {
|
||||
if (!scene?.camera || !position || !Number.isFinite(courseDeg)) {
|
||||
return previous;
|
||||
}
|
||||
const courseRad = Cesium.Math.toRadians(courseDeg);
|
||||
Cesium.Cartesian3.fromElements(
|
||||
Math.sin(courseRad) * NEAR_PROBE_M,
|
||||
Math.cos(courseRad) * NEAR_PROBE_M,
|
||||
0,
|
||||
_scratchForward,
|
||||
);
|
||||
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(
|
||||
position,
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
_scratchEnu,
|
||||
);
|
||||
Cesium.Matrix4.multiplyByPointAsVector(
|
||||
enu,
|
||||
_scratchForward,
|
||||
_scratchWorldForward,
|
||||
);
|
||||
Cesium.Cartesian3.add(position, _scratchWorldForward, _scratchProbe);
|
||||
|
||||
const at = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
position,
|
||||
_scratchWindowAt,
|
||||
);
|
||||
const ahead = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
_scratchProbe,
|
||||
_scratchWindowAhead,
|
||||
);
|
||||
if (!at || !ahead) {
|
||||
return screenProjectedRotation(scene, position, courseDeg, previous);
|
||||
}
|
||||
const dx = ahead.x - at.x;
|
||||
const dy = ahead.y - at.y;
|
||||
const separation = Math.hypot(dx, dy);
|
||||
// Window y grows downward; rotation 0 = icon pointing screen-up.
|
||||
const exact = Math.atan2(-dx, -dy);
|
||||
if (separation >= PERSPECTIVE_BLEND_MAX_PX) return exact;
|
||||
// Below a pixel or so of separation the exact answer is dominated by
|
||||
// projection noise, and above it the camera-basis answer is the wrong one
|
||||
// by up to twenty-odd degrees. A hard cutoff between the two flipped a
|
||||
// sprite by 23° for a 20 m change of camera altitude; the two answers are
|
||||
// blended across the band instead, the short way round, so the rotation is
|
||||
// continuous through it.
|
||||
const basis = screenProjectedRotation(scene, position, courseDeg, previous);
|
||||
if (!Number.isFinite(basis)) return exact;
|
||||
if (separation <= PERSPECTIVE_BLEND_MIN_PX) return basis;
|
||||
const weight =
|
||||
(separation - PERSPECTIVE_BLEND_MIN_PX) /
|
||||
(PERSPECTIVE_BLEND_MAX_PX - PERSPECTIVE_BLEND_MIN_PX);
|
||||
const delta = Math.atan2(Math.sin(exact - basis), Math.cos(exact - basis));
|
||||
return basis + delta * weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Probe separations (px) between which the exact and camera-basis answers
|
||||
* are blended. At or below the floor the camera-basis answer is used alone;
|
||||
* at or above the ceiling the exact one.
|
||||
*/
|
||||
export const PERSPECTIVE_BLEND_MIN_PX = 0.5;
|
||||
export const PERSPECTIVE_BLEND_MAX_PX = 3;
|
||||
|
||||
/** Exported for tests: how far ahead the exact projection probes. */
|
||||
export const PERSPECTIVE_PROBE_M = NEAR_PROBE_M;
|
||||
@@ -3,11 +3,13 @@ import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import {
|
||||
HORIZON_FEATHER_RAD,
|
||||
horizonOccluder,
|
||||
screenProjectedRotation,
|
||||
skyBackdropFactor,
|
||||
stabilizeScreenRotation,
|
||||
} from './iconOrientation.js';
|
||||
import {
|
||||
horizonOccluder,
|
||||
screenProjectedRotation,
|
||||
} from '../render/cesium/iconOrientation.js';
|
||||
|
||||
const equatorPosition = Cesium.Cartesian3.fromDegrees(0, 0, 0);
|
||||
|
||||
@@ -563,7 +565,7 @@ import {
|
||||
PERSPECTIVE_BLEND_MIN_PX,
|
||||
PERSPECTIVE_PROBE_M,
|
||||
perspectiveProjectedRotation,
|
||||
} from './iconOrientation.js';
|
||||
} from '../render/cesium/iconOrientation.js';
|
||||
|
||||
/**
|
||||
* A scene the exact projector accepts: 3D mode, a canvas, and a camera with a
|
||||
|
||||
@@ -62,8 +62,8 @@ export function createLifecycle({
|
||||
if (!layerState.enabled) return;
|
||||
const now = Date.now();
|
||||
// "Did the camera move" uses the same quantization as the fleet
|
||||
// rotation pass's iconOrientation.cameraPoseSignature (keep the two
|
||||
// in step), read from the camera port's pose, rather than
|
||||
// rotation pass's cameraPoseSignature (render/cesium/iconOrientation;
|
||||
// keep the two in step), read from the camera port's pose, rather than
|
||||
// camera.changed, whose granularity is globally degraded by other layers
|
||||
// mutating camera.percentageChanged.
|
||||
const poseSig = cameraMotionSignature(layerState.viewer);
|
||||
|
||||
@@ -21,7 +21,7 @@ import { writeHoldSegment } from '../../data/iconSegment.js';
|
||||
import { IconSetPrimitive } from '../../render/cesium/iconSetPrimitive.js';
|
||||
import { iconAtlas } from '../../data/iconAtlas.js';
|
||||
import { cctvPicks } from './pickState.js';
|
||||
import { horizonOccluder } from '../../data/iconOrientation.js';
|
||||
import { horizonOccluder } from '../../render/cesium/iconOrientation.js';
|
||||
import { frustumVolumeGeometryData } from '../../data/cctvViewshed.js';
|
||||
import { entityRecord } from '../../data/entityRecords.js';
|
||||
import { toColor } from '../../render/cesium/draw.js';
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { CLASS_SCALE_2D } from '../../data/aircraftClass.js';
|
||||
import { aircraftIcon } from '../../data/aircraftIcons.js';
|
||||
import {
|
||||
screenProjectedRotation,
|
||||
courseScreenRotation,
|
||||
stabilizeScreenRotation,
|
||||
} from '../../data/iconOrientation.js';
|
||||
} from '../../data/screenRotation.js';
|
||||
import { fromDegreesInto, toLonLatH } from '../../geo/ellipsoid.js';
|
||||
import { hexColor } from '../../render/color.js';
|
||||
import {
|
||||
@@ -200,14 +200,12 @@ export function createLocalAdsbLayer({
|
||||
*/
|
||||
function cameraBasis() {
|
||||
const pose = viewer ? findCamera(viewer)?.pose() : null;
|
||||
return pose?.right && pose?.up
|
||||
? { camera: { rightWC: pose.right, upWC: pose.up } }
|
||||
: null;
|
||||
return pose?.right && pose?.up ? { right: pose.right, up: pose.up } : null;
|
||||
}
|
||||
|
||||
function markerRotation(marker, basis = cameraBasis()) {
|
||||
if (!basis || !marker.position) return marker.lastRotation;
|
||||
const projected = screenProjectedRotation(
|
||||
const projected = courseScreenRotation(
|
||||
basis,
|
||||
marker.position,
|
||||
marker.courseDeg ?? 0,
|
||||
|
||||
@@ -3,7 +3,7 @@ import * as Cesium from 'cesium';
|
||||
// renderer bound, the layer's flights and camera reads find a camera port.
|
||||
import '../../render/cesium/camera.js';
|
||||
import { clusterPointCollection as clusterPointsOf } from '../../render/cesium/internals.js';
|
||||
import { horizonOccluder } from '../../data/iconOrientation.js';
|
||||
import { horizonOccluder } from '../../render/cesium/iconOrientation.js';
|
||||
import {
|
||||
MARKER_LIFT_M,
|
||||
RADIO_PREFIX,
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
import {
|
||||
cameraPoseSignature,
|
||||
perspectiveProjectedRotation,
|
||||
} from '../../data/iconOrientation.js';
|
||||
} from '../../render/cesium/iconOrientation.js';
|
||||
import {
|
||||
updatePlayback,
|
||||
applyDisplayCourse,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import test from 'node:test';
|
||||
import { cameraPoseSignature } from '../../data/iconOrientation.js';
|
||||
import { cameraPoseSignature } from '../cesium/iconOrientation.js';
|
||||
import { poseSignature } from './poseSignature.js';
|
||||
|
||||
const pose = {
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* @module render/cesium/iconOrientation
|
||||
* @description The icon orientation and horizon helpers that read a Cesium
|
||||
* scene or camera: the camera-basis course rotation, the exact perspective
|
||||
* rotation for surface contacts, the shared horizon occluder and the camera
|
||||
* pose signature. Why the course is projected the way it is, and the
|
||||
* engine-free pieces (`skyBackdropFactor`, `stabilizeScreenRotation`), are
|
||||
* in `src/data/iconOrientation.js` and `src/data/screenRotation.js`.
|
||||
*/
|
||||
import * as Cesium from 'cesium';
|
||||
import { poseSignature } from '../camera/poseSignature.js';
|
||||
import { courseScreenRotation } from '../../data/screenRotation.js';
|
||||
|
||||
const _scratchEnu = new Cesium.Matrix4();
|
||||
const _scratchForward = new Cesium.Cartesian3();
|
||||
const _scratchWorldForward = new Cesium.Cartesian3();
|
||||
|
||||
/**
|
||||
* Computes the billboard rotation (radians, CCW-positive, for
|
||||
* alignedAxis = Cartesian3.ZERO) that points an icon along its real-world
|
||||
* course in the stable camera-basis approximation described in
|
||||
* `src/data/iconOrientation.js`; the
|
||||
* scene's camera axes in `screenRotation.js`'s `courseScreenRotation`.
|
||||
*
|
||||
* @param {Cesium.Scene} scene - The scene (projection source).
|
||||
* @param {Cesium.Cartesian3} position - Entity world position.
|
||||
* @param {number} courseDeg - Course/track in degrees clockwise from north.
|
||||
* @param {number|null} previous - Rotation to keep when projection is
|
||||
* unavailable (off-screen/behind camera/degenerate).
|
||||
* @returns {number|null} Rotation in radians, or `previous` when unknown.
|
||||
*/
|
||||
export function screenProjectedRotation(
|
||||
scene,
|
||||
position,
|
||||
courseDeg,
|
||||
previous = null,
|
||||
) {
|
||||
const camera = scene?.camera;
|
||||
return courseScreenRotation(
|
||||
camera && { right: camera.rightWC, up: camera.upWC },
|
||||
position,
|
||||
courseDeg,
|
||||
previous,
|
||||
);
|
||||
}
|
||||
|
||||
const _occluder = new Cesium.EllipsoidalOccluder(
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
new Cesium.Cartesian3(),
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the shared horizon occluder, updated to the camera's position.
|
||||
* With the Cesium globe hidden (Google 3D tiles provide the planet) nothing
|
||||
* writes far-side depth, so billboards must be horizon-culled manually.
|
||||
* Call once per tick, then test points with occluder.isPointVisible(pos).
|
||||
*
|
||||
* @param {Cesium.Camera} camera - The scene camera.
|
||||
* @returns {Cesium.EllipsoidalOccluder}
|
||||
*/
|
||||
export function horizonOccluder(camera) {
|
||||
_occluder.cameraPosition = camera.positionWC;
|
||||
return _occluder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cheap camera pose signature for "did the camera move" gating of rotation
|
||||
* passes (position quantized to ~10m, angles to ~0.06 deg).
|
||||
* @param {Cesium.Camera} camera - The scene camera.
|
||||
* @returns {string}
|
||||
*/
|
||||
export function cameraPoseSignature(camera) {
|
||||
return poseSignature({
|
||||
position: camera.positionWC,
|
||||
heading: camera.heading,
|
||||
pitch: camera.pitch,
|
||||
roll: camera.roll,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Meters ahead used by the exact projection below. Short on purpose: the point
|
||||
* of a perspective projection is that it is LOCAL to the contact, and a two
|
||||
* kilometre probe on a bus at six hundred metres would sample a part of the
|
||||
* frustum the vehicle is nowhere near.
|
||||
*/
|
||||
const NEAR_PROBE_M = 30;
|
||||
const _scratchProbe = new Cesium.Cartesian3();
|
||||
const _scratchWindowAt = new Cesium.Cartesian2();
|
||||
const _scratchWindowAhead = new Cesium.Cartesian2();
|
||||
|
||||
/**
|
||||
* Billboard rotation for a SURFACE contact, projected exactly — perspective
|
||||
* division included — instead of through the camera-basis approximation.
|
||||
*
|
||||
* `screenProjectedRotation` above deliberately projects the course vector onto
|
||||
* the camera's right/up basis, which is orthographic: exact at the viewport
|
||||
* centre and an approximation away from it. That is the right trade for
|
||||
* aircraft, where the alternative loses continuity through a tracked orbit and
|
||||
* the contacts are far enough away for the error to be small.
|
||||
*
|
||||
* It is the wrong trade for street-level vehicles. A probe with a real Cesium
|
||||
* camera at 600 m and −45° pitch, on a northbound contact 350 m right of
|
||||
* centre, put the orthographic answer at 0° where the true screen direction of
|
||||
* travel was 22.5°. At that pitch and that range the vehicles fill the frame
|
||||
* away from the centre, and every one of them points visibly wrong.
|
||||
*
|
||||
* So this projects two nearby world points through the actual view-projection
|
||||
* and reads the angle between them on screen. When either point cannot be
|
||||
* projected — behind the camera, off the frustum, degenerate — it falls back to
|
||||
* the camera-basis answer rather than inventing one.
|
||||
*
|
||||
* @param {Cesium.Scene} scene The scene (projection source).
|
||||
* @param {Cesium.Cartesian3} position Entity world position.
|
||||
* @param {number} courseDeg Course in degrees clockwise from north.
|
||||
* @param {number|null} previous Rotation to keep when projection is unavailable.
|
||||
* @returns {number|null} Rotation in radians, or the fallback.
|
||||
*/
|
||||
export function perspectiveProjectedRotation(
|
||||
scene,
|
||||
position,
|
||||
courseDeg,
|
||||
previous = null,
|
||||
) {
|
||||
if (!scene?.camera || !position || !Number.isFinite(courseDeg)) {
|
||||
return previous;
|
||||
}
|
||||
const courseRad = Cesium.Math.toRadians(courseDeg);
|
||||
Cesium.Cartesian3.fromElements(
|
||||
Math.sin(courseRad) * NEAR_PROBE_M,
|
||||
Math.cos(courseRad) * NEAR_PROBE_M,
|
||||
0,
|
||||
_scratchForward,
|
||||
);
|
||||
const enu = Cesium.Transforms.eastNorthUpToFixedFrame(
|
||||
position,
|
||||
Cesium.Ellipsoid.WGS84,
|
||||
_scratchEnu,
|
||||
);
|
||||
Cesium.Matrix4.multiplyByPointAsVector(
|
||||
enu,
|
||||
_scratchForward,
|
||||
_scratchWorldForward,
|
||||
);
|
||||
Cesium.Cartesian3.add(position, _scratchWorldForward, _scratchProbe);
|
||||
|
||||
const at = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
position,
|
||||
_scratchWindowAt,
|
||||
);
|
||||
const ahead = Cesium.SceneTransforms.worldToWindowCoordinates(
|
||||
scene,
|
||||
_scratchProbe,
|
||||
_scratchWindowAhead,
|
||||
);
|
||||
if (!at || !ahead) {
|
||||
return screenProjectedRotation(scene, position, courseDeg, previous);
|
||||
}
|
||||
const dx = ahead.x - at.x;
|
||||
const dy = ahead.y - at.y;
|
||||
const separation = Math.hypot(dx, dy);
|
||||
// Window y grows downward; rotation 0 = icon pointing screen-up.
|
||||
const exact = Math.atan2(-dx, -dy);
|
||||
if (separation >= PERSPECTIVE_BLEND_MAX_PX) return exact;
|
||||
// Below a pixel or so of separation the exact answer is dominated by
|
||||
// projection noise, and above it the camera-basis answer is the wrong one
|
||||
// by up to twenty-odd degrees. A hard cutoff between the two flipped a
|
||||
// sprite by 23° for a 20 m change of camera altitude; the two answers are
|
||||
// blended across the band instead, the short way round, so the rotation is
|
||||
// continuous through it.
|
||||
const basis = screenProjectedRotation(scene, position, courseDeg, previous);
|
||||
if (!Number.isFinite(basis)) return exact;
|
||||
if (separation <= PERSPECTIVE_BLEND_MIN_PX) return basis;
|
||||
const weight =
|
||||
(separation - PERSPECTIVE_BLEND_MIN_PX) /
|
||||
(PERSPECTIVE_BLEND_MAX_PX - PERSPECTIVE_BLEND_MIN_PX);
|
||||
const delta = Math.atan2(Math.sin(exact - basis), Math.cos(exact - basis));
|
||||
return basis + delta * weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Probe separations (px) between which the exact and camera-basis answers
|
||||
* are blended. At or below the floor the camera-basis answer is used alone;
|
||||
* at or above the ceiling the exact one.
|
||||
*/
|
||||
export const PERSPECTIVE_BLEND_MIN_PX = 0.5;
|
||||
export const PERSPECTIVE_BLEND_MAX_PX = 3;
|
||||
|
||||
/** Exported for tests: how far ahead the exact projection probes. */
|
||||
export const PERSPECTIVE_PROBE_M = NEAR_PROBE_M;
|
||||
@@ -11,7 +11,6 @@
|
||||
"src/data/detection.js",
|
||||
"src/data/focusDeemphasis.js",
|
||||
"src/data/geoImportPins.js",
|
||||
"src/data/iconOrientation.js",
|
||||
"src/input/dispatcher.js",
|
||||
"src/input/sensorPick.js",
|
||||
"src/layers/cctv/projection.js",
|
||||
|
||||
Reference in new issue
Block a user