tobogganSe connecter

starfleet-ui

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

30 lignes · 1424 octetsBrut · Historique
1/**
2 * Game → scene coordinates. The game uses a 2D plane (x right, y up); scenes lay it on
3 * the XZ plane with +y mapped to −z so "up" on the game map is "away" from the default camera.
4 */
5export type V3 = [number, number, number];
6
7/** Galaxy map units per game unit (systems sit hundreds of units apart). */
8export const GALAXY_SCALE = 0.25;
9
10export const galaxyPos = (s: { x: number; y: number }): V3 => [s.x * GALAXY_SCALE, 0, -s.y * GALAXY_SCALE];
11
12export const systemPos = (w: { x: number; y: number }): V3 => [w.x, 0, -w.y];
13
14/**
15 * Camera home that frames every system: looks at the middle of their bounds from above
16 * and in front, far enough to see the widest side. The look point is nudged right so the
17 * galaxy sits left of centre, clear of the HUD's right-hand panel.
18 */
19export function frameGalaxy(systems: readonly { x: number; y: number }[]): { pos: V3; look: V3 } {
20 if (systems.length === 0) return { pos: [0, 320, 260], look: [0, 0, 0] };
21 const pts = systems.map(galaxyPos);
22 const xs = pts.map((p) => p[0]);
23 const zs = pts.map((p) => p[2]);
24 const [minX, maxX, minZ, maxZ] = [Math.min(...xs), Math.max(...xs), Math.min(...zs), Math.max(...zs)];
25 const cx = (minX + maxX) / 2;
26 const cz = (minZ + maxZ) / 2;
27 const extent = Math.max(maxX - minX, maxZ - minZ, 80);
28 const lookX = cx + extent * 0.15;
29 return { pos: [lookX, extent * 0.85 + 40, cz + extent * 0.7 + 40], look: [lookX, 0, cz] };
30}