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:
German Khokhlov committed 2026-10-16 20:26:43 +04:00
1 parent a89719aba9
commit f640890cf6
24 files changed
+1226 -218

No files matched your search

+7
View File
@@ -408,6 +408,13 @@ export function createCameraModel({
lift(position) {
place({ ...state, position: copy3(position) });
},
/**
* Places the camera at `pose` ({ position, direction, up }) without
* camera.commanded: the follow camera's own step, not a new owner.
*/
aim(pose) {
place(pose);
},
/** The current camera for projections: pose, vertical fov and CSS size. */
view,
worldToWindow: (position, result) =>
+19
View File
@@ -18,6 +18,7 @@ import { createNavaraClock } from './clock.js';
import { createNavaraCredits } from './credits.js';
import { createNavaraInput } from './input.js';
import { createNavaraPicking } from './picking.js';
import { createFollowController } from '../follow.js';
import { createNavaraMaps } from './maps.js';
import { createNavaraSurface } from './surface.js';
import { createGroundFloor, GROUND_FLOOR } from './groundFloor.js';
@@ -143,6 +144,21 @@ export function createNavaraEngine(
postRender: createEngineEvent(),
};
const engineClock = createNavaraClock(appClock ? { appClock } : {});
// camera.follow (src/globe/follow.js): Navara's own cameraFollow takes
// no user rotation or zoom (phase 3 Task 5 probe), so the engine steps
// its own follow each frame.
const followStep = createEngineEvent();
const follow = createFollowController({
camera: model.camera,
aim: (pose) => model.aim(pose),
frame: followStep,
requestRender: () => view.forceUpdate(),
});
Object.assign(model.camera, {
follow: (options) => follow.follow(options),
following: () => follow.following(),
followChanged: follow.followChanged,
});
// Defined below, with the surface and input it needs.
let groundFloor = null;
const handlers = {
@@ -152,6 +168,8 @@ export function createNavaraEngine(
},
preRender: (time) => {
model.sync();
// After the user's camera is read, before anything draws.
followStep.raiseEvent();
groundFloor?.update();
frames.preRender.raiseEvent(time);
},
@@ -278,6 +296,7 @@ export function createNavaraEngine(
destroyed = true;
for (const [name, handler] of Object.entries(handlers))
view.off(name, handler);
follow.destroy();
model.destroy();
input.destroy();
picking.destroy();