mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
Set the field of view and read the matrices through the camera port
setFov holds the vertical angle it is given across resizes (Cesium keeps the wider one), waits for a frustum with a field of view, and rejects angles outside (0, pi). matrices returns Cesium's view and projection matrices, ECEF to eye in 3D, the only mode the app runs. The conformance run checks both on Cesium.
This commit is contained in:
1 parent
e3a850bc9c
commit
28b5de7196
4 files changed
+60
-4
No files matched your search
@@ -91,7 +91,10 @@ export function createCesiumCamera({ scene, camera, report, widget }) {
|
||||
report,
|
||||
});
|
||||
removers.push(
|
||||
scene.postUpdate.addEventListener(() => cameraEvents.stepChanged()),
|
||||
scene.postUpdate.addEventListener(() => {
|
||||
applyFov();
|
||||
cameraEvents.stepChanged();
|
||||
}),
|
||||
camera.moveStart.addEventListener(() => cameraEvents.emit('moveStart')),
|
||||
camera.moveEnd.addEventListener(() => cameraEvents.emit('moveEnd')),
|
||||
);
|
||||
@@ -176,6 +179,23 @@ export function createCesiumCamera({ scene, camera, report, widget }) {
|
||||
return handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* The vertical field of view `setFov` asked for, held across resizes:
|
||||
* Cesium's `fov` is the wider of the two angles (the horizontal one when
|
||||
* the view is wider than tall), and it keeps that one when the aspect
|
||||
* changes. Before the first resize, and on a frustum without a field of
|
||||
* view, it waits.
|
||||
*/
|
||||
let heldFovy = null;
|
||||
function applyFov() {
|
||||
const frustum = camera.frustum;
|
||||
const aspect = frustum?.aspectRatio;
|
||||
if (heldFovy === null || !('fov' in frustum) || !(aspect > 0)) return;
|
||||
const fov =
|
||||
aspect > 1 ? 2 * Math.atan(Math.tan(heldFovy / 2) * aspect) : heldFovy;
|
||||
if (frustum.fov !== fov) frustum.fov = fov;
|
||||
}
|
||||
|
||||
const cameraPort = {
|
||||
on: (event, cb, options) => cameraEvents.on(event, cb, options),
|
||||
onCommand: (cb) => commandHooks.on(cb),
|
||||
@@ -288,6 +308,24 @@ export function createCesiumCamera({ scene, camera, report, widget }) {
|
||||
else camera.zoomIn(metres);
|
||||
scene.requestRender();
|
||||
},
|
||||
setFov({ vertical }) {
|
||||
// Cesium would take a bad angle and draw a garbage projection.
|
||||
if (!(vertical > 0 && vertical < Math.PI))
|
||||
throw new RangeError(`no vertical field of view of ${vertical}`);
|
||||
heldFovy = vertical;
|
||||
applyFov();
|
||||
scene.requestRender();
|
||||
},
|
||||
// The scene's own frame: ECEF in 3D, the only mode the app runs (Cesium's
|
||||
// 2D and Columbus view frames are projected map coordinates).
|
||||
matrices() {
|
||||
return {
|
||||
view: Float64Array.from(Cesium.Matrix4.toArray(camera.viewMatrix)),
|
||||
projection: Float64Array.from(
|
||||
Cesium.Matrix4.toArray(camera.frustum.projectionMatrix),
|
||||
),
|
||||
};
|
||||
},
|
||||
viewRectangle() {
|
||||
const rect = camera.computeViewRectangle(Cesium.Ellipsoid.WGS84);
|
||||
if (!rect) return null;
|
||||
|
||||
Reference in new issue
Block a user