mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 03:02: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
@@ -14,6 +14,8 @@ export function createFakeViewer({ width = 1024, height = 768 } = {}) {
|
||||
return typeof value === 'function' ? value(...args) : value;
|
||||
};
|
||||
const primitiveList = [];
|
||||
const entityList = [];
|
||||
let trackedEntity;
|
||||
const imageryList = [];
|
||||
const staticCredits = [];
|
||||
const creditDisplay = {
|
||||
@@ -28,6 +30,9 @@ export function createFakeViewer({ width = 1024, height = 768 } = {}) {
|
||||
const fovy = 2 * Math.atan(Math.tan(Math.PI / 6) * (height / width));
|
||||
const camera = {
|
||||
positionWC: new Cesium.Cartesian3(7e6, 1e5, 2e5),
|
||||
// Position and direction in the camera's transform (identity: world).
|
||||
position: new Cesium.Cartesian3(7e6, 1e5, 2e5),
|
||||
direction: new Cesium.Cartesian3(-1, 0, 0),
|
||||
directionWC: new Cesium.Cartesian3(-1, 0, 0),
|
||||
upWC: new Cesium.Cartesian3(0, 0, 1),
|
||||
rightWC: new Cesium.Cartesian3(0, 1, 0),
|
||||
@@ -81,9 +86,18 @@ export function createFakeViewer({ width = 1024, height = 768 } = {}) {
|
||||
flight.options.cancel?.();
|
||||
}),
|
||||
lookAt: record('camera.lookAt'),
|
||||
lookAtTransform: record('camera.lookAtTransform', (transform) =>
|
||||
Cesium.Matrix4.clone(transform, camera.transform),
|
||||
),
|
||||
// With an offset (a Cartesian3), the camera sits there in the new frame
|
||||
// looking at its origin.
|
||||
lookAtTransform: record('camera.lookAtTransform', (transform, offset) => {
|
||||
Cesium.Matrix4.clone(transform, camera.transform);
|
||||
if (offset instanceof Cesium.Cartesian3) {
|
||||
Cesium.Cartesian3.clone(offset, camera.position);
|
||||
Cesium.Cartesian3.normalize(
|
||||
Cesium.Cartesian3.negate(offset, camera.direction),
|
||||
camera.direction,
|
||||
);
|
||||
}
|
||||
}),
|
||||
zoomIn: record('camera.zoomIn'),
|
||||
zoomOut: record('camera.zoomOut'),
|
||||
computeViewRectangle: record(
|
||||
@@ -165,9 +179,37 @@ export function createFakeViewer({ width = 1024, height = 768 } = {}) {
|
||||
staticCredits,
|
||||
primitiveList,
|
||||
trackedEntityChanged: new Cesium.Event(),
|
||||
// The viewer clock: only its tick event (CesiumWidget ticks it right
|
||||
// before scene.render on every animation frame).
|
||||
clock: { onTick: new Cesium.Event() },
|
||||
// Assigning raises trackedEntityChanged, as Cesium's Viewer does.
|
||||
get trackedEntity() {
|
||||
return trackedEntity;
|
||||
},
|
||||
set trackedEntity(value) {
|
||||
if (value === trackedEntity) return;
|
||||
trackedEntity = value;
|
||||
calls.push({ name: 'trackedEntity', args: [value] });
|
||||
viewer.trackedEntityChanged.raiseEvent(value);
|
||||
},
|
||||
entities: {
|
||||
values: entityList,
|
||||
add: record('entities.add', (options) => {
|
||||
const entity = new Cesium.Entity(options);
|
||||
entityList.push(entity);
|
||||
return entity;
|
||||
}),
|
||||
remove: record('entities.remove', (entity) => {
|
||||
const index = entityList.indexOf(entity);
|
||||
if (index >= 0) entityList.splice(index, 1);
|
||||
return index >= 0;
|
||||
}),
|
||||
contains: (entity) => entityList.includes(entity),
|
||||
},
|
||||
isDestroyed: () => false,
|
||||
// The viewer clock: its tick event (CesiumWidget ticks it right before
|
||||
// scene.render on every animation frame) and current time.
|
||||
clock: {
|
||||
onTick: new Cesium.Event(),
|
||||
currentTime: Cesium.JulianDate.fromIso8601('2026-10-16T12:00:00Z'),
|
||||
},
|
||||
imageryList,
|
||||
terrainProvider: undefined,
|
||||
imageryLayers: {
|
||||
|
||||
Reference in new issue
Block a user