mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
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.
56 lines
2.1 KiB
JavaScript
56 lines
2.1 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
|
|
import {
|
|
cameraSensitivityClaims,
|
|
claimCameraSensitivity,
|
|
releaseCameraSensitivity,
|
|
} from './cameraSensitivity.js';
|
|
|
|
test('claims on a globe engine set its camera sensitivity and share one ledger', () => {
|
|
const engine = createFakeEngine();
|
|
assert.equal(claimCameraSensitivity(engine, 'traffic', 0.05), 0.05);
|
|
assert.equal(engine.camera.percentageChanged, 0.05);
|
|
// The engine and its camera are the same claimant.
|
|
assert.equal(
|
|
claimCameraSensitivity(engine.camera, 'installations', 0.01),
|
|
0.01,
|
|
);
|
|
assert.deepEqual(cameraSensitivityClaims(engine), [
|
|
'traffic',
|
|
'installations',
|
|
]);
|
|
assert.equal(releaseCameraSensitivity(engine, 'installations'), 0.05);
|
|
assert.equal(releaseCameraSensitivity(engine.camera, 'traffic'), 0.5);
|
|
assert.equal(engine.camera.percentageChanged, 0.5);
|
|
assert.deepEqual(cameraSensitivityClaims(engine), []);
|
|
});
|
|
|
|
test("a Cesium viewer's camera claims on the same key as its engine's camera", async () => {
|
|
const { createFakeViewer } =
|
|
await import('../globe/cesium/testing/fakeViewer.mjs');
|
|
const { createCesiumEngine } =
|
|
await import('../globe/cesium/createCesiumEngine.js');
|
|
const { registerViewerEngine } =
|
|
await import('../globe/cesium/engineFromViewer.js');
|
|
const viewer = createFakeViewer();
|
|
const engine = createCesiumEngine(viewer, { requestRender: () => {} });
|
|
const unregister = registerViewerEngine(viewer, engine);
|
|
try {
|
|
claimCameraSensitivity(viewer.camera, 'traffic', 0.05);
|
|
claimCameraSensitivity(engine, 'transit', 0.05);
|
|
// One ledger: both claims are on it, and releasing one keeps the other.
|
|
assert.deepEqual(cameraSensitivityClaims(viewer).sort(), [
|
|
'traffic',
|
|
'transit',
|
|
]);
|
|
releaseCameraSensitivity(engine, 'transit');
|
|
assert.equal(viewer.camera.percentageChanged, 0.05);
|
|
releaseCameraSensitivity(viewer.camera, 'traffic');
|
|
assert.equal(viewer.camera.percentageChanged, 0.5);
|
|
} finally {
|
|
unregister();
|
|
engine.destroy();
|
|
}
|
|
});
|