mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 01:02:23 +00:00
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.
This commit is contained in:
1 parent
ac0496a785
commit
f834903950
2 files changed
+72
-2
No files matched your search
@@ -697,6 +697,54 @@ export function cameraChecks() {
|
|||||||
r.destroy();
|
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',
|
id: 'camera.fov',
|
||||||
port: 'camera',
|
port: 'camera',
|
||||||
|
|||||||
@@ -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 } = {}) {
|
function setView({ destination, orientation } = {}) {
|
||||||
command('setView');
|
command('setView');
|
||||||
const resolved = resolveDestination(destination, orientation);
|
if (orientation && 'direction' in orientation) {
|
||||||
placeAt(resolved.destination, resolved.angles);
|
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');
|
requestRender('camera');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user