mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
fix(camera): moveEnd fires during a follow once the eye stands still, as Cesium's did
Cesium raised moveEnd 500 ms after the camera last moved, following or not: a followed target that moves keeps the eye moving, and one that stands still (a marker, a parked aircraft) lets the move end once the user stops orbiting it. The port never raised moveEnd while following, so Weather, Recent Imagery, the share link and every other moveEnd listener stopped catching up around a still target. The rule is now the eye's alone, through the shared camera events.
This commit is contained in:
1 parent
63a6595eaf
commit
5d48503c51
6 files changed
+25
-28
No files matched your search
@@ -5,8 +5,9 @@
|
||||
* export):
|
||||
* the listener lists, delivery (a throwing listener is reported, the rest
|
||||
* still run), the contract's per-listener `changed` measure, move detection
|
||||
* (`moveStart` on a change, `moveEnd` 500 ms after the last one, never
|
||||
* while following) and the command hooks (`onCommand`). A renderer calls
|
||||
* (`moveStart` on a change, `moveEnd` 500 ms after the last one, as the
|
||||
* reference measures them: a followed target that moves keeps the eye
|
||||
* moving, one that stands still lets the move end) and the command hooks (`onCommand`). A renderer calls
|
||||
* `stepChanged()` and `stepMoveDetection()` once per frame, `command()`
|
||||
* before each camera command, and `emit()` for the events its engine
|
||||
* raises.
|
||||
@@ -52,18 +53,16 @@ function sameView(a, b) {
|
||||
/**
|
||||
* @param {{pose: () => import('../contract/camera').CameraPose,
|
||||
* world?: () => {position: object, direction: object, up: object},
|
||||
* following?: () => boolean,
|
||||
* report: (error: unknown) => void, thresholds?: boolean}} options `pose`
|
||||
* is read only while a `changed` listener is registered; `world` (the
|
||||
* eye in world coordinates; `pose()` when omitted) and `following` (no
|
||||
* `moveEnd` while true) are read by `stepMoveDetection`; `thresholds`
|
||||
* eye in world coordinates; `pose()` when omitted) is read by
|
||||
* `stepMoveDetection`; `thresholds`
|
||||
* false (a renderer without `cameraChangeThreshold`) ignores a listener's
|
||||
* own threshold, so every listener fires at 0.5.
|
||||
*/
|
||||
export function createCameraEvents({
|
||||
pose,
|
||||
world = pose,
|
||||
following = () => false,
|
||||
report,
|
||||
thresholds = true,
|
||||
}) {
|
||||
@@ -168,11 +167,7 @@ export function createCameraEvents({
|
||||
moving = true;
|
||||
emit('moveStart');
|
||||
}
|
||||
} else if (
|
||||
moving &&
|
||||
!following() &&
|
||||
now - lastMovedAt >= MOVE_END_WAIT_MS
|
||||
) {
|
||||
} else if (moving && now - lastMovedAt >= MOVE_END_WAIT_MS) {
|
||||
moving = false;
|
||||
emit('moveEnd');
|
||||
}
|
||||
|
||||
@@ -9,14 +9,12 @@ const view = (x) => ({
|
||||
up: { x: 0, y: 0, z: 1 },
|
||||
});
|
||||
|
||||
test('moveStart on a change, moveEnd once nothing moved for 500 ms and nothing is followed', () => {
|
||||
test('moveStart on a change, moveEnd once nothing moved for 500 ms', () => {
|
||||
let eye = view(7e6);
|
||||
let following = false;
|
||||
const seen = [];
|
||||
const events = createCameraEvents({
|
||||
pose: () => eye,
|
||||
world: () => eye,
|
||||
following: () => following,
|
||||
report: (error) => assert.fail(error),
|
||||
});
|
||||
events.on('moveStart', () => seen.push('start'));
|
||||
@@ -34,11 +32,7 @@ test('moveStart on a change, moveEnd once nothing moved for 500 ms and nothing i
|
||||
assert.deepEqual(seen, ['start']);
|
||||
events.stepMoveDetection(400 + MOVE_END_WAIT_MS - 1);
|
||||
assert.deepEqual(seen, ['start']);
|
||||
following = true;
|
||||
events.stepMoveDetection(400 + MOVE_END_WAIT_MS);
|
||||
assert.deepEqual(seen, ['start'], 'never while following');
|
||||
following = false;
|
||||
events.stepMoveDetection(401 + MOVE_END_WAIT_MS);
|
||||
assert.deepEqual(seen, ['start', 'end']);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user