mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
feat(globe): follow camera on both engines
camera.follow({ position, viewFrom, minRange = 150, native? }) keeps a
moving target centred at an east-north-up offset the user may turn and
zoom; camera.following() and camera.followChanged report it; stop() frees
the camera and a camera command (setView, flyTo, flyToSphere, lookAt,
cancelFlight) ends it.
Probe ruling: Navara 0.2.1's cameraFollow holds the target but ignores the
user's drag and wheel, the aircraft sits ~13 px off centre with 7.6 px of
spread, and calling it without an offset each frame gives a NaN camera.
So Navara (and the fake engine) follow with src/globe/follow.js: each
frame, before Navara draws, the offset is re-read from where the user put
the camera relative to the previous target, kept outside the minimum
range and carried to the new target.
Cesium follows with viewer.trackedEntity: the layer's own Entity
(`native`) or a proxy Entity at position() with a 1 px transparent point,
since EntityView moves the camera only for an entity with a bounding
sphere. applyTrackedCameraFrame and the zoom limits moved to
src/globe/cesium/follow.js; src/data/trackedCamera.js keeps the pure parts
(the range clamp now lives in src/globe/follow.js). following() also
reports an entity the app tracked itself. Camera sensitivity claims made
on a viewer's Cesium camera now share the engine camera's ledger, and the
orientation controls and the world jump read the follow from the engine.
Contract (both engines): a target flying at 250 m/s stays within 3 px of
the centre for 2 s, zoomIn through it stops at 150 m, stop() and setView
end the follow. Cesium 71/71, Navara 77/77; shell 23/25/4.
This commit is contained in:
1 parent
a89719aba9
commit
f640890cf6
24 files changed
+1226
-218
No files matched your search
@@ -24,6 +24,8 @@
|
||||
* for, only that nobody's answer is taken away while they still need it.
|
||||
*/
|
||||
|
||||
import { engineFromViewer } from '../globe/cesium/engineFromViewer.js';
|
||||
|
||||
/** @type {WeakMap<object, {base: number, claims: Map<string, number>}>} */
|
||||
const _cameras = new WeakMap();
|
||||
|
||||
@@ -31,10 +33,13 @@ const _cameras = new WeakMap();
|
||||
const DEFAULT_PERCENTAGE_CHANGED = 0.5;
|
||||
|
||||
/**
|
||||
* A globe engine (or a viewer) claims through its camera; anything else is
|
||||
* the camera itself (a camera has no `camera` of its own).
|
||||
* One key per camera: the engine's camera. A globe engine claims through its
|
||||
* camera; a Cesium viewer or its camera through the engine registered for
|
||||
* that viewer (engineFromViewer); anything else is the camera itself (a
|
||||
* camera has no `camera` of its own).
|
||||
*/
|
||||
const cameraOf = (target) => target?.camera ?? target;
|
||||
const cameraOf = (target) =>
|
||||
engineFromViewer(target)?.camera ?? target?.camera ?? target;
|
||||
|
||||
function ledgerFor(camera) {
|
||||
let ledger = _cameras.get(camera);
|
||||
@@ -60,9 +65,8 @@ function applyLedger(camera, ledger) {
|
||||
/**
|
||||
* Ask for a camera-change sensitivity at least as fine as `value`.
|
||||
* @param {object|null|undefined} target A globe engine, its camera, or a
|
||||
* Cesium camera (anything with `percentageChanged`). Layers still pass the
|
||||
* viewer's Cesium camera until phase 1c; that is a separate claimant from
|
||||
* the engine's camera, so one camera must not be claimed both ways.
|
||||
* Cesium viewer or camera (anything with `percentageChanged`). A viewer
|
||||
* with a registered engine, and its camera, claim on the engine camera.
|
||||
* @param {string} owner Stable claim name, usually the layer id.
|
||||
* @param {number} value Requested `percentageChanged`.
|
||||
* @returns {number|null} The value now in force, or null when there is no camera.
|
||||
|
||||
Reference in new issue
Block a user