mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
refactor(camera): use the globe engine
The startup fly-in, orbit, world-target focus, the arrival ground guard, arrival ownership, camera sensitivity claims, landmark/viewport/globe flights and place search (with its view bias and near-view recovery) take the globe engine. Callers that still hold a viewer (voice, layers until phase 1c) reach the same engine through engineFromViewer, and arrival ownership is keyed by the engine whichever one a caller names. The ground guard yields on camera.commanded instead of patching the viewer camera itself; on Cesium that event hooks the same command methods and tracking changes, so direct Cesium callers still end it. Landmark framing reads the frustum fov from the pose's fovy and aspectRatio. Tests that built viewer doubles now run on the fake engine (or on the Cesium engine over the same double), with the same expectations.
This commit is contained in:
1 parent
a3e929870d
commit
16e63f4c50
19 files changed
+601
-215
No files matched your search
+20
-16
@@ -1,5 +1,5 @@
|
||||
import * as Cesium from 'cesium';
|
||||
import * as geo from './geo/index.js';
|
||||
import { engineFromViewer } from './globe/cesium/engineFromViewer.js';
|
||||
import {
|
||||
holdContinuousRender,
|
||||
releaseContinuousRender,
|
||||
@@ -7,12 +7,16 @@ import {
|
||||
|
||||
/**
|
||||
* OrbitController — smooth orbit around a target point.
|
||||
* Uses scene.preRender for frame-rate-independent 60fps updates.
|
||||
* Uses the engine's preRender frames for frame-rate-independent updates.
|
||||
* Toggle with O key; auto-stops on POI/city change.
|
||||
*/
|
||||
export class OrbitController {
|
||||
constructor(viewer) {
|
||||
this.viewer = viewer;
|
||||
/**
|
||||
* @param {import('./globe/contract.js').GlobeEngine | object} engine The
|
||||
* globe engine, or a viewer registered for one.
|
||||
*/
|
||||
constructor(engine) {
|
||||
this.engine = engineFromViewer(engine);
|
||||
this.active = false;
|
||||
this.target = null;
|
||||
this.radius = 500;
|
||||
@@ -24,14 +28,15 @@ export class OrbitController {
|
||||
|
||||
/**
|
||||
* Start orbiting around a target position.
|
||||
* @param {Cesium.Cartesian3} targetCartesian - The point to orbit around
|
||||
* @param {{x: number, y: number, z: number}} targetCartesian - The point to orbit around
|
||||
* @param {object} options
|
||||
* @param {number} options.radius - Distance from target in meters
|
||||
* @param {number} options.pitch - Tilt angle in degrees (negative = looking down)
|
||||
* @param {number} options.speed - Degrees per second (default 6)
|
||||
*/
|
||||
start(targetCartesian, options = {}) {
|
||||
if (!targetCartesian) return;
|
||||
if (!targetCartesian || !this.engine) return;
|
||||
const { camera, frames } = this.engine;
|
||||
|
||||
this.target = targetCartesian;
|
||||
this.radius = options.radius || this.radius;
|
||||
@@ -43,10 +48,10 @@ export class OrbitController {
|
||||
holdContinuousRender('camera-orbit');
|
||||
|
||||
// Start from the camera's current heading for seamless transition
|
||||
this.angle = this.viewer.camera.heading;
|
||||
this.angle = camera.pose().heading;
|
||||
|
||||
let lastTime = Date.now();
|
||||
this._removeListener = this.viewer.scene.preRender.addEventListener(() => {
|
||||
this._removeListener = frames.preRender.addEventListener(() => {
|
||||
if (!this.active) return;
|
||||
|
||||
const now = Date.now();
|
||||
@@ -55,12 +60,11 @@ export class OrbitController {
|
||||
|
||||
this.angle += this.speed * dt;
|
||||
|
||||
const hpr = new Cesium.HeadingPitchRange(
|
||||
this.angle,
|
||||
geo.math.toRadians(this.pitch),
|
||||
this.radius,
|
||||
);
|
||||
this.viewer.camera.lookAt(this.target, hpr);
|
||||
camera.lookAt(this.target, {
|
||||
heading: this.angle,
|
||||
pitch: geo.math.toRadians(this.pitch),
|
||||
range: this.radius,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -75,12 +79,12 @@ export class OrbitController {
|
||||
this._removeListener = null;
|
||||
}
|
||||
// Unlock camera for free interaction
|
||||
this.viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
|
||||
this.engine?.camera.release();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle orbit on/off.
|
||||
* @param {Cesium.Cartesian3} targetCartesian - Required when starting
|
||||
* @param {{x: number, y: number, z: number}} targetCartesian - Required when starting
|
||||
* @param {object} options - Passed to start()
|
||||
* @returns {boolean} Whether orbit is now active
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user