mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 02:32:18 +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,5 +1,9 @@
|
||||
import { findCamera } from '../../render/rendererOf.js';
|
||||
import { FOLLOW_MIN_RANGE_M } from '../../data/trackedCamera.js';
|
||||
import {
|
||||
FOLLOW_MIN_RANGE_M,
|
||||
keptViewFrom,
|
||||
SELECTION_FOLLOW_TRANSITION_S,
|
||||
} from '../../data/trackedCamera.js';
|
||||
import { copyInto, lerpInto } from '../../geo/vector.js';
|
||||
import {
|
||||
FOLLOW_HANDOVER_MS,
|
||||
@@ -14,12 +18,14 @@ export const RAIL_FOCUS_KIND = 'train';
|
||||
* The selected train's camera.
|
||||
*
|
||||
* A moving train is followed as a tracked aircraft is: the layer hands the
|
||||
* camera port a follow target that stands on the train's marker, framed by
|
||||
* the shared world-focus framing for a train and never closer than the
|
||||
* aircraft's readable minimum, so the camera rides with the train and the
|
||||
* user still orbits and zooms around it. Any other train gets one fly-to
|
||||
* through the shared world-focus request, as a vessel does. Inside the
|
||||
* Cockpit that request is refused with its toast.
|
||||
* camera port a follow target that stands on the train's marker, seen from
|
||||
* where the camera is (its distance and angle kept, the train sliding to
|
||||
* the centre) and never closer than the aircraft's readable minimum, so the
|
||||
* camera rides with the train and the user still orbits and zooms around it.
|
||||
* Any other train gets one fly-to through the shared world-focus request,
|
||||
* keeping the view as a vessel's does. Inside the Cockpit that request is
|
||||
* refused with its toast. Without a view to keep (no camera pose), the
|
||||
* shared world-focus framing for a train frames it.
|
||||
*
|
||||
* The follow lets go when the train is deselected (an empty click, Escape, its
|
||||
* category hidden, the train leaving its feed, the layer turned off), when
|
||||
@@ -106,7 +112,9 @@ export function createFollow({ state, services, parts }) {
|
||||
}
|
||||
|
||||
function startFollow(entry, position, port) {
|
||||
const offset = railFollowOffset(camera.framing, port.pose()?.heading);
|
||||
const offset =
|
||||
keptViewFrom(port.pose(), position) ??
|
||||
railFollowOffset(camera.framing, port.pose()?.heading);
|
||||
const follow = {
|
||||
key: entry.key,
|
||||
target: null,
|
||||
@@ -119,8 +127,9 @@ export function createFollow({ state, services, parts }) {
|
||||
position: () => followedPosition(follow),
|
||||
frame: 'enu',
|
||||
viewFrom: { x: offset.x, y: offset.y, z: offset.z },
|
||||
// Framed exactly once, as a tracked aircraft is, and never closer.
|
||||
// Framed once, as a tracked aircraft is, and never closer.
|
||||
minRange: FOLLOW_MIN_RANGE_M,
|
||||
transitionS: SELECTION_FOLLOW_TRANSITION_S,
|
||||
selectionOrigin: 'user',
|
||||
};
|
||||
state._follow = follow;
|
||||
@@ -158,6 +167,7 @@ export function createFollow({ state, services, parts }) {
|
||||
id: entry.key,
|
||||
label: label || entry.key,
|
||||
position: { x: position.x, y: position.y, z: position.z },
|
||||
keepView: true,
|
||||
}) === true
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,11 @@
|
||||
// distance while the rest of the network hides as before.
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { FOLLOW_MIN_RANGE_M } from '../../data/trackedCamera.js';
|
||||
import {
|
||||
FOLLOW_MIN_RANGE_M,
|
||||
keptViewFrom,
|
||||
SELECTION_FOLLOW_TRANSITION_S,
|
||||
} from '../../data/trackedCamera.js';
|
||||
import { fromDegrees } from '../../geo/ellipsoid.js';
|
||||
import { distance } from '../../geo/vector.js';
|
||||
import {
|
||||
@@ -147,19 +151,24 @@ test('selecting a moving train hands the camera a follow target that rides on it
|
||||
const key = await bringToMotion(app, 'mbta-rail', 'T1', BOSTON);
|
||||
app.moveCameraQuietly({ heading: Math.PI / 4 });
|
||||
const cancelled = app.camera.flightsCancelled;
|
||||
const pose = app.camera.pose();
|
||||
const at = { ...app.entry(key).marker.position };
|
||||
app.parts().selection.selectAndFocusTrain(key);
|
||||
|
||||
const target = app.camera.followed;
|
||||
assert.ok(target, 'the camera follows a target');
|
||||
assert.equal(app.focusRequests.length, 0, 'no one-shot fly-to');
|
||||
assert.equal(app.camera.flightsCancelled, cancelled + 1);
|
||||
// Framed as the aircraft are (exactly once, never closer than their
|
||||
// minimum), from the train's own framing seen along the camera's heading.
|
||||
// Framed as the aircraft are (once, never closer than their minimum),
|
||||
// from where the camera already is: its distance and angle kept, the train
|
||||
// gliding to the centre.
|
||||
assert.equal(app.follows.length, 1);
|
||||
assert.equal(target.frame, 'enu');
|
||||
assert.equal(target.minRange, FOLLOW_MIN_RANGE_M);
|
||||
const expected = railFollowOffset(WORLD_FOCUS_FRAMING.train, Math.PI / 4);
|
||||
assert.equal(target.transitionS, SELECTION_FOLLOW_TRANSITION_S);
|
||||
const expected = keptViewFrom(pose, at);
|
||||
assert.ok(Math.abs(target.viewFrom.x - expected.x) < 1e-6);
|
||||
assert.ok(Math.abs(target.viewFrom.y - expected.y) < 1e-6);
|
||||
assert.ok(Math.abs(target.viewFrom.z - expected.z) < 1e-6);
|
||||
|
||||
// The target stands where the marker is drawn, frame after frame.
|
||||
|
||||
@@ -152,7 +152,6 @@ export const TRACK_MAX_GRADE = 0.05;
|
||||
export const TRACK_SETTLE_MPS = 0.5;
|
||||
export const TRACK_SNAP_M = 2_000;
|
||||
export const MARKER_PIXEL_SIZE = 18;
|
||||
export const SELECTED_PIXEL_SIZE = 28;
|
||||
export const SELECTED_CARD_REFRESH_MS = 250;
|
||||
/** While a train is selected, every other train is drawn at this opacity. */
|
||||
export const UNSELECTED_TRAIN_ALPHA = 0.35;
|
||||
|
||||
@@ -34,7 +34,6 @@ import {
|
||||
FLOOR_WARM_MAX_DIST_KM,
|
||||
MARKER_PIXEL_SIZE,
|
||||
RAIL_CATEGORY_COLORS,
|
||||
SELECTED_PIXEL_SIZE,
|
||||
UNSELECTED_TRAIN_ALPHA,
|
||||
} from './policy.js';
|
||||
import { placeOnPath } from './pathBinding.js';
|
||||
@@ -736,11 +735,10 @@ export function createRendering({ state, services, parts }) {
|
||||
|
||||
function paint(entry) {
|
||||
if (!entry.marker) return;
|
||||
const selected = entry.key === state._selectedKey;
|
||||
const size = selected ? SELECTED_PIXEL_SIZE : MARKER_PIXEL_SIZE;
|
||||
// Selection dims the other trains; the selected one keeps its size.
|
||||
entry.marker.image = spriteFor(entry.category, entry.railMode);
|
||||
entry.marker.width = size;
|
||||
entry.marker.height = size;
|
||||
entry.marker.width = MARKER_PIXEL_SIZE;
|
||||
entry.marker.height = MARKER_PIXEL_SIZE;
|
||||
entry.marker.color = tintFor(entry);
|
||||
entry.marker.show = markerShown(entry);
|
||||
touch(entry);
|
||||
|
||||
Reference in new issue
Block a user