mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Read the HUD and share-link camera through the renderer's camera port
The first camera-family slice. The camera port's events move into a shared module (render/camera/events.js) that the stub and the Cesium port both use: listener lists, delivery with errors reported, and the contract's per-listener `changed` measure. The Cesium port gains: - camera.on: `changed` measured per listener on every tick, where Cesium measures its single threshold (the counts match Cesium's own at each threshold); moveStart and moveEnd relayed from Cesium's camera; - camera.viewRectangle, in degrees (now in CESIUM_CHECKS); - lon and lat in pose, and NaN where Cesium has no cartographic position. Code that still holds the viewer reaches the renderer through rendererOf(viewer); the application renderer binds it on create and unbinds on destroy. The HUD reads its telemetry from the camera port and no longer imports Cesium (off the allow-list). The share link writes the hash from the pose. Its restore path stays on the viewer's camera for a later slice. Behaviour changes: - The share link listens to `changed` at its own 0.5 threshold, not at whatever global threshold layers had set, and also to moveEnd, so the hash always catches up with where the camera comes to rest. - The HUD's and share link's camera callbacks run from the port's single relay, ahead of other moveStart/moveEnd listeners, and a throw in one is reported to the renderer's error listeners instead of escaping from Cesium's render.
This commit is contained in:
1 parent
910185bfe0
commit
b5900b4178
28 files changed
+688
-243
No files matched your search
@@ -11,7 +11,6 @@ import {
|
||||
IDENTITY,
|
||||
PI_OVER_TWO,
|
||||
TWO_PI,
|
||||
acosClamped,
|
||||
add,
|
||||
clone,
|
||||
cross,
|
||||
@@ -44,6 +43,7 @@ import {
|
||||
vec,
|
||||
zeroToTwoPi,
|
||||
} from './math.js';
|
||||
import { createCameraEvents } from '../camera/events.js';
|
||||
import { geodesicAt } from './geodesic.js';
|
||||
|
||||
const DEFAULT_FOV = Math.PI / 3;
|
||||
@@ -94,13 +94,8 @@ export function createStubCamera({
|
||||
const near = 1;
|
||||
const far = 5e8;
|
||||
|
||||
const listeners = {
|
||||
changed: [],
|
||||
moveStart: [],
|
||||
moveEnd: [],
|
||||
followChanged: [],
|
||||
flightEnd: [],
|
||||
};
|
||||
const events = createCameraEvents({ pose, report });
|
||||
const { emit, on, stepChanged } = events;
|
||||
const commandHooks = [];
|
||||
const holds = new Map();
|
||||
let holdSeq = 0;
|
||||
@@ -727,89 +722,6 @@ export function createStubCamera({
|
||||
|
||||
// --- Events ----------------------------------------------------------------
|
||||
|
||||
function emit(event) {
|
||||
for (const entry of listeners[event].slice()) {
|
||||
if (!entry.live) continue;
|
||||
try {
|
||||
entry.cb();
|
||||
} catch (error) {
|
||||
report(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function on(event, cb, options = {}) {
|
||||
const entry = {
|
||||
cb,
|
||||
live: true,
|
||||
threshold: options.threshold ?? 0.5,
|
||||
ref: null,
|
||||
};
|
||||
listeners[event].push(entry);
|
||||
return () => {
|
||||
entry.live = false;
|
||||
const list = listeners[event];
|
||||
const i = list.indexOf(entry);
|
||||
if (i >= 0) list.splice(i, 1);
|
||||
};
|
||||
}
|
||||
|
||||
/** How far the view moved from a listener's reference, as a fraction. */
|
||||
const angleDelta = (a, b) => {
|
||||
const d = Math.abs(a - b) % TWO_PI;
|
||||
return (d > Math.PI ? TWO_PI - d : d) / Math.PI;
|
||||
};
|
||||
|
||||
/**
|
||||
* Per listener, the reference camera's formula: heading and roll each
|
||||
* against their own last reported value, then direction and position
|
||||
* against the last reported view. Each can report in the same frame.
|
||||
*/
|
||||
function stepChanged() {
|
||||
const list = listeners.changed;
|
||||
if (!list.length) return;
|
||||
const current = pose();
|
||||
for (const entry of list.slice()) {
|
||||
if (!entry.live) continue;
|
||||
const t = entry.threshold;
|
||||
entry.heading ??= current.heading;
|
||||
entry.roll ??= current.roll;
|
||||
const headingF = angleDelta(entry.heading, current.heading);
|
||||
const rollF = angleDelta(entry.roll, current.roll);
|
||||
if (headingF > t) entry.heading = current.heading;
|
||||
if (rollF > t) entry.roll = current.roll;
|
||||
if (headingF > t || rollF > t) deliver(entry);
|
||||
if (!entry.view) {
|
||||
entry.view = {
|
||||
position: current.position,
|
||||
direction: current.direction,
|
||||
};
|
||||
continue;
|
||||
}
|
||||
const dirF =
|
||||
acosClamped(dot(current.direction, entry.view.direction)) /
|
||||
(current.fovy * 0.5);
|
||||
const heightF =
|
||||
distance(current.position, entry.view.position) / current.height;
|
||||
if (dirF > t || heightF > t) {
|
||||
entry.view = {
|
||||
position: current.position,
|
||||
direction: current.direction,
|
||||
};
|
||||
deliver(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function deliver(entry) {
|
||||
if (!entry.live) return;
|
||||
try {
|
||||
entry.cb();
|
||||
} catch (error) {
|
||||
report(error);
|
||||
}
|
||||
}
|
||||
|
||||
function sameView(a, b) {
|
||||
return (
|
||||
a &&
|
||||
|
||||
Reference in new issue
Block a user