mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 16:52:20 +00:00
Follow framing has one implementation: followViewFrom reads the camera port and calls followOffsetFitting
This commit is contained in:
1 parent
561cd8f1cf
commit
16c8936d70
1 file changed
+10
-24
+10
-24
@@ -7,39 +7,25 @@
|
|||||||
* one without (a line) is zoomed to at once instead. It runs only while the
|
* one without (a line) is zoomed to at once instead. It runs only while the
|
||||||
* renderer's own double-click follow is on (a tool can hold it off).
|
* renderer's own double-click follow is on (a tool can hold it off).
|
||||||
*/
|
*/
|
||||||
import { WGS84 } from '../geo/ellipsoid.js';
|
import { followOffsetFitting } from '../geo/frames.js';
|
||||||
import { offsetFromHeadingPitchRange } from '../geo/frames.js';
|
|
||||||
import { findCamera, findQuery } from '../render/rendererOf.js';
|
import { findCamera, findQuery } from '../render/rendererOf.js';
|
||||||
|
|
||||||
/** The range the default renderer frames a sphere of no size from. */
|
|
||||||
const MINIMUM_FIT_RANGE_M = 100;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Where the camera frames a part it starts following, as the default
|
* Where the camera frames a part it starts following: `followOffsetFitting`
|
||||||
* renderer framed an entity it started following with no view of its own:
|
* with the camera port's field of view and zoom limits.
|
||||||
* looking at the bounds' centre, heading north, pitched down 45° (steeper
|
|
||||||
* far from the ground), at the range that fits the bounds in view, within
|
|
||||||
* the camera's zoom limits. Returned as the eye's offset from the centre,
|
|
||||||
* east-north-up there; `at` is where the part stands.
|
|
||||||
* @param {{center: {x: number, y: number, z: number}, radius: number}} sphere
|
* @param {{center: {x: number, y: number, z: number}, radius: number}} sphere
|
||||||
* @param {{x: number, y: number, z: number}} at
|
* @param {{x: number, y: number, z: number}} at
|
||||||
* @param {object} camera The camera port.
|
* @param {object} camera The camera port.
|
||||||
*/
|
*/
|
||||||
export function followViewFrom(sphere, at, camera) {
|
export function followViewFrom(sphere, at, camera) {
|
||||||
const pose = camera.pose?.();
|
const pose = camera.pose?.();
|
||||||
const fovy = Number.isFinite(pose?.fovy) ? pose.fovy : Math.PI / 3;
|
const { minDistance, maxDistance } = camera.controls ?? {};
|
||||||
const aspect = Number.isFinite(pose?.aspectRatio) ? pose.aspectRatio : 1;
|
return followOffsetFitting(sphere, at, {
|
||||||
const tanPhi = Math.tan(fovy / 2);
|
fovy: pose?.fovy,
|
||||||
const tanTheta = aspect * tanPhi;
|
aspectRatio: pose?.aspectRatio,
|
||||||
let range =
|
minDistance,
|
||||||
sphere.radius === 0
|
maxDistance,
|
||||||
? MINIMUM_FIT_RANGE_M
|
});
|
||||||
: Math.max(sphere.radius / tanTheta, sphere.radius / tanPhi);
|
|
||||||
const { minDistance = 0, maxDistance = Infinity } = camera.controls ?? {};
|
|
||||||
range = Math.min(Math.max(range, minDistance), maxDistance);
|
|
||||||
const factor =
|
|
||||||
2 - 1 / Math.max(1, Math.hypot(at.x, at.y, at.z) / WGS84.radii.x);
|
|
||||||
return offsetFromHeadingPitchRange(0, (-Math.PI / 4) * factor, range);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user