mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 18:22:25 +00:00
fix(cockpit): the orbital view gives the field of view back on exit
Cesium's fov was saved and put back when the orbital view closed, so a later resize or rotation kept Cesium's own behaviour. The exit held the saved vertical angle through setFov instead, which the camera port kept for the rest of the session: rotated to portrait, the view stayed zoomed in. setFov(null) gives the field of view back: Cesium's fov as it was before the first hold, the stub's own angle.
This commit is contained in:
1 parent
03a7d8827a
commit
4a781f0480
6 files changed
+52
-12
No files matched your search
@@ -240,6 +240,8 @@ export function createCesiumCamera({
|
||||
* view, it waits.
|
||||
*/
|
||||
let heldFovy = null;
|
||||
/** Cesium's own `fov` before the first hold, put back on release. */
|
||||
let ownFov = null;
|
||||
function applyFov() {
|
||||
const frustum = camera.frustum;
|
||||
const aspect = frustum?.aspectRatio;
|
||||
@@ -388,10 +390,22 @@ export function createCesiumCamera({
|
||||
camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
|
||||
scene.requestRender();
|
||||
},
|
||||
setFov({ vertical }) {
|
||||
setFov(fov) {
|
||||
const frustum = camera.frustum;
|
||||
if (fov === null) {
|
||||
// Given back: Cesium's own angle again, kept as it keeps it.
|
||||
if (heldFovy !== null && ownFov !== null && 'fov' in frustum)
|
||||
frustum.fov = ownFov;
|
||||
heldFovy = null;
|
||||
ownFov = null;
|
||||
scene.requestRender();
|
||||
return;
|
||||
}
|
||||
const { vertical } = fov;
|
||||
// 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}`);
|
||||
if (heldFovy === null && 'fov' in frustum) ownFov = frustum.fov;
|
||||
heldFovy = vertical;
|
||||
applyFov();
|
||||
scene.requestRender();
|
||||
|
||||
Reference in new issue
Block a user