feat: turn the camera by dragging the map, and put big-screen labels on glass

Dragging the map walks the camera round the black hole (yaw) and raises or
lowers it (lift); clicking the hole springs back to the default view. The
shader takes an azimuth and an elevation, and the orbit overlay is projected
through the same view (orbitPose, trailAngle and project take a View), so rings,
stars, trails and rockets turn with the disk. A star behind the hole's shadow is
hidden by it. Labels and moons wait until the camera rests. A camera at rest
costs nothing, and the still quality tier still draws while it turns.

Big-screen map labels sit on dark glass chips so the radar grid cannot swallow
them, and the picked label and its status read as one chip.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 17:02:50 +07:00
parent 5773f42d90
commit 228ca42801
10 changed files with 259 additions and 49 deletions

View File

@@ -1,18 +1,19 @@
import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
import { animate, motion, useMotionValue, useTransform, type MotionStyle, type MotionValue } from "motion/react";
import type { PointerEvent as ReactPointerEvent } from "react";
import type { Orbit, Snapshot } from "../../api";
import { orbitStatus } from "../../lib/format";
import { LABEL_HEIGHT, placeLabels, type Rect } from "../../lib/galaxyLabelLayout";
import {
assignOrbitSlots, moonPoses, orbitCapacity, orbitPose, orbitRadii, ORBIT_TILT,
SCENE_HEIGHT, SCENE_WIDTH, trailAngle, type Vec2,
assignOrbitSlots, DEFAULT_VIEW, LIFT_MAX, LIFT_MIN, moonPoses, orbitCapacity, orbitPose, orbitRadii,
SCENE_HEIGHT, SCENE_WIDTH, tiltOf, trailAngle, type Vec2, type View,
} from "../../lib/galaxyLayout";
import { useGalaxyMotion } from "../../hooks/useGalaxyMotion";
import { useScreenTransition } from "../../hooks/useScreenTransition";
import { gentleSpring, uiSpring } from "../../lib/motion";
import { VaultCore } from "./VaultCore";
import type { CoreSignal } from "../../lib/blackhole/controller";
import { SCENE_UNITS_PER_M } from "../../lib/blackhole/layout";
import { SCENE_UNITS_PER_M, SHADOW_SCENE_RADIUS } from "../../lib/blackhole/layout";
import { createActivity, observeStatuses, type FailureCause } from "../../lib/orbitActivity";
import { applyActivity, createField, fieldActive, starPose, stepField, type FieldEvent } from "../../lib/rocket";
import { RocketSprites, createSpriteRefs, paintSprites } from "./RocketSprites";
@@ -44,6 +45,12 @@ const MAX_LABELS = 12;
const MAX_BIG_LABELS = 60;
/** On the big screen the picked orbit's label stands off its star, on the end of an elbowed leader line. */
const BIG_LABEL_GAP = 64;
/** Radians of yaw and of lift per pixel dragged, and how far a press may wander and still be a click. */
const YAW_PER_PX = 0.006;
const LIFT_PER_PX = 0.003;
const CLICK_SLOP = 5;
/** A click this close to the hole, in scene units from its centre, sends the camera back to the default view. */
const HOLE_CLICK_RADIUS = 72;
const clamp = (value: number) => Math.max(0, Math.min(1, value));
const ACCRETION_SECONDS = 6.4;
/** Glow falloff, close to a gaussian so there is no visible edge. */
@@ -102,13 +109,23 @@ export function BlackholeGalaxy({
const selectionX = useMotionValue(0);
const selectionY = useMotionValue(0);
const selectionPlaced = useRef(false);
// The camera. The two values are what the loop paints from; `view` is what the labels and moons are laid out from, and
// only catches up once the camera comes to rest, so a drag never triggers a layout.
const viewYaw = useMotionValue(0);
const viewLift = useMotionValue(0);
const [view, setView] = useState<View>(DEFAULT_VIEW);
const [turning, setTurning] = useState(false);
const painted = useRef<View>(DEFAULT_VIEW);
const turn = useRef<{ x: number; y: number; yaw: number; lift: number; moved: boolean } | undefined>(undefined);
useLayoutEffect(() => () => {
rate.stop();
reveal.stop();
selectionX.stop();
selectionY.stop();
}, [rate, reveal, selectionX, selectionY]);
viewYaw.stop();
viewLift.stop();
}, [rate, reveal, selectionX, selectionY, viewYaw, viewLift]);
useLayoutEffect(() => {
if (reducedMotion) {
rate.jump(0);
@@ -144,7 +161,7 @@ export function BlackholeGalaxy({
useScreenTransition(frame, bigScreen, reducedMotion, setWidth);
const selectedSlot = selectedOrbitId ? slots.get(selectedOrbitId) : undefined;
const selectedPosition = selectedSlot && orbitPose(selectedSlot, lockedPhase);
const selectedPosition = selectedSlot && orbitPose(selectedSlot, lockedPhase, view);
const selectedX = selectedPosition?.x;
const selectedY = selectedPosition?.y;
useLayoutEffect(() => {
@@ -246,14 +263,25 @@ export function BlackholeGalaxy({
const wasEntering = entrance.current < 0.6;
if (slots.size) entrance.current = reducedMotion ? 0.6 : Math.min(0.6, entrance.current + delta);
const entering = !reducedMotion && slots.size > 0 && entrance.current < 0.6;
if (!delta || moving || (!reducedMotion && wasEntering)) {
const live: View = { yaw: viewYaw.get(), lift: viewLift.get() };
const viewChanged = live.yaw !== painted.current.yaw || live.lift !== painted.current.lift;
if (viewChanged) {
// The orbit plane tips as the camera rises and falls; the circles turn into ellipses and back.
const tilt = tiltOf(live);
for (const [radius, ring] of ringNodes.current) ring.setAttribute("ry", String(radius * tilt));
painted.current = live;
}
if (!delta || moving || viewChanged || (!reducedMotion && wasEntering)) {
for (const [node, { id, index }] of bodyNodes.current) {
const slot = slots.get(id)!;
const { x, y } = orbitPose(slot, elapsed.current);
const depth = y / (slot.radius * ORBIT_TILT);
const { x, y } = orbitPose(slot, elapsed.current, live);
const depth = y / (slot.radius * tiltOf(live));
const appear = entering ? clamp((entrance.current - Math.min(index * 0.013, 0.33)) / 0.23) : 1;
node.setAttribute("transform", `translate(${x} ${y}) scale(${0.95 + depth * 0.08})`);
node.setAttribute("opacity", String(appear * (0.88 + depth * 0.12)));
// A star on the far side of the hole, seen through its shadow, is hidden by it. This only happens once the
// camera has come down far enough for the far side to reach the shadow.
const hidden = depth < 0 ? clamp((Math.hypot(x, y) - SHADOW_SCENE_RADIUS * 0.95) / (SHADOW_SCENE_RADIUS * 0.4)) : 1;
node.setAttribute("opacity", String(appear * (0.88 + depth * 0.12) * hidden));
const body = bodyNodes.current.get(node)!;
body.x = x;
body.y = y;
@@ -261,7 +289,7 @@ export function BlackholeGalaxy({
// fades out as the map stops.
body.trail ??= node.querySelector<SVGGElement>(".marker-trail");
if (body.trail) {
body.trail.setAttribute("transform", `rotate(${(trailAngle(slot, elapsed.current) * 180) / Math.PI}) scale(${0.55 + 0.45 * Math.min(1, speed)} 1)`);
body.trail.setAttribute("transform", `rotate(${(trailAngle(slot, elapsed.current, live) * 180) / Math.PI}) scale(${0.55 + 0.45 * Math.min(1, speed)} 1)`);
body.trail.setAttribute("opacity", String(Math.min(1, speed * 1.6) * (1 - body.look)));
}
}
@@ -283,8 +311,8 @@ export function BlackholeGalaxy({
body.life.setAttribute("opacity", String(1 - depth * 0.45 * (1 - wave)));
}
}
if (moving && selectedSlot) {
const point = orbitPose(selectedSlot, elapsed.current);
if ((moving || viewChanged) && selectedSlot) {
const point = orbitPose(selectedSlot, elapsed.current, live);
selectionX.jump(point.x);
selectionY.jump(point.y);
}
@@ -298,7 +326,7 @@ export function BlackholeGalaxy({
return slot ? starPose(slot, elapsed.current, speed) : undefined;
};
if (dt > 0) for (const event of stepField(field.current, dt, starOf)) outcome(event);
paintSprites(sprites.current, field.current, { starOf, lookAt: signal.lookAt, time: ambient.current, dt });
paintSprites(sprites.current, field.current, { starOf, lookAt: signal.lookAt, time: ambient.current, dt, view: live });
absorption = Math.max(0, field.current.absorption.value);
}
// The snapshot flash waits for the rocket to arrive and for the confirmed snapshot to show up in the list.
@@ -313,9 +341,11 @@ export function BlackholeGalaxy({
const phase = (diskTime.current % ACCRETION_SECONDS) / ACCRETION_SECONDS;
core.current?.style.setProperty("--accretion-offset", String(-100 * phase));
}
if (signal.time !== diskTime.current || signal.absorption !== absorption) {
if (signal.time !== diskTime.current || signal.absorption !== absorption || signal.yaw !== live.yaw || signal.lift !== live.lift) {
signal.time = diskTime.current;
signal.absorption = absorption;
signal.yaw = live.yaw;
signal.lift = live.lift;
signal.wake?.();
}
const coreStyle = core.current?.style;
@@ -351,7 +381,7 @@ export function BlackholeGalaxy({
const scale = width / SCENE_WIDTH;
const height = SCENE_HEIGHT * scale;
const hitRadius = Math.max(12, scale ? 12 / scale : 12);
const positions = [...slots.values()].map((slot) => orbitPose(slot, lockedPhase));
const positions = [...slots.values()].map((slot) => orbitPose(slot, lockedPhase, view));
const moons = selectedPosition
? moonPoses(selectedPosition, recentSnapshots.length, 2 * hitRadius + 3, positions)
: [];
@@ -376,7 +406,7 @@ export function BlackholeGalaxy({
const markers = positions.map((point) => box(point, 7));
const core = box({ x: 0, y: 0 }, 65 * scale);
labels = placeLabels(labelCandidates.map(({ id, name }) => {
const point = screen(orbitPose(slots.get(id)!, lockedPhase));
const point = screen(orbitPose(slots.get(id)!, lockedPhase, view));
return { id, ...point, width: Math.min(146, Math.ceil(measure?.measureText(name).width ?? name.length * 7) + 16) };
}), width, height, [core, ...markers, ...moons.map((moon) => box(moon, 12))], selectedOrbitId, bigScreen ? BIG_LABEL_GAP : 0);
}
@@ -443,8 +473,78 @@ export function BlackholeGalaxy({
);
});
// Wake the loop whenever the camera moves, so a locked map draws while it turns and goes back to sleep after.
useLayoutEffect(() => {
const stops = [viewYaw.on("change", wake), viewLift.on("change", wake)];
return () => stops.forEach((stop) => stop());
}, [viewYaw, viewLift, wake]);
const settle = () => {
setView({ yaw: viewYaw.get(), lift: viewLift.get() });
setTurning(false);
};
/** Back to the default view by the short way round, with the shared spring. */
const resetView = () => {
const full = 2 * Math.PI;
const yawTarget = Math.round(viewYaw.get() / full) * full;
if (reducedMotion) {
viewYaw.jump(0);
viewLift.jump(0);
settle();
return;
}
setTurning(true);
animate(viewLift, 0, gentleSpring);
animate(viewYaw, yawTarget, {
...gentleSpring,
onComplete: () => {
viewYaw.jump(0);
settle();
},
});
};
const startTurn = (event: ReactPointerEvent<HTMLDivElement>) => {
if (!event.isPrimary || event.button !== 0 || (event.target as Element).closest("[data-orbit-marker], .orbit-hit, [data-snapshot-marker]")) return;
turn.current = { x: event.clientX, y: event.clientY, yaw: viewYaw.get(), lift: viewLift.get(), moved: false };
};
const moveTurn = (event: ReactPointerEvent<HTMLDivElement>) => {
const drag = turn.current;
if (!drag) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
if (!drag.moved) {
if (Math.hypot(dx, dy) < CLICK_SLOP) return;
drag.moved = true;
viewYaw.stop();
viewLift.stop();
event.currentTarget.setPointerCapture(event.pointerId);
setTurning(true);
}
// Dragging right brings the near side of the orbits to the right; dragging down raises the camera.
viewYaw.set(drag.yaw - dx * YAW_PER_PX);
viewLift.set(Math.min(LIFT_MAX, Math.max(LIFT_MIN, drag.lift + dy * LIFT_PER_PX)));
};
const endTurn = (event: ReactPointerEvent<HTMLDivElement>) => {
const drag = turn.current;
turn.current = undefined;
if (!drag) return;
if (drag.moved) {
if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
settle();
return;
}
// A click on the black hole itself puts the camera back.
const box = event.currentTarget.getBoundingClientRect();
const radius = (HOLE_CLICK_RADIUS * box.width) / SCENE_WIDTH;
if (event.type === "pointerup" && Math.hypot(event.clientX - (box.left + box.width / 2), event.clientY - (box.top + box.height / 2)) <= radius &&
(viewYaw.get() !== 0 || viewLift.get() !== 0)) {
resetView();
}
};
return (
<motion.div ref={frame} className="galaxy-frame" data-flowing={flowing} style={revealVariables}>
<motion.div ref={frame} className="galaxy-frame" data-flowing={flowing} data-turning={turning || undefined} style={revealVariables}
onPointerDown={startTurn} onPointerMove={moveTurn} onPointerUp={endTurn} onPointerCancel={endTurn}>
<svg viewBox={`${-HALF_WIDTH} ${-HALF_HEIGHT} ${SCENE_WIDTH} ${SCENE_HEIGHT}`} aria-hidden="true">
<defs>
<radialGradient id={knockoutId}>
@@ -482,7 +582,7 @@ export function BlackholeGalaxy({
</defs>
<g className="orbit-tracks" pointerEvents="none">
{orbitRadii.map((radius) => (
<ellipse key={radius} rx={radius} ry={radius * ORBIT_TILT} className={selectedSlot?.radius === radius ? "is-selected" : ""}
<ellipse key={radius} rx={radius} ry={radius * tiltOf(view)} className={selectedSlot?.radius === radius ? "is-selected" : ""}
ref={(node) => {
if (!node) return;
ringNodes.current.set(radius, node);
@@ -543,7 +643,7 @@ export function BlackholeGalaxy({
</span>
))}
{bigScreen && focusLabel && (
<span className="scene-label-note" style={{ left: `${100 * focusLabel.x / width}%`, top: `${100 * (focusLabel.y + LABEL_HEIGHT - 4) / height}%`, opacity: reducedMotion ? 1 : "var(--lock-reveal)" }}>
<span className="scene-label-note" style={{ left: `${100 * focusLabel.x / width}%`, top: `${100 * (focusLabel.y + LABEL_HEIGHT) / height}%`, width: focusLabel.width, opacity: reducedMotion ? 1 : "var(--lock-reveal)" }}>
{orbitStatus(shownStatus(visible.find(({ id }) => id === selectedOrbitId)!)).label}
</span>
)}

View File

@@ -1,6 +1,6 @@
import { useId } from "react";
import { ABSORB_LINGER, MAX_ROCKETS, infallLook, screenRadius, type Field, type Rocket, type StarPose } from "../../lib/rocket";
import { ORBIT_TILT } from "../../lib/galaxyLayout";
import { DEFAULT_VIEW, project, type View } from "../../lib/galaxyLayout";
import { SCENE_UNITS_PER_M } from "../../lib/blackhole/layout";
import { advanceTrail, smoothPath, trailLength, type Trail } from "../../lib/trail";
@@ -98,15 +98,18 @@ export type PaintContext = {
/** Seconds, for the engine flicker. */
time: number;
dt: number;
/** Where the camera stands; the field itself lives in the orbit plane. */
view?: View;
};
/** Move every sprite to match the field. Called once per frame by the scene loop. */
export function paintSprites(refs: SpriteRefs, field: Field, context: PaintContext) {
const view = context.view ?? DEFAULT_VIEW;
let slot = 0;
for (const rocket of field.rockets.values()) {
const node = refs.rockets[slot];
if (!node || slot >= MAX_ROCKETS) break;
paintRocket(refs, slot, node, rocket, context);
paintRocket(refs, slot, node, rocket, context, view);
slot++;
}
for (; slot < MAX_ROCKETS; slot++) {
@@ -123,8 +126,9 @@ export function paintSprites(refs: SpriteRefs, field: Field, context: PaintConte
const node = refs.debris[index];
if (!node) return;
const fade = Math.max(0, 1 - piece.age / piece.life);
node.setAttribute("cx", String(piece.x));
node.setAttribute("cy", String(piece.y * ORBIT_TILT));
const at = project(piece.x, piece.y, view);
node.setAttribute("cx", String(at.x));
node.setAttribute("cy", String(at.y));
node.setAttribute("r", String(piece.size * (0.6 + 0.4 * fade)));
node.setAttribute("opacity", String(fade ** 1.4));
});
@@ -140,8 +144,9 @@ export function paintSprites(refs: SpriteRefs, field: Field, context: PaintConte
if (!node || !star || flare >= refs.flares.length) continue;
flare++;
const value = Math.max(0, spring.value);
node.setAttribute("cx", String(star.x));
node.setAttribute("cy", String(star.y * ORBIT_TILT));
const at = project(star.x, star.y, view);
node.setAttribute("cx", String(at.x));
node.setAttribute("cy", String(at.y));
node.setAttribute("r", String(7 + 22 * (1 - value)));
node.setAttribute("opacity", String(0.85 * value));
}
@@ -176,14 +181,12 @@ function paintTrail(refs: SpriteRefs, slot: number, rocket: Rocket, sx: number,
path.classList.toggle("rocket-trail--ghost", rocket.mode === "ghost");
}
function paintRocket(refs: SpriteRefs, slot: number, node: SVGGElement, rocket: Rocket, { lookAt, time, dt }: PaintContext) {
function paintRocket(refs: SpriteRefs, slot: number, node: SVGGElement, rocket: Rocket, { lookAt, time, dt }: PaintContext, view: View) {
if (node.dataset.orbit !== rocket.id) node.dataset.orbit = rocket.id;
const sx = rocket.x;
const sy = rocket.y * ORBIT_TILT;
const { x: sx, y: sy } = project(rocket.x, rocket.y, view);
// Heading follows the screen-space velocity, smoothed so an interruption turns the rocket instead of snapping it.
const vx = rocket.vx;
const vy = rocket.vy * ORBIT_TILT;
const { x: vx, y: vy } = project(rocket.vx, rocket.vy, view);
const previous = headings.get(node) ?? Math.atan2(vy, vx);
let heading = previous;
if (Math.hypot(vx, vy) > 4) {

View File

@@ -1166,13 +1166,13 @@ button.act-row[data-group="needs"]:hover { background: #20161a; }
.big-screen .view-switch .scene-look-control span { display: inline; }
.big-screen .view-switch button[aria-checked="true"][data-look] { color: var(--holo-bright); text-shadow: var(--holo-glow); border-bottom-color: var(--holo); }
/* the map's own labels are light too */
/* the map's own labels are light too, each on a dark glass chip so the radar's grid cannot swallow it */
/* keep the label's own font and padding: its width is measured with them, and any wider type is cut to an ellipsis */
.big-screen .scene-labels span { background: none; border-color: transparent; color: var(--holo); text-shadow: var(--holo-glow); }
.big-screen .scene-labels span.is-selected { color: var(--holo-bright); }
.big-screen .scene-labels .scene-label-note { position: absolute; display: block; height: auto; overflow: visible; background: none; border: 0; padding-inline: 7px; line-height: 1; font: 500 9px/1 var(--font-mono); letter-spacing: .2em; text-transform: uppercase; color: var(--holo-dim); text-shadow: var(--holo-glow); }
.big-screen .scene-labels span { background: rgba(4, 9, 11, .8); border-color: rgba(159, 232, 212, .26); border-radius: 3px; color: var(--holo); text-shadow: var(--holo-glow); backdrop-filter: blur(3px); }
.big-screen .scene-labels span.is-selected { color: var(--holo-bright); border-color: rgba(159, 232, 212, .6); border-bottom-color: transparent; border-radius: 3px 3px 0 0; }
.big-screen .scene-labels .scene-label-note { position: absolute; display: block; box-sizing: border-box; height: auto; overflow: visible; padding: 3px 7px 5px; line-height: 1; font: 500 9px/1 var(--font-mono); letter-spacing: .2em; text-transform: uppercase; color: var(--holo-dim); border: 1px solid rgba(159, 232, 212, .6); border-top: 0; border-radius: 0 0 3px 3px; }
.big-screen .focus-leader { stroke: var(--holo); opacity: .85; }
.big-screen .focus-leader-dot { fill: var(--holo); filter: drop-shadow(0 0 4px rgba(120, 232, 205, .8)); }
.big-screen .focus-leader { stroke: var(--holo); opacity: .7; }
@media (max-width: 900px) {
.big-screen { --edge: 24px; }
@@ -1195,3 +1195,9 @@ button.act-row[data-group="needs"]:hover { background: #20161a; }
.big-screen .vault-topbar-tools { top: auto; bottom: 84px; }
.big-screen .vault-overview { display: none; }
}
/* The camera: drag the map to turn it, click the black hole to bring it back. Labels and moons wait for it to rest. */
.galaxy-frame { cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.big-screen .galaxy-frame { touch-action: none; }
.galaxy-frame[data-turning] { cursor: grabbing; }
.galaxy-frame[data-turning] :is(.scene-labels, .snapshot-marker, .focus-leader, .focus-leader-big) { opacity: 0; }

View File

@@ -1,4 +1,5 @@
import { cancelFrame, frame as frameLoop } from "motion/react";
import { elevationOf } from "../galaxyLayout.ts";
import { farthestCornerM, layoutFor } from "./layout";
import { createLook, jumpLook, requestLook, stepLook, styleAt, waveParams, type Look } from "./look";
import { CALIBRATION_SAMPLES, QUALITY_TIERS, chooseTier, initialTier } from "./quality";
@@ -8,6 +9,9 @@ import { createBlackholeRenderer, defaultParams, type BlackholeParams } from "./
export type CoreSignal = {
time: number;
absorption: number;
/** Where the viewer stands, written by the scene: yaw round the hole and lift above the orbit plane, radians. */
yaw?: number;
lift?: number;
wake?: () => void;
/** The look at a distance from the hole, in gravitational radii: 0 realistic .. 1 radar. Set by the renderer. */
lookAt?: (radiusM: number) => number;
@@ -63,6 +67,8 @@ export function createBlackholeController({ canvas, panel, frame, signal, onLost
const params: BlackholeParams = { ...defaultParams };
let queued = false;
let lastDraw = 0;
let drawnYaw = 0;
let drawnLift = 0;
let trackUntil = 0;
let forced = true;
let frozenTime = signal.time;
@@ -123,8 +129,11 @@ export function createBlackholeController({ canvas, panel, frame, signal, onLost
const radar = look.to === 1 || look.from === 1;
const motion = !reduced && preset.maxFps > 0;
const sweepTarget = radar && motion ? 1 : 0;
// The still tier freezes ambient motion, but a capture still plays out at a low rate.
const cap = preset.maxFps > 0 ? preset.maxFps : signal.absorption > 0 ? 15 : 0;
// Turning the camera is the viewer's own doing, so it is drawn even on the still tier, at the tier's rate or at a
// low one there. A camera at rest costs nothing: nothing differs from the last draw, so nothing is drawn.
const turned = (signal.yaw ?? 0) !== drawnYaw || (signal.lift ?? 0) !== drawnLift;
// The still tier freezes ambient motion, but a capture or a turning camera still plays out at a low rate.
const cap = preset.maxFps > 0 ? preset.maxFps : signal.absorption > 0 || turned ? 15 : 0;
const free = tracking || waving;
if (!free && !forced && cap === 0 && Math.abs(sweepTarget - sweepAmount) < 0.004) return;
if (!free && !forced && now - lastDraw < 1000 / cap - 2) {
@@ -153,7 +162,11 @@ export function createBlackholeController({ canvas, panel, frame, signal, onLost
const time = preset.maxFps > 0 ? signal.time : frozenTime;
params.sway = 0.06 * Math.sin(time * 0.05);
params.absorb = signal.absorption;
params.azimuth = signal.yaw ?? 0;
params.elevation = elevationOf(signal.lift ?? 0);
gpu.render(time, params);
drawnYaw = signal.yaw ?? 0;
drawnLift = signal.lift ?? 0;
lastDraw = now;
forced = false;
if (tracking || look.running || sweepTarget > 0 || sweepAmount !== sweepTarget) schedule();

View File

@@ -7,7 +7,7 @@ export type Box = { left: number; top: number; width: number; height: number };
* The shadow's radius in scene units. The disk reaches about five times that, so at 34 it ends near the first orbit
* ring (128) instead of covering the orbits, while staying in proportion to the shadow.
*/
const SHADOW_SCENE_RADIUS = 34;
export const SHADOW_SCENE_RADIUS = 34;
/** Scene units per gravitational radius: how far from the hole a marker is, in the renderer's units. */
export const SCENE_UNITS_PER_M = SHADOW_SCENE_RADIUS / CRITICAL_IMPACT;
const PX_PER_M_SCENE = SCENE_UNITS_PER_M;

View File

@@ -7,6 +7,8 @@ export const SKY_ELEVATION = (12 * Math.PI) / 180;
export type BlackholeParams = {
/** Camera elevation above the disk plane, radians. */
elevation: number;
/** Camera yaw round the hole, radians. */
azimuth: number;
diskIn: number;
diskOut: number;
diskGain: number;
@@ -51,6 +53,7 @@ export type BlackholeParams = {
export const defaultParams: BlackholeParams = {
elevation: (8 * Math.PI) / 180,
azimuth: 0,
diskIn: ISCO,
diskOut: 26,
diskGain: 2.1,
@@ -241,6 +244,7 @@ export function createBlackholeRenderer(canvas: HTMLCanvasElement, options: { sk
gl.uniform2f(scene.uniform("uCenter"), centerX * scale, centerY * scale);
gl.uniform1f(scene.uniform("uPxPerM"), pxPerM * scale);
gl.uniform1f(scene.uniform("uElevation"), params.elevation);
gl.uniform1f(scene.uniform("uAzimuth"), params.azimuth);
gl.uniform1f(scene.uniform("uTime"), time);
gl.uniform1f(scene.uniform("uSway"), params.sway);
gl.uniform1f(scene.uniform("uDiskIn"), params.diskIn);

View File

@@ -178,6 +178,7 @@ uniform samplerCube uSkyMap;
uniform vec2 uCenter; // hole centre in target pixels, y up
uniform float uPxPerM; // target pixels per gravitational radius
uniform float uElevation; // camera elevation above the disk plane, radians
uniform float uAzimuth; // camera yaw round the hole, radians; 0 is the default view
uniform float uTime; // disk clock, seconds
uniform float uSway; // sky yaw, radians
uniform float uSky; // sky brightness
@@ -340,9 +341,13 @@ vec3 diskLight(vec3 hit, vec3 dir) {
void main() {
vec2 p = (gl_FragCoord.xy - uCenter) / uPxPerM;
vec3 camera = vec3(0.0, sin(uElevation), cos(uElevation));
vec3 right = vec3(1.0, 0.0, 0.0);
vec3 up = vec3(0.0, cos(uElevation), -sin(uElevation));
// The camera stands on a sphere round the hole: uElevation above the disk plane, uAzimuth round it. At azimuth 0
// this is the original (0, sin e, cos e) view.
float ca = cos(uAzimuth), sa = sin(uAzimuth);
float ce = cos(uElevation), se = sin(uElevation);
vec3 camera = vec3(sa * ce, se, ca * ce);
vec3 right = vec3(ca, 0.0, -sa);
vec3 up = vec3(-sa * se, ce, -ca * se);
vec3 pos = camera * START_RADIUS + right * p.x + up * p.y;
vec3 vel = -camera;

View File

@@ -53,18 +53,56 @@ export function assignOrbitSlots(
return next;
}
export function orbitPose(slot: OrbitSlot, time: number): Vec2 {
const angle = slot.angle + time * slot.speed;
/**
* Where the viewer stands. `yaw` walks the camera round the hole; `lift` raises it above the orbit plane (negative
* lowers it). Both are radians, and the default is the view the map has always had.
*/
export type View = { yaw: number; lift: number };
export const DEFAULT_VIEW: View = { yaw: 0, lift: 0 };
export const LIFT_MIN = -0.55;
export const LIFT_MAX = 0.7;
/** The angle the orbit plane is seen at by default: its flattening is sin of this, which is ORBIT_TILT. */
const BASE_PITCH = Math.asin(ORBIT_TILT);
const DISK_ELEVATION = (8 * Math.PI) / 180;
/**
* The camera's elevation above the black hole's disk for a given lift, radians. The default is the disk's own 8
* degrees; the extremes stay clear of edge-on and of straight down, and the orbit plane and the disk always rise and
* fall together.
*/
export function elevationOf(lift: number): number {
const clamped = Math.min(LIFT_MAX, Math.max(LIFT_MIN, lift));
return clamped >= 0
? DISK_ELEVATION + (clamped * (1.25 - DISK_ELEVATION)) / LIFT_MAX
: DISK_ELEVATION + (clamped * (DISK_ELEVATION - 0.03)) / -LIFT_MIN;
}
/** How flat the orbit plane looks: ORBIT_TILT by default, a line edge-on, a circle seen from above. */
export function tiltOf({ lift }: View): number {
return lift === 0 ? ORBIT_TILT : Math.sin(BASE_PITCH + Math.min(LIFT_MAX, Math.max(LIFT_MIN, lift)));
}
/** A point in the orbit plane, as the camera sees it. With the default view this is (x, y * ORBIT_TILT). */
export function project(x: number, y: number, view: View = DEFAULT_VIEW): Vec2 {
const tilt = tiltOf(view);
if (!view.yaw) return { x, y: y * tilt };
const cos = Math.cos(view.yaw);
const sin = Math.sin(view.yaw);
return { x: x * cos - y * sin, y: (x * sin + y * cos) * tilt };
}
export function orbitPose(slot: OrbitSlot, time: number, view: View = DEFAULT_VIEW): Vec2 {
const angle = slot.angle + time * slot.speed + view.yaw;
return {
x: Math.cos(angle) * slot.radius,
y: Math.sin(angle) * slot.radius * ORBIT_TILT,
y: Math.sin(angle) * slot.radius * tiltOf(view),
};
}
/** Screen direction, in radians, from a marker back along its orbit: where its trail points. */
export function trailAngle(slot: OrbitSlot, time: number): number {
const angle = slot.angle + time * slot.speed;
return Math.atan2(-Math.cos(angle) * slot.radius * ORBIT_TILT, Math.sin(angle) * slot.radius);
export function trailAngle(slot: OrbitSlot, time: number, view: View = DEFAULT_VIEW): number {
const angle = slot.angle + time * slot.speed + view.yaw;
return Math.atan2(-Math.cos(angle) * slot.radius * tiltOf(view), Math.sin(angle) * slot.radius);
}
export function moonPoses(star: Vec2, count: number, distance: number, obstacles: Vec2[] = []): Vec2[] {