From f8349039500860cde7f61f716b9ef4f58d374fb7 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Tue, 10 Nov 2026 09:45:49 -0800 Subject: [PATCH] Place the stub's camera exactly from a direction and up The contract places a view given as direction and up exactly, but the stub turned it into heading, pitch and roll first, so a thousand small turns straight down drifted by a hundredth. The new check camera.setView.exact holds the stub and Cesium to it; both pass. --- src/render/conformance/checks/camera.js | 48 +++++++++++++++++++++++++ src/render/stub/camera.js | 26 ++++++++++++-- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/render/conformance/checks/camera.js b/src/render/conformance/checks/camera.js index ffd4787af..a6819b528 100644 --- a/src/render/conformance/checks/camera.js +++ b/src/render/conformance/checks/camera.js @@ -697,6 +697,54 @@ export function cameraChecks() { r.destroy(); }, }, + { + id: 'camera.setView.exact', + port: 'camera', + title: + 'a view given as direction and up is placed exactly: a thousand small turns straight down add up to one', + async run(h) { + const r = await fresh(h); + r.camera.setView({ + destination: { lon: -97.74, lat: 30.27, height: 5000 }, + orientation: { heading: 0, pitch: -Math.PI / 2, roll: 0 }, + }); + await h.frame(r); + const start = r.camera.pose(); + // Turn about the eye's own up, as a step turn left does. + const turn = (v, axis, angle) => { + const c = Math.cos(angle); + const s = Math.sin(angle); + const k = axis; + const d = k.x * v.x + k.y * v.y + k.z * v.z; + return { + x: v.x * c + (k.y * v.z - k.z * v.y) * s + k.x * d * (1 - c), + y: v.y * c + (k.z * v.x - k.x * v.z) * s + k.y * d * (1 - c), + z: v.z * c + (k.x * v.y - k.y * v.x) * s + k.z * d * (1 - c), + }; + }; + const step = 1e-5; + for (let i = 0; i < 1000; i++) { + const { position, direction, up } = r.camera.pose(); + r.camera.setView({ + destination: position, + orientation: { direction: turn(direction, up, step), up }, + }); + } + await h.frame(r); + const end = r.camera.pose(); + const want = turn(start.direction, start.up, 1000 * step); + for (const axis of ['x', 'y', 'z']) + near(end.direction[axis], want[axis], 1e-6, `direction.${axis}`); + for (const axis of ['x', 'y', 'z']) + near( + end.position[axis], + start.position[axis], + 1e-3, + `position.${axis}`, + ); + r.destroy(); + }, + }, { id: 'camera.fov', port: 'camera', diff --git a/src/render/stub/camera.js b/src/render/stub/camera.js index b28a14622..1bb3b03ad 100644 --- a/src/render/stub/camera.js +++ b/src/render/stub/camera.js @@ -302,10 +302,32 @@ export function createStubCamera({ }; } + /** + * The eye at `destination` (world), looking along `orientation.direction` + * with `up` made square to it: exactly, not through heading, pitch and + * roll, so step moves sent many times over do not drift. + */ + function placeExactly(destination, orientation) { + const d = normalize(inverseFrameVector(frame, orientation.direction)); + const u0 = inverseFrameVector(frame, orientation.up); + position = inverseFramePoint(frame, destination); + direction = d; + up = normalize(sub(u0, scale(d, dot(u0, d)))); + right = cross(direction, up); + } + function setView({ destination, orientation } = {}) { command('setView'); - const resolved = resolveDestination(destination, orientation); - placeAt(resolved.destination, resolved.angles); + if (orientation && 'direction' in orientation) { + const target = + destination && !('rect' in destination) + ? toEcef(destination) + : resolveDestination(destination, orientation).destination; + placeExactly(target, orientation); + } else { + const resolved = resolveDestination(destination, orientation); + placeAt(resolved.destination, resolved.angles); + } requestRender('camera'); }