mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-09 21:02:19 +00:00
Start Navara's camera model from a placed pose only
Navara's camera sits at the Earth's centre until it is first placed. The model took that as the pose, so camera.height() threw while a layer attached to a starting Navara (wildlife sightings asks for it), and switching to Navara with that layer on rolled back to Cesium.
This commit is contained in:
1 parent
b4556f9763
commit
68845a4977
2 files changed
+23
-2
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user