mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-20 10:12:18 +00:00
fix(cctv): a count click yields to what is on top and keeps its group in frame
- A count click stands aside when an overlay label or another layer's card already took the click, and CCTV now claims a count click in the shared pick registry, so the flights layer no longer reads it as an empty-map click and keeps tracking its aircraft. - The flight to a group halves the distance only while the group stays in frame; otherwise it flies to the nearest ground cell of the group, so a tilted click no longer ends with no camera on screen. - Counts hidden under the HUD no longer push the active icon aside, and a lone camera that would move a merged count under the HUD leaves the original count and its icon as they were. - Cameras on one mount are spread before counts merge, so a spread icon no longer slides under a neighbouring count. - The ground module comment says how a camera without a batch height takes the drawn terrain.
This commit is contained in:
1 parent
2b7a6b0c63
commit
f6982dc934
16 files changed
+452
-70
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { distance } from '../../geo/vector.js';
|
||||
import { rangeForBoundingSphere } from '../../data/cameraFraming.js';
|
||||
import { isFollowing } from '../../data/followed.js';
|
||||
import { cellBounds } from '../../data/cctvCellCounts.js';
|
||||
import { cellBounds, cellCenter } from '../../data/cctvCellCounts.js';
|
||||
import { CCTV_FOCUS_RESULT, VIEW_CELL_PX, VIEW_MIN_CELL_M } from './policy.js';
|
||||
import { cameraOf, canvasOf } from '../../render/rendererOf.js';
|
||||
|
||||
@@ -131,6 +131,20 @@ export function createNavigation({
|
||||
return CCTV_FOCUS_RESULT.FOCUSED;
|
||||
}
|
||||
|
||||
/** The ground cell of a group nearest the eye, or the group itself if unmerged. */
|
||||
function nearestPart(cell, eye) {
|
||||
let nearest = cell;
|
||||
let best = Infinity;
|
||||
for (const part of cell.parts ?? []) {
|
||||
const d = distance(eye, cellCenter(part));
|
||||
if (d < best) {
|
||||
best = d;
|
||||
nearest = part;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
/** Frame a group's padded bounds from above, including coincident mounts. */
|
||||
function zoomToCell(cell) {
|
||||
const viewer = layerState._viewer;
|
||||
@@ -140,18 +154,23 @@ export function createNavigation({
|
||||
const tanHalfY = Math.tan((pose.fovy || Math.PI / 3) / 2);
|
||||
const canvas = canvasOf(viewer);
|
||||
const height = canvas?.clientHeight || canvas?.height || 1;
|
||||
const bounds = cellBounds(cell);
|
||||
// Half the range where cells stop grouping, so even coincident mounts split.
|
||||
const closeRange =
|
||||
(VIEW_MIN_CELL_M * height) / (4 * VIEW_CELL_PX * tanHalfY);
|
||||
const fitRange = (bounds) =>
|
||||
Math.max(closeRange, rangeForBoundingSphere(viewer, bounds.radius));
|
||||
// Approach long groups in halves so every click gets closer.
|
||||
const halfway = pose.position
|
||||
? distance(pose.position, bounds.center) / 2
|
||||
: Infinity;
|
||||
const range = Math.min(
|
||||
halfway,
|
||||
Math.max(closeRange, rangeForBoundingSphere(viewer, bounds.radius)),
|
||||
);
|
||||
const halfway = (bounds) =>
|
||||
pose.position ? distance(pose.position, bounds.center) / 2 : Infinity;
|
||||
let bounds = cellBounds(cell);
|
||||
const fit = fitRange(bounds);
|
||||
let range = Math.min(halfway(bounds), fit);
|
||||
// If the group exceeds the narrower side of the frame, approach its nearest part.
|
||||
const tanHalf = tanHalfY * Math.min(1, pose.aspectRatio || 1);
|
||||
if (range < fit && range * tanHalf < bounds.radius) {
|
||||
bounds = cellBounds(nearestPart(cell, pose.position));
|
||||
range = Math.min(halfway(bounds), fitRange(bounds));
|
||||
}
|
||||
camera.flyToBounds(bounds, {
|
||||
offset: { heading: 0, pitch: -Math.PI / 2, range },
|
||||
durationS: 1.2,
|
||||
|
||||
Reference in new issue
Block a user