mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
fix(globe): the Navara follow turns and dollies as Cesium's tracked camera
Review of Tasks 6-7: a 240 px drag right turned Navara's follow by -67.5° where Cesium turns +119.5°, and a right drag did nothing (Cesium dollies, 1.95 Mm → 0.91 Mm). followGestures.js now follows Cesium's ScreenSpaceCameraController for a tracked camera: - left drag (rotate3D): heading += 1.77 × dx / width × 2π (clockwise for a drag right; 1.77 is Cesium's maximum rotate rate, which a tracked camera beyond a few metres always reaches) and the camera rises by 1.77 × -dy / height × π; each move counts at most a tenth of the canvas (maximumMovementRatio); - right drag (zoom3D): follow.js dollyOffset moves 5 × dy / height of the distance above the floor (closing) or of the range (opening), never inside it; no context menu while following. The contract follow check turns the camera with a 240 px drag right and asserts the heading turn against Cesium's rate (±15 %; the harness holds the pointer before releasing it so Cesium adds no inertia), and dollies with a right drag down (range below 80 %, never under 149 m). Cesium 73/73, Navara 79/79.
This commit is contained in:
1 parent
b0cbed081b
commit
f0ce1b04c7
5 files changed
+188
-19
No files matched your search
@@ -1,12 +1,19 @@
|
||||
// The follow camera's drag and wheel on Navara (src/globe/follow.js
|
||||
// `gestures`): while following, Navara's own spin, zoom and tilt are off
|
||||
// (they pan about the ground point under the cursor and zoom toward it) and
|
||||
// a left drag turns the offset around the target, a wheel scales its range,
|
||||
// as Cesium's tracked camera does: a drag across the whole canvas width is
|
||||
// one turn of heading, across its height half a turn of pitch; one wheel
|
||||
// notch (deltaY 100) is 20 % of the range.
|
||||
// the gestures act on the offset as Cesium's tracked camera does
|
||||
// (ScreenSpaceCameraController rotate3D and zoom3D):
|
||||
// - left drag: heading turns by rate × dx / width × 2π and the camera rises
|
||||
// by rate × −dy / height × π, rate = 1.77 (Cesium's maximum rotate rate,
|
||||
// which a tracked camera beyond a few metres always reaches); each move
|
||||
// counts at most a tenth of the canvas (maximumMovementRatio); a drag
|
||||
// right turns the heading clockwise;
|
||||
// - right drag: a dolly by dy / height (down closes in);
|
||||
// - wheel: one notch (deltaY 100) is 20 % of the range.
|
||||
|
||||
const WHEEL_STEP = 1.2;
|
||||
const ROTATE_RATE = 1.77;
|
||||
const MAX_MOVEMENT_RATIO = 0.1;
|
||||
|
||||
/**
|
||||
* @param {HTMLCanvasElement} canvas
|
||||
@@ -20,21 +27,28 @@ export function navaraFollowGestures(
|
||||
suspendCameraInputs,
|
||||
windowTarget = globalThis.window ?? canvas,
|
||||
) {
|
||||
return ({ orbit, zoom }) => {
|
||||
return ({ orbit, zoom, dolly }) => {
|
||||
const resume = suspendCameraInputs();
|
||||
let last = null;
|
||||
const down = (event) => {
|
||||
if (event.button !== 0) return;
|
||||
last = { x: event.clientX, y: event.clientY };
|
||||
if (event.button !== 0 && event.button !== 2) return;
|
||||
last = { x: event.clientX, y: event.clientY, button: event.button };
|
||||
};
|
||||
const move = (event) => {
|
||||
if (!last) return;
|
||||
const dx = event.clientX - last.x;
|
||||
const dy = event.clientY - last.y;
|
||||
last = { x: event.clientX, y: event.clientY };
|
||||
last = { ...last, x: event.clientX, y: event.clientY };
|
||||
const width = canvas.clientWidth || 1;
|
||||
const height = canvas.clientHeight || 1;
|
||||
orbit((-dx / width) * 2 * Math.PI, (dy / height) * Math.PI);
|
||||
if (last.button === 2) {
|
||||
dolly?.(dy / height);
|
||||
return;
|
||||
}
|
||||
orbit(
|
||||
ROTATE_RATE * Math.min(dx / width, MAX_MOVEMENT_RATIO) * 2 * Math.PI,
|
||||
ROTATE_RATE * Math.min(-dy / height, MAX_MOVEMENT_RATIO) * Math.PI,
|
||||
);
|
||||
};
|
||||
const up = () => {
|
||||
last = null;
|
||||
@@ -44,11 +58,15 @@ export function navaraFollowGestures(
|
||||
event.preventDefault?.();
|
||||
zoom(WHEEL_STEP ** (event.deltaY / 100));
|
||||
};
|
||||
// The right button drags; no context menu over it.
|
||||
const contextMenu = (event) => event.preventDefault?.();
|
||||
canvas.addEventListener('pointerdown', down);
|
||||
windowTarget.addEventListener('pointermove', move);
|
||||
windowTarget.addEventListener('pointerup', up);
|
||||
canvas.addEventListener('wheel', wheel, { passive: false });
|
||||
canvas.addEventListener('contextmenu', contextMenu);
|
||||
return () => {
|
||||
canvas.removeEventListener('contextmenu', contextMenu);
|
||||
canvas.removeEventListener('pointerdown', down);
|
||||
windowTarget.removeEventListener('pointermove', move);
|
||||
windowTarget.removeEventListener('pointerup', up);
|
||||
|
||||
Reference in new issue
Block a user