mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 18:52:18 +00:00
Open the orbital cockpit on Navara
The orbital view, sensor zoom, ground focus and satellite switching run on the contract: camera.setFovy sets the vertical lens on both engines and the fake, including sub-degree angles on Navara through the guarded core bridge, with a contract check and mutants. Cesium's imagery look-ahead stays inside its adapter. KNOWN-ISSUES keeps the two parts Navara still lacks: imagery prefetch for the orbital view and finest-detail meshes for the ship bridge waterline.
This commit is contained in:
1 parent
6727aaadcd
commit
aac65c21c4
23 files changed
+479
-234
No files matched your search
@@ -19,7 +19,6 @@
|
||||
import * as geo from '../../geo/index.js';
|
||||
import { createEngineEvent } from '../contract.js';
|
||||
import {
|
||||
cesiumFovy,
|
||||
headingPitchRoll,
|
||||
horizonVisible,
|
||||
lookAtFrame,
|
||||
@@ -83,6 +82,7 @@ function posesNear(a, b, distance, angle) {
|
||||
* stop: () => void,
|
||||
* size: () => { width: number, height: number },
|
||||
* requestFrame: () => void,
|
||||
* setFovy?: (radians: number) => void,
|
||||
* suspendCameraInputs?: () => () => void,
|
||||
* },
|
||||
* clock?: { now: () => number, setTimeout: Function, clearTimeout: Function },
|
||||
@@ -120,6 +120,13 @@ export function createCameraModel({
|
||||
...orientationVectors(position, 0, -math.PI_OVER_TWO, 0),
|
||||
};
|
||||
})();
|
||||
let fov = Math.PI / 3;
|
||||
const fovy = () => {
|
||||
const { width, height } = port.size();
|
||||
return width > height
|
||||
? 2 * Math.atan((Math.tan(fov / 2) * height) / width)
|
||||
: fov;
|
||||
};
|
||||
let transform = [...matrix4.IDENTITY];
|
||||
let percentageChanged = DEFAULT_PERCENTAGE_CHANGED;
|
||||
let flight = null;
|
||||
@@ -139,7 +146,7 @@ export function createCameraModel({
|
||||
|
||||
const view = () => {
|
||||
const { width, height } = port.size();
|
||||
return { ...state, fovy: cesiumFovy(width, height), width, height };
|
||||
return { ...state, fovy: fovy(), width, height };
|
||||
};
|
||||
|
||||
// A programmatic pose: exact here, pushed to Navara for drawing.
|
||||
@@ -154,11 +161,7 @@ export function createCameraModel({
|
||||
const { width, height } = port.size();
|
||||
const position =
|
||||
'west' in destination
|
||||
? rectangleViewPosition(
|
||||
destination,
|
||||
cesiumFovy(width, height),
|
||||
width / height,
|
||||
)
|
||||
? rectangleViewPosition(destination, fovy(), width / height)
|
||||
: copy3(destination);
|
||||
if (orientation && 'direction' in orientation)
|
||||
return {
|
||||
@@ -311,6 +314,17 @@ export function createCameraModel({
|
||||
const livePosition = cartesian3.create();
|
||||
|
||||
const camera = {
|
||||
setFovy(radians) {
|
||||
if (!Number.isFinite(radians) || radians <= 0 || radians >= Math.PI)
|
||||
throw new RangeError('Field of view must be between 0 and PI');
|
||||
const { width, height } = port.size();
|
||||
fov =
|
||||
width > height
|
||||
? 2 * Math.atan((Math.tan(radians / 2) * width) / height)
|
||||
: radians;
|
||||
port.setFovy?.(radians);
|
||||
port.requestFrame();
|
||||
},
|
||||
get livePosition() {
|
||||
return cartesian3.clone(state.position, livePosition);
|
||||
},
|
||||
@@ -356,8 +370,7 @@ export function createCameraModel({
|
||||
transform = [...matrix4.IDENTITY];
|
||||
const { width, height } = port.size();
|
||||
const range =
|
||||
options.range ||
|
||||
sphereRange(sphere.radius, cesiumFovy(width, height), width / height);
|
||||
options.range || sphereRange(sphere.radius, fovy(), width / height);
|
||||
const frame = geo.transforms.eastNorthUpToFixedFrame(
|
||||
sphere.center,
|
||||
WGS84,
|
||||
|
||||
@@ -114,10 +114,13 @@ export function createNavaraEngine(
|
||||
width: canvas.clientWidth,
|
||||
height: canvas.clientHeight,
|
||||
});
|
||||
const applyFovy = (radians) => {
|
||||
if (hooks.setCameraFovy) hooks.setCameraFovy(radians);
|
||||
else view.camera.fov = math.toDegrees(radians);
|
||||
};
|
||||
const matchFov = () => {
|
||||
const { width, height } = size();
|
||||
if (width > 0 && height > 0)
|
||||
view.camera.fov = math.toDegrees(cesiumFovy(width, height));
|
||||
if (width > 0 && height > 0) applyFovy(cesiumFovy(width, height));
|
||||
};
|
||||
matchFov();
|
||||
|
||||
@@ -131,6 +134,7 @@ export function createNavaraEngine(
|
||||
stop: () => view.setCamera({}),
|
||||
size,
|
||||
requestFrame: () => view.forceUpdate(),
|
||||
setFovy: applyFovy,
|
||||
suspendCameraInputs: () => input.input.suspendCameraInputs(),
|
||||
},
|
||||
...(clock ? { clock } : {}),
|
||||
@@ -201,7 +205,9 @@ export function createNavaraEngine(
|
||||
model.afterFrame();
|
||||
frames.postRender.raiseEvent(time);
|
||||
},
|
||||
resize: () => matchFov(),
|
||||
resize: () => {
|
||||
applyFovy(model.camera.pose().fovy);
|
||||
},
|
||||
};
|
||||
for (const [name, handler] of Object.entries(handlers))
|
||||
view.on(name, handler);
|
||||
|
||||
@@ -769,3 +769,17 @@ test('a wheel during a flight with the camera inputs suspended does not cancel i
|
||||
assert.equal(engine.input.cameraInputsEnabled(), true);
|
||||
engine.destroy();
|
||||
});
|
||||
|
||||
test('optical zoom reaches the drawn camera and survives a resize', () => {
|
||||
const { engine, view } = setup();
|
||||
engine.camera.setFovy(0.2);
|
||||
near(view.camera.fovs.at(-1), geo.math.toDegrees(0.2), 1e-12, 'drawn fovy');
|
||||
near(engine.camera.pose().fovy, 0.2, 1e-12, 'projector fovy');
|
||||
const fov = 2 * Math.atan(Math.tan(0.1) * engine.camera.pose().aspectRatio);
|
||||
view.canvas.clientWidth = 600;
|
||||
view.canvas.clientHeight = 900;
|
||||
view.emit('resize');
|
||||
near(view.camera.fovs.at(-1), geo.math.toDegrees(fov), 1e-12, 'resized fovy');
|
||||
near(engine.camera.pose().fovy, fov, 1e-12, 'resized projector');
|
||||
engine.destroy();
|
||||
});
|
||||
@@ -233,11 +233,25 @@ export function featureChangeQueue(view) {
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Navara's public camera.fov setter drops angles below one degree, although
|
||||
* the core supports them. Optical zoom needs the same frustum for drawing,
|
||||
* tile selection and picking. Upstream ask: accept every positive FOV.
|
||||
*/
|
||||
export function setCameraFovy(view, radians) {
|
||||
requireMember(
|
||||
'view._core.setFrustum',
|
||||
typeof view?._core?.setFrustum === 'function',
|
||||
);
|
||||
view._core.setFrustum((radians * 180) / Math.PI, undefined, undefined);
|
||||
}
|
||||
|
||||
/** The hooks createNavaraEngine takes. */
|
||||
export const navaraHooks = (view) => {
|
||||
assertNavaraInternals(view);
|
||||
return {
|
||||
retainTileGeometry,
|
||||
setCameraFovy: (radians) => setCameraFovy(view, radians),
|
||||
tileRoots: () => tileRoots(view),
|
||||
isIdle: () => isIdle(view),
|
||||
dropOrphanFeatureChanges: () =>
|
||||
|
||||
@@ -13,7 +13,8 @@ const loader = registerHooks({
|
||||
: next(specifier, context);
|
||||
},
|
||||
});
|
||||
const { navaraHooks, forEachLuminanceUniform } = await import('./internals.js');
|
||||
const { navaraHooks, forEachLuminanceUniform, setCameraFovy } =
|
||||
await import('./internals.js');
|
||||
loader.deregister();
|
||||
const { ModelMesh } = await import(sdkStub);
|
||||
|
||||
@@ -201,3 +202,31 @@ test('feature changes of a deleted vector layer leave the queue; live ones stay'
|
||||
0,
|
||||
);
|
||||
});
|
||||
|
||||
test('optical zoom below one degree reaches the native frustum', async () => {
|
||||
const { initSync, Core } = await import('@navaramap/engine');
|
||||
initSync({
|
||||
module: readFileSync(
|
||||
new URL(
|
||||
'../../../node_modules/@navaramap/engine/navara_wasm_bg.wasm',
|
||||
import.meta.url,
|
||||
),
|
||||
),
|
||||
});
|
||||
const core = new Core('optical-zoom-test');
|
||||
core.start();
|
||||
core.resize(1280, 800, 1);
|
||||
core.update(0);
|
||||
try {
|
||||
const view = { _core: core };
|
||||
setCameraFovy(view, 0.0002);
|
||||
core.update(16);
|
||||
assert.ok(Math.abs(core.getCameraFOV() - 0.0002) < 1e-12);
|
||||
setCameraFovy(view, Math.PI / 3);
|
||||
core.update(32);
|
||||
assert.ok(Math.abs(core.getCameraFOV() - Math.PI / 3) < 1e-12);
|
||||
assert.throws(() => setCameraFovy({}, 0.0002), /setFrustum/);
|
||||
} finally {
|
||||
core.free();
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user