diff --git a/src/globe/navara/cameraModel.js b/src/globe/navara/cameraModel.js index 1645c87fd..6f8fe17b9 100644 --- a/src/globe/navara/cameraModel.js +++ b/src/globe/navara/cameraModel.js @@ -101,7 +101,13 @@ export function createCameraModel({ }; // A camera command takes the camera from whoever held it; say so first. const announce = () => events.commanded.raiseEvent(); - const initial = port.read(); + // Navara's camera sits at the Earth's centre until it is first placed: no + // pose yet (Cesium's camera always has one). + const read = () => { + const pose = port.read(); + return pose && cartesian3.magnitude(pose.position) > 1 ? pose : null; + }; + const initial = read(); let state = initial ? copyPose(initial) : (() => { @@ -216,7 +222,7 @@ export function createCameraModel({ /** Reads Navara's drawn camera; called once per frame before preRender. */ function sync() { - const seen = port.read(); + const seen = read(); if (!seen) return; const moved = !lastSeen || !posesNear(seen, lastSeen, 1e-6, 1e-10); lastSeen = copyPose(seen); diff --git a/src/globe/navara/cameraModel.test.mjs b/src/globe/navara/cameraModel.test.mjs index 425b6fb8b..32b8960eb 100644 --- a/src/globe/navara/cameraModel.test.mjs +++ b/src/globe/navara/cameraModel.test.mjs @@ -157,6 +157,21 @@ test('a camera Navara moves by itself (user input) becomes the pose', () => { near(camera.pose().heading, 0.3, 1e-9, 'heading'); }); +test('a Navara camera not yet placed (at the Earth centre) is not the pose', () => { + const port = createFakePort(); + const unplaced = { + position: cartesian3.create(0, 0, 0), + direction: cartesian3.create(0, 0, -1), + up: cartesian3.create(0, 1, 0), + }; + port.drawn = unplaced; + const model = createCameraModel({ port, clock: createClock() }); + assert.ok(Number.isFinite(model.camera.height()), 'height at start'); + model.sync(); + assert.ok(Number.isFinite(model.camera.height()), 'height after a sync'); + assert.ok(model.camera.pose().cartographic, 'a place on the Earth'); +}); + test('missing angles default to heading 0, pitch −π/2 and roll 0', () => { const { camera } = setup(); const destination = cartesian3.fromDegrees(40, 30, 20000);