mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 00:32:21 +00:00
feat(selection): selecting a contact keeps its size and the camera's view: aircraft, vessels, trains and transit vehicles keep their form and size when selected (colour only); a click follows from the camera's own distance and angle, the contact gliding to the centre over one second (FollowTarget transitionS, shared rule render/camera/followTransition, conformance camera.follow.transition)
This commit is contained in:
1 parent
e3865f462f
commit
7a61bf04a0
52 files changed
+1648
-891
No files matched your search
@@ -1,7 +1,17 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import * as Cesium from 'cesium';
|
||||
import { trackedModelScaleForPixelCap } from './trackedCamera.js';
|
||||
import { keptViewFrom } from './trackedCamera.js';
|
||||
import {
|
||||
distance,
|
||||
eastNorthUp,
|
||||
framePoint,
|
||||
frameVector,
|
||||
fromDegrees,
|
||||
magnitude,
|
||||
normalize,
|
||||
scale,
|
||||
} from '../geo/index.js';
|
||||
import { clampFollowEye as clampTrackedCameraPosition } from '../render/cesium/follow.js';
|
||||
|
||||
test('tracked camera origin crossing returns to the prior side at the minimum range', () => {
|
||||
@@ -12,7 +22,9 @@ test('tracked camera origin crossing returns to the prior side at the minimum ra
|
||||
const previous = new Cesium.Cartesian3(0, -1000, 600);
|
||||
assert.equal(clampTrackedCameraPosition(camera, previous, 150), true);
|
||||
assert.ok(Cesium.Cartesian3.dot(camera.position, previous) > 0);
|
||||
assert.ok(Math.abs(Cesium.Cartesian3.magnitude(camera.position) - 150) < 1e-9);
|
||||
assert.ok(
|
||||
Math.abs(Cesium.Cartesian3.magnitude(camera.position) - 150) < 1e-9,
|
||||
);
|
||||
});
|
||||
|
||||
test('tracked camera clamps a too-close approach along the current sight line', () => {
|
||||
@@ -41,29 +53,24 @@ test('tracked camera leaves a safe approach unchanged', () => {
|
||||
assert.deepEqual(camera.position, before);
|
||||
});
|
||||
|
||||
test('tracked model keeps calibrated scale when it projects below the pixel cap', () => {
|
||||
const scale = trackedModelScaleForPixelCap({
|
||||
baseScale: 24,
|
||||
nativeRadiusM: 1.43,
|
||||
rangeM: 1000,
|
||||
viewportHeightPx: 800,
|
||||
fovyRad: Math.PI / 3,
|
||||
maximumPixelSize: 104,
|
||||
});
|
||||
assert.equal(scale, 24);
|
||||
test('a kept view follows from the eye: its own view direction at its own range', () => {
|
||||
const at = fromDegrees(-122.2, 37.7, 600);
|
||||
const enu = eastNorthUp(at);
|
||||
// An eye 2 km off, looking a little beside the target.
|
||||
const eye = framePoint(enu, { x: 300, y: -1600, z: 1100 });
|
||||
const direction = normalize(frameVector(enu, { x: -250, y: 1600, z: -1150 }));
|
||||
const viewFrom = keptViewFrom({ position: eye, direction }, at);
|
||||
assert.ok(Math.abs(magnitude(viewFrom) - distance(eye, at)) < 1e-6);
|
||||
// Followed from there, the eye looks the way it looked.
|
||||
const followedLook = normalize(frameVector(enu, scale(viewFrom, -1)));
|
||||
assert.ok(distance(followedLook, direction) < 1e-12);
|
||||
});
|
||||
|
||||
test('tracked model shrinks smoothly when close enough to exceed the pixel cap', () => {
|
||||
const scale = trackedModelScaleForPixelCap({
|
||||
baseScale: 24,
|
||||
nativeRadiusM: 1.43,
|
||||
rangeM: 150,
|
||||
viewportHeightPx: 800,
|
||||
fovyRad: Math.PI / 3,
|
||||
maximumPixelSize: 104,
|
||||
});
|
||||
const focalLengthPx = 800 / (2 * Math.tan(Math.PI / 6));
|
||||
const projectedDiameterPx = (2 * 1.43 * scale * focalLengthPx) / 150;
|
||||
assert.ok(scale < 24);
|
||||
assert.ok(Math.abs(projectedDiameterPx - 104) < 1e-9);
|
||||
test('a kept view needs an eye apart from the target', () => {
|
||||
const at = fromDegrees(-122.2, 37.7, 600);
|
||||
assert.equal(keptViewFrom(null, at), null);
|
||||
assert.equal(
|
||||
keptViewFrom({ position: at, direction: { x: 0, y: 0, z: -1 } }, at),
|
||||
null,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user