mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
Tilt, north-up and the compass through the camera, query and frame ports
The map orientation controls pick the view's centre through the query port (depth, then the globe along the pick ray, then the ellipsoid), read the camera from the camera port's pose, and set the orbit frame through the port's lookAt, release and setView. The eased orientation runs on the frame port's preUpdate, the compass needle on its preRender, and the tilt state refreshes on the camera port's moveEnd. While the camera follows something, the orbit offset must stay in the follow's own frame (a satellite's included), which only Cesium knows: that step moves verbatim into placeFollowEye in shareFollow, which stays on the Cesium allow-list. cameraOrientationControls leaves it.
This commit is contained in:
1 parent
7ab969599c
commit
068c39d5e7
5 files changed
+169
-131
No files matched your search
@@ -13,8 +13,34 @@ import {
|
||||
} from './cameraOrientationControls.js';
|
||||
import { NavigationController } from './navigationController.js';
|
||||
import { bindRenderer } from '../render/rendererOf.js';
|
||||
import {
|
||||
createCesiumQuery,
|
||||
queryCapabilities,
|
||||
} from '../render/cesium/query.js';
|
||||
import { bindFakeCesiumCamera } from '../testSupport/fakeCameraPort.mjs';
|
||||
import { fakeSceneFrame } from '../testSupport/fakeCesiumScene.mjs';
|
||||
import { entityRecord } from '../data/entityRecords.js';
|
||||
|
||||
/**
|
||||
* Bind the camera, query and frame ports over a viewer double, as the
|
||||
* renderer does: the Cesium query port over its scene, and the frame
|
||||
* phases from the scene's own events.
|
||||
*/
|
||||
function withPorts(viewer, { frames = true } = {}) {
|
||||
return bindFakeCesiumCamera(viewer, {
|
||||
query: createCesiumQuery({
|
||||
scene: viewer.scene,
|
||||
camera: viewer.camera,
|
||||
draw: { sets: new Map(), version: () => 0 },
|
||||
capabilities: new Set(queryCapabilities(viewer.scene)),
|
||||
}),
|
||||
...(frames ? { frame: fakeSceneFrame(viewer) } : {}),
|
||||
});
|
||||
}
|
||||
|
||||
/** Coordinates only, as the query port answers. */
|
||||
const plain = (p) => ({ x: p.x, y: p.y, z: p.z });
|
||||
|
||||
function createViewer({ cameraPosition, target, pickPosition = null } = {}) {
|
||||
const calls = [];
|
||||
const changed = new Cesium.Event();
|
||||
@@ -27,7 +53,7 @@ function createViewer({ cameraPosition, target, pickPosition = null } = {}) {
|
||||
heading: Cesium.Math.toRadians(90),
|
||||
changed,
|
||||
pickEllipsoid: () => surface,
|
||||
getPickRay: () => ({}),
|
||||
getPickRay: () => new Cesium.Ray(),
|
||||
lookAt(targetValue, offset) {
|
||||
calls.push({ type: 'lookAt', target: targetValue, offset });
|
||||
},
|
||||
@@ -48,7 +74,7 @@ function createViewer({ cameraPosition, target, pickPosition = null } = {}) {
|
||||
requestRender: () => calls.push({ type: 'requestRender' }),
|
||||
},
|
||||
};
|
||||
return { viewer, calls, target: surface };
|
||||
return { viewer: withPorts(viewer), calls, target: surface };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,8 +124,12 @@ function createRealCamera() {
|
||||
return { camera, scene };
|
||||
}
|
||||
|
||||
/** A viewer whose center pick is a fixed ground point and whose camera is real. */
|
||||
function createRealViewer(target) {
|
||||
/**
|
||||
* A viewer whose center pick is a fixed ground point and whose camera is
|
||||
* real. Without `frames` it has no frame loop, so orientation changes land
|
||||
* at once rather than easing.
|
||||
*/
|
||||
function createRealViewer(target, { frames = true } = {}) {
|
||||
const { camera, scene } = createRealCamera();
|
||||
scene.pickPositionSupported = false;
|
||||
scene.pickPosition = () => null;
|
||||
@@ -108,8 +138,8 @@ function createRealViewer(target) {
|
||||
// The binding drives the needle from the scene's per-frame signal, not from
|
||||
// `camera.changed`, so the fixture has to carry one.
|
||||
scene.preRender = new Cesium.Event();
|
||||
camera.getPickRay = () => ({});
|
||||
return { viewer: { camera, scene }, target };
|
||||
camera.getPickRay = () => new Cesium.Ray();
|
||||
return { viewer: withPorts({ camera, scene }, { frames }), target };
|
||||
}
|
||||
|
||||
/** Place a real camera in an orbit around `target` and release the frame. */
|
||||
@@ -279,7 +309,7 @@ test('tilt alternates at globe range, not only at map range', () => {
|
||||
|
||||
test('the button shows the state the next click will produce, at every range', () => {
|
||||
for (const range of [3_000, 18_000_000]) {
|
||||
const { viewer } = createRealViewer(AUSTIN_GROUND);
|
||||
const { viewer } = createRealViewer(AUSTIN_GROUND, { frames: false });
|
||||
orbit(viewer, AUSTIN_GROUND, 0, STRAIGHT_DOWN_PITCH, range);
|
||||
const bar = recorder();
|
||||
const controls = bindCameraOrientationControls({
|
||||
@@ -410,9 +440,9 @@ test('a sky-facing camera yields no frame and both actions decline', () => {
|
||||
scene.pickPosition = () => null;
|
||||
scene.globe.pick = () => undefined;
|
||||
scene.requestRender = () => {};
|
||||
camera.getPickRay = () => ({});
|
||||
camera.getPickRay = () => new Cesium.Ray();
|
||||
camera.pickEllipsoid = () => undefined;
|
||||
const viewer = { camera, scene };
|
||||
const viewer = withPorts({ camera, scene });
|
||||
|
||||
assert.equal(readCameraTargetFrame(viewer), null);
|
||||
assert.equal(toggleCameraTilt(viewer), false);
|
||||
@@ -426,16 +456,16 @@ test('center picking prefers terrain over the ellipsoid and falls through an inv
|
||||
const { viewer } = createViewer({ pickPosition: () => invalid });
|
||||
viewer.scene.globe.pick = () => terrain;
|
||||
viewer.camera.pickEllipsoid = () => sea;
|
||||
assert.equal(
|
||||
assert.deepEqual(
|
||||
pickViewTarget(viewer),
|
||||
terrain,
|
||||
plain(terrain),
|
||||
'the rendered ground wins over sea level',
|
||||
);
|
||||
|
||||
viewer.scene.globe.pick = () => null;
|
||||
assert.equal(
|
||||
assert.deepEqual(
|
||||
pickViewTarget(viewer),
|
||||
sea,
|
||||
plain(sea),
|
||||
'the ellipsoid still answers when nothing is under the cursor',
|
||||
);
|
||||
});
|
||||
@@ -455,7 +485,7 @@ test('tilt preserves the picked target and range while choosing oblique pitch',
|
||||
const result = toggleCameraTilt(viewer);
|
||||
const lookAt = calls.find((call) => call.type === 'lookAt');
|
||||
assert.deepEqual(result, { tilted: true, pitch: OBLIQUE_PITCH });
|
||||
assert.equal(lookAt.target, target);
|
||||
assert.ok(Cesium.Cartesian3.equals(lookAt.target, target));
|
||||
assert.equal(lookAt.offset.range, before.range);
|
||||
assert.equal(lookAt.offset.pitch, OBLIQUE_PITCH);
|
||||
assert.ok(calls.some((call) => call.type === 'lookAtTransform'));
|
||||
|
||||
Reference in new issue
Block a user