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

@@ -9,7 +9,7 @@ The persistent viewport maps backup jobs and recovery points. The black hole rep
- The first three recovery points of the selected orbit appear as moons when the map has room. Select a moon or history entry to review the snapshot and start a restore. Escape closes the console. Restore countdown and polling continue if the console closes. - The first three recovery points of the selected orbit appear as moons when the map has room. Select a moon or history entry to review the snapshot and start a restore. Escape closes the console. Restore countdown and polling continue if the console closes.
- Hub connectivity is separate from backup health. Capture targets the named orbit. A running backup is a light circling its star; when it succeeds the light leaves for the black hole, and when it fails it is lost. See Orbit activity below. Rehearsals show text feedback and a ghost light. - Hub connectivity is separate from backup health. Capture targets the named orbit. A running backup is a light circling its star; when it succeeds the light leaves for the black hole, and when it fails it is lost. See Orbit activity below. Rehearsals show text feedback and a ghost light.
- The map shows up to 55 overview orbits and reserves one slot for inspecting an orbit beyond that limit. The register provides access to every orbit. On narrow screens the map, register, and inspector stack vertically. - The map shows up to 55 overview orbits and reserves one slot for inspecting an orbit beyond that limit. The register provides access to every orbit. On narrow screens the map, register, and inspector stack vertically.
- **Big Screen** is a holographic visor. The map fills the viewport, and every piece of the workspace has a counterpart there and springs to it with `useScreenTransition` rather than popping. There are no panels or plates, only light: thin mint lines and glowing text, a vignette and faint scan over the scene, four corner brackets and a glass edge. Top left, the brand and the map's mode (Flowing, or Locked with the orbit). Top right, the four telemetry readings with their lamps. Bottom left, the legend. Bottom centre, the systems as text, the active one held in a glowing frame (it can still be dragged), and an ember label for Activity while something needs you. Bottom right, the Window | Radar words with a sliding underline, the motion and exit keys, then search and sign out as outlined circles, with the hub's state above them. The register, the inspector, the canopy frame and the sill captions fade out; every orbit is labelled on the map (up to 60, each placed clear of the others; the workspace map shows 12), and the picked orbit's label stands off its star on an elbowed leader line, with its status beneath. Use **Exit big screen** or Escape to return to the workspace. Below 900 px the legend is hidden and the controls sit above the systems; below 520 px the brand and telemetry are hidden too and the view switch shows icons. - **Big Screen** is a holographic visor. The map fills the viewport, and every piece of the workspace has a counterpart there and springs to it with `useScreenTransition` rather than popping. There are no panels or plates, only light: thin mint lines and glowing text, a vignette and faint scan over the scene, four corner brackets and a glass edge. Top left, the brand and the map's mode (Flowing, or Locked with the orbit). Top right, the four telemetry readings with their lamps. Bottom left, the legend. Bottom centre, the systems as text, the active one held in a glowing frame (it can still be dragged), and an ember label for Activity while something needs you. Bottom right, the Window | Radar words with a sliding underline, the motion and exit keys, then search and sign out as outlined circles, with the hub's state above them. The register, the inspector, the canopy frame and the sill captions fade out; every orbit is labelled on the map, each on a dark glass chip so the radar's grid cannot swallow it (up to 60, each placed clear of the others; the workspace map shows 12), and the picked orbit's label stands off its star on an elbowed leader line, with its status beneath. Use **Exit big screen** or Escape to return to the workspace. Below 900 px the legend is hidden and the controls sit above the systems; below 520 px the brand and telemetry are hidden too and the view switch shows icons.
- Drag the active navbar item sideways and release to open the destination. The regular navbar is a tray of switches with a sliding pill. Big Screen uses the same text tabs with a glowing frame in place of the pill. - Drag the active navbar item sideways and release to open the destination. The regular navbar is a tray of switches with a sliding pill. Big Screen uses the same text tabs with a glowing frame in place of the pill.
- The navbar stays available above the side panel so you can switch directly between consoles. In the regular workspace it becomes a floating text dock in the same top position. Big Screen keeps its tabs at the bottom. - The navbar stays available above the side panel so you can switch directly between consoles. In the regular workspace it becomes a floating text dock in the same top position. Big Screen keeps its tabs at the bottom.
- Use **Search**, **⌘K**, or **Ctrl+K** from the vault, a console, or Big Screen. An empty field shows navigation shortcuts. Type to find destinations, orbits by name, ID, or provider, and snapshots by orbit name, ID, or displayed capture date. Search uses the summaries already loaded by the vault. Use the arrow keys and Enter, or select a result with a pointer. Escape closes search and returns focus to its button. Search is a spotlight panel over a dimmed, lightly blurred deck: a large input, grouped results with a kind label on the right (the active row adds an Enter mark), a footer of key hints and the result count, and a "No signal" message when nothing matches. - Use **Search**, **⌘K**, or **Ctrl+K** from the vault, a console, or Big Screen. An empty field shows navigation shortcuts. Type to find destinations, orbits by name, ID, or provider, and snapshots by orbit name, ID, or displayed capture date. Search uses the summaries already loaded by the vault. Use the arrow keys and Enter, or select a result with a pointer. Escape closes search and returns focus to its button. Search is a spotlight panel over a dimmed, lightly blurred deck: a large input, grouped results with a kind label on the right (the active row adds an Enter mark), a footer of key hints and the result count, and a "No signal" message when nothing matches.
@@ -38,6 +38,7 @@ The persistent viewport maps backup jobs and recovery points. The black hole rep
- The proportions follow reference imagery of a thin disk seen from a low angle: the disk reaches about 26 M, roughly five times the shadow's radius, the camera sits 8° above the disk plane, the disk is optically thick near the hole and thins toward its rim, and its brightness falls steeply outward. In the app the shadow is 34 scene units across its radius, so the disk ends just past the first orbit ring. The disk plane is not the orbit plane: the orbits keep their own 0.68 tilt. - The proportions follow reference imagery of a thin disk seen from a low angle: the disk reaches about 26 M, roughly five times the shadow's radius, the camera sits 8° above the disk plane, the disk is optically thick near the hole and thins toward its rim, and its brightness falls steeply outward. In the app the shadow is 34 scene units across its radius, so the disk ends just past the first orbit ring. The disk plane is not the orbit plane: the orbits keep their own 0.68 tilt.
- The orbit overlay has two looks that follow the radar wave. In the realistic look each orbit is a star: a bright core, a glow tinted by status (mint when healthy, amber while working, ember red when failed) and four diffraction spikes, which the sky's own stars never have, so a marker cannot be mistaken for scenery. The orbit tracks recede to a faint trace; hovering a marker reveals its shell, and the selected orbit keeps its bright dashed ring. While the map flows, each marker trails a tapered comet tail back along its orbit, which lengthens with speed. Stars shimmer: each scales and brightens slightly out of phase with the others, and working and failed stars move the most. The shimmer rides the scene loop that is already running, so a stopped map is perfectly still, and it is off under reduced motion. Hovering a star enlarges it with the shared spring. Status is still carried by shape as well as colour: failed keeps its diamond and busy keeps its dashed ring. In the radar look the markers are plain instrument dots and the tracks are drawn at full strength. Each marker and track ring takes the look at its own distance from the hole, so they change as the wave front passes. The renderer exposes this as `signal.lookAt` and calls `signal.onLook` while the wave runs. - The orbit overlay has two looks that follow the radar wave. In the realistic look each orbit is a star: a bright core, a glow tinted by status (mint when healthy, amber while working, ember red when failed) and four diffraction spikes, which the sky's own stars never have, so a marker cannot be mistaken for scenery. The orbit tracks recede to a faint trace; hovering a marker reveals its shell, and the selected orbit keeps its bright dashed ring. While the map flows, each marker trails a tapered comet tail back along its orbit, which lengthens with speed. Stars shimmer: each scales and brightens slightly out of phase with the others, and working and failed stars move the most. The shimmer rides the scene loop that is already running, so a stopped map is perfectly still, and it is off under reduced motion. Hovering a star enlarges it with the shared spring. Status is still carried by shape as well as colour: failed keeps its diamond and busy keeps its dashed ring. In the radar look the markers are plain instrument dots and the tracks are drawn at full strength. Each marker and track ring takes the look at its own distance from the hole, so they change as the wave front passes. The renderer exposes this as `signal.lookAt` and calls `signal.onLook` while the wave runs.
- The disk's texture is filtered by how many pixels each feature covers: noise octaves too fine to resolve collapse to their mean and melt into a smooth glow, so thin lines cannot alias into moire. Light bent a long way round the hole is squeezed onto fewer pixels, so it is filtered harder. The gas shears with differential rotation, and the whole pattern flows faster near the hole. - The disk's texture is filtered by how many pixels each feature covers: noise octaves too fine to resolve collapse to their mean and melt into a smooth glow, so thin lines cannot alias into moire. Light bent a long way round the hole is squeezed onto fewer pixels, so it is filtered harder. The gas shears with differential rotation, and the whole pattern flows faster near the hole.
- **Camera.** Drag the map to turn the view: dragging sideways walks the camera round the hole (`yaw`), dragging down raises it above the orbit plane and dragging up lowers it (`lift`, from nearly edge-on to steeply from above). Click the black hole to spring back to the default view by the short way round. The whole scene turns together: the shader's camera takes an azimuth and an elevation (`uAzimuth`, `uElevation`), and the orbit overlay is projected through the same view in `galaxyLayout.ts` (`orbitPose`, `trailAngle` and `project` take a `View`; the default view is the map's old one). Rings open into circles or flatten into lines, stars and rockets move along them, a star behind the hole's shadow is hidden by it, and the disk's bright side and the lensed sky change as they would. A press that starts on a marker or a moon still selects it. While the camera moves, markers, rings and rockets are placed straight onto the SVG and labels and moons are hidden; they are laid out again once it rests. A camera at rest costs nothing: the black hole is redrawn only while the view differs from the last draw, at the tier's rate (15 fps on the still tier). On touch screens a sideways drag turns the map and a vertical one still scrolls the page; Big Screen takes both. The camera has no keyboard control yet; the register and the search reach every orbit without it.
- The sky must never rival the orbit markers drawn over it. Point sources in the bake (stars and distant galaxies) are small, few, and capped in brightness (`POINT_CAP`), and every marker has a soft dark backing disc and a dark outline, so it stays readable over any haze. Treat both as a contract: a sky change that adds bright features near the orbits breaks clickability. - The sky must never rival the orbit markers drawn over it. Point sources in the bake (stars and distant galaxies) are small, few, and capped in brightness (`POINT_CAP`), and every marker has a soft dark backing disc and a dark outline, so it stays readable over any haze. Treat both as a contract: a sky change that adds bright features near the orbits breaks clickability.
- The sky is baked once into a cubemap at load and sampled per pixel. It is a procedural galaxy with a bulge, dust lanes, nebulae, distant galaxies and stars. - The sky is baked once into a cubemap at load and sampled per pixel. It is a procedural galaxy with a bulge, dust lanes, nebulae, distant galaxies and stars.
- The canvas sits under the whole scene panel and follows `.galaxy-frame` through its bounding rectangle, so the hole stays centred on the orbits while the frame springs between the workspace and Big Screen. Drawing happens in Motion's post-render step so it never lags the frame's transform. - The canvas sits under the whole scene panel and follows `.galaxy-frame` through its bounding rectangle, so the hole stays centred on the orbits while the frame springs between the workspace and Big Screen. Drawing happens in Motion's post-render step so it never lags the frame's transform.

View File

@@ -1,6 +1,6 @@
import assert from "node:assert/strict"; import assert from "node:assert/strict";
import test from "node:test"; import test from "node:test";
import { assignOrbitSlots, orbitPose, groupSnapshots, moonPoses, trailAngle } from "../src/lib/galaxyLayout.ts"; import { assignOrbitSlots, elevationOf, orbitPose, groupSnapshots, moonPoses, project, tiltOf, trailAngle } from "../src/lib/galaxyLayout.ts";
import { placeLabels } from "../src/lib/galaxyLabelLayout.ts"; import { placeLabels } from "../src/lib/galaxyLabelLayout.ts";
test("slot identities survive reordering, insertion and removal", () => { test("slot identities survive reordering, insertion and removal", () => {
@@ -82,3 +82,43 @@ test("a marker's trail points back along the direction it came from", () => {
} }
} }
}); });
test("the default view is the map's own view, and a turned view is the same orbit seen from elsewhere", () => {
const slot = { radius: 190, angle: 0.4, speed: 0.033 };
assert.deepEqual(orbitPose(slot, 3, { yaw: 0, lift: 0 }), orbitPose(slot, 3));
assert.equal(tiltOf({ yaw: 0, lift: 0 }), 0.68);
// The orbit plane is a circle: turning the camera round it only moves a marker along its own ellipse.
const turned = orbitPose(slot, 3, { yaw: 1.1, lift: 0 });
const tilt = tiltOf({ yaw: 1.1, lift: 0 });
assert.ok(Math.abs((turned.x / 190) ** 2 + (turned.y / (190 * tilt)) ** 2 - 1) < 1e-9);
// Raising the camera opens the ellipse towards a circle; lowering it flattens it towards a line.
assert.ok(tiltOf({ yaw: 0, lift: 0.4 }) > 0.68);
assert.ok(tiltOf({ yaw: 0, lift: -0.5 }) < 0.4);
assert.ok(tiltOf({ yaw: 0, lift: 9 }) <= 1 && tiltOf({ yaw: 0, lift: -9 }) > 0);
});
test("project agrees with orbitPose for a point on the orbit", () => {
const slot = { radius: 128, angle: 1.9, speed: 0.047 };
const view = { yaw: -0.8, lift: 0.3 };
const angle = slot.angle + 2 * slot.speed;
const direct = orbitPose(slot, 2, view);
const projected = project(Math.cos(angle) * slot.radius, Math.sin(angle) * slot.radius, view);
assert.ok(Math.abs(direct.x - projected.x) < 1e-9 && Math.abs(direct.y - projected.y) < 1e-9);
});
test("a trail points back along the turned orbit", () => {
const slot = { radius: 190, angle: 0.4, speed: 0.033 };
const view = { yaw: 0.9, lift: 0.2 };
const now = orbitPose(slot, 5, view);
const before = orbitPose(slot, 5 - 0.01, view);
const tail = Math.atan2(before.y - now.y, before.x - now.x);
const diff = Math.atan2(Math.sin(trailAngle(slot, 5, view) - tail), Math.cos(trailAngle(slot, 5, view) - tail));
assert.ok(Math.abs(diff) < 0.05);
});
test("raising the camera raises the disk's view too, within bounds", () => {
assert.equal(elevationOf(0), (8 * Math.PI) / 180);
assert.ok(elevationOf(0.3) > elevationOf(0) && elevationOf(-0.3) < elevationOf(0));
assert.ok(elevationOf(-99) > 0 && elevationOf(99) < Math.PI / 2);
for (let lift = -0.55; lift < 0.7; lift += 0.05) assert.ok(elevationOf(lift + 0.05) > elevationOf(lift));
});

View File

@@ -1,18 +1,19 @@
import { useId, useLayoutEffect, useMemo, useRef, useState } from "react"; import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
import { animate, motion, useMotionValue, useTransform, type MotionStyle, type MotionValue } from "motion/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 type { Orbit, Snapshot } from "../../api";
import { orbitStatus } from "../../lib/format"; import { orbitStatus } from "../../lib/format";
import { LABEL_HEIGHT, placeLabels, type Rect } from "../../lib/galaxyLabelLayout"; import { LABEL_HEIGHT, placeLabels, type Rect } from "../../lib/galaxyLabelLayout";
import { import {
assignOrbitSlots, moonPoses, orbitCapacity, orbitPose, orbitRadii, ORBIT_TILT, assignOrbitSlots, DEFAULT_VIEW, LIFT_MAX, LIFT_MIN, moonPoses, orbitCapacity, orbitPose, orbitRadii,
SCENE_HEIGHT, SCENE_WIDTH, trailAngle, type Vec2, SCENE_HEIGHT, SCENE_WIDTH, tiltOf, trailAngle, type Vec2, type View,
} from "../../lib/galaxyLayout"; } from "../../lib/galaxyLayout";
import { useGalaxyMotion } from "../../hooks/useGalaxyMotion"; import { useGalaxyMotion } from "../../hooks/useGalaxyMotion";
import { useScreenTransition } from "../../hooks/useScreenTransition"; import { useScreenTransition } from "../../hooks/useScreenTransition";
import { gentleSpring, uiSpring } from "../../lib/motion"; import { gentleSpring, uiSpring } from "../../lib/motion";
import { VaultCore } from "./VaultCore"; import { VaultCore } from "./VaultCore";
import type { CoreSignal } from "../../lib/blackhole/controller"; 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 { createActivity, observeStatuses, type FailureCause } from "../../lib/orbitActivity";
import { applyActivity, createField, fieldActive, starPose, stepField, type FieldEvent } from "../../lib/rocket"; import { applyActivity, createField, fieldActive, starPose, stepField, type FieldEvent } from "../../lib/rocket";
import { RocketSprites, createSpriteRefs, paintSprites } from "./RocketSprites"; import { RocketSprites, createSpriteRefs, paintSprites } from "./RocketSprites";
@@ -44,6 +45,12 @@ const MAX_LABELS = 12;
const MAX_BIG_LABELS = 60; 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. */ /** 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; 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 clamp = (value: number) => Math.max(0, Math.min(1, value));
const ACCRETION_SECONDS = 6.4; const ACCRETION_SECONDS = 6.4;
/** Glow falloff, close to a gaussian so there is no visible edge. */ /** Glow falloff, close to a gaussian so there is no visible edge. */
@@ -102,13 +109,23 @@ export function BlackholeGalaxy({
const selectionX = useMotionValue(0); const selectionX = useMotionValue(0);
const selectionY = useMotionValue(0); const selectionY = useMotionValue(0);
const selectionPlaced = useRef(false); 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(() => () => { useLayoutEffect(() => () => {
rate.stop(); rate.stop();
reveal.stop(); reveal.stop();
selectionX.stop(); selectionX.stop();
selectionY.stop(); selectionY.stop();
}, [rate, reveal, selectionX, selectionY]); viewYaw.stop();
viewLift.stop();
}, [rate, reveal, selectionX, selectionY, viewYaw, viewLift]);
useLayoutEffect(() => { useLayoutEffect(() => {
if (reducedMotion) { if (reducedMotion) {
rate.jump(0); rate.jump(0);
@@ -144,7 +161,7 @@ export function BlackholeGalaxy({
useScreenTransition(frame, bigScreen, reducedMotion, setWidth); useScreenTransition(frame, bigScreen, reducedMotion, setWidth);
const selectedSlot = selectedOrbitId ? slots.get(selectedOrbitId) : undefined; 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 selectedX = selectedPosition?.x;
const selectedY = selectedPosition?.y; const selectedY = selectedPosition?.y;
useLayoutEffect(() => { useLayoutEffect(() => {
@@ -246,14 +263,25 @@ export function BlackholeGalaxy({
const wasEntering = entrance.current < 0.6; const wasEntering = entrance.current < 0.6;
if (slots.size) entrance.current = reducedMotion ? 0.6 : Math.min(0.6, entrance.current + delta); 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; 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) { for (const [node, { id, index }] of bodyNodes.current) {
const slot = slots.get(id)!; const slot = slots.get(id)!;
const { x, y } = orbitPose(slot, elapsed.current); const { x, y } = orbitPose(slot, elapsed.current, live);
const depth = y / (slot.radius * ORBIT_TILT); const depth = y / (slot.radius * tiltOf(live));
const appear = entering ? clamp((entrance.current - Math.min(index * 0.013, 0.33)) / 0.23) : 1; 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("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)!; const body = bodyNodes.current.get(node)!;
body.x = x; body.x = x;
body.y = y; body.y = y;
@@ -261,7 +289,7 @@ export function BlackholeGalaxy({
// fades out as the map stops. // fades out as the map stops.
body.trail ??= node.querySelector<SVGGElement>(".marker-trail"); body.trail ??= node.querySelector<SVGGElement>(".marker-trail");
if (body.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))); 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))); body.life.setAttribute("opacity", String(1 - depth * 0.45 * (1 - wave)));
} }
} }
if (moving && selectedSlot) { if ((moving || viewChanged) && selectedSlot) {
const point = orbitPose(selectedSlot, elapsed.current); const point = orbitPose(selectedSlot, elapsed.current, live);
selectionX.jump(point.x); selectionX.jump(point.x);
selectionY.jump(point.y); selectionY.jump(point.y);
} }
@@ -298,7 +326,7 @@ export function BlackholeGalaxy({
return slot ? starPose(slot, elapsed.current, speed) : undefined; return slot ? starPose(slot, elapsed.current, speed) : undefined;
}; };
if (dt > 0) for (const event of stepField(field.current, dt, starOf)) outcome(event); 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); 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. // 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; const phase = (diskTime.current % ACCRETION_SECONDS) / ACCRETION_SECONDS;
core.current?.style.setProperty("--accretion-offset", String(-100 * phase)); 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.time = diskTime.current;
signal.absorption = absorption; signal.absorption = absorption;
signal.yaw = live.yaw;
signal.lift = live.lift;
signal.wake?.(); signal.wake?.();
} }
const coreStyle = core.current?.style; const coreStyle = core.current?.style;
@@ -351,7 +381,7 @@ export function BlackholeGalaxy({
const scale = width / SCENE_WIDTH; const scale = width / SCENE_WIDTH;
const height = SCENE_HEIGHT * scale; const height = SCENE_HEIGHT * scale;
const hitRadius = Math.max(12, scale ? 12 / scale : 12); 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 const moons = selectedPosition
? moonPoses(selectedPosition, recentSnapshots.length, 2 * hitRadius + 3, positions) ? moonPoses(selectedPosition, recentSnapshots.length, 2 * hitRadius + 3, positions)
: []; : [];
@@ -376,7 +406,7 @@ export function BlackholeGalaxy({
const markers = positions.map((point) => box(point, 7)); const markers = positions.map((point) => box(point, 7));
const core = box({ x: 0, y: 0 }, 65 * scale); const core = box({ x: 0, y: 0 }, 65 * scale);
labels = placeLabels(labelCandidates.map(({ id, name }) => { 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) }; 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); }), 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 ( 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"> <svg viewBox={`${-HALF_WIDTH} ${-HALF_HEIGHT} ${SCENE_WIDTH} ${SCENE_HEIGHT}`} aria-hidden="true">
<defs> <defs>
<radialGradient id={knockoutId}> <radialGradient id={knockoutId}>
@@ -482,7 +582,7 @@ export function BlackholeGalaxy({
</defs> </defs>
<g className="orbit-tracks" pointerEvents="none"> <g className="orbit-tracks" pointerEvents="none">
{orbitRadii.map((radius) => ( {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) => { ref={(node) => {
if (!node) return; if (!node) return;
ringNodes.current.set(radius, node); ringNodes.current.set(radius, node);
@@ -543,7 +643,7 @@ export function BlackholeGalaxy({
</span> </span>
))} ))}
{bigScreen && focusLabel && ( {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} {orbitStatus(shownStatus(visible.find(({ id }) => id === selectedOrbitId)!)).label}
</span> </span>
)} )}

View File

@@ -1,6 +1,6 @@
import { useId } from "react"; import { useId } from "react";
import { ABSORB_LINGER, MAX_ROCKETS, infallLook, screenRadius, type Field, type Rocket, type StarPose } from "../../lib/rocket"; 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 { SCENE_UNITS_PER_M } from "../../lib/blackhole/layout";
import { advanceTrail, smoothPath, trailLength, type Trail } from "../../lib/trail"; import { advanceTrail, smoothPath, trailLength, type Trail } from "../../lib/trail";
@@ -98,15 +98,18 @@ export type PaintContext = {
/** Seconds, for the engine flicker. */ /** Seconds, for the engine flicker. */
time: number; time: number;
dt: 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. */ /** Move every sprite to match the field. Called once per frame by the scene loop. */
export function paintSprites(refs: SpriteRefs, field: Field, context: PaintContext) { export function paintSprites(refs: SpriteRefs, field: Field, context: PaintContext) {
const view = context.view ?? DEFAULT_VIEW;
let slot = 0; let slot = 0;
for (const rocket of field.rockets.values()) { for (const rocket of field.rockets.values()) {
const node = refs.rockets[slot]; const node = refs.rockets[slot];
if (!node || slot >= MAX_ROCKETS) break; if (!node || slot >= MAX_ROCKETS) break;
paintRocket(refs, slot, node, rocket, context); paintRocket(refs, slot, node, rocket, context, view);
slot++; slot++;
} }
for (; slot < MAX_ROCKETS; slot++) { for (; slot < MAX_ROCKETS; slot++) {
@@ -123,8 +126,9 @@ export function paintSprites(refs: SpriteRefs, field: Field, context: PaintConte
const node = refs.debris[index]; const node = refs.debris[index];
if (!node) return; if (!node) return;
const fade = Math.max(0, 1 - piece.age / piece.life); const fade = Math.max(0, 1 - piece.age / piece.life);
node.setAttribute("cx", String(piece.x)); const at = project(piece.x, piece.y, view);
node.setAttribute("cy", String(piece.y * ORBIT_TILT)); 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("r", String(piece.size * (0.6 + 0.4 * fade)));
node.setAttribute("opacity", String(fade ** 1.4)); 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; if (!node || !star || flare >= refs.flares.length) continue;
flare++; flare++;
const value = Math.max(0, spring.value); const value = Math.max(0, spring.value);
node.setAttribute("cx", String(star.x)); const at = project(star.x, star.y, view);
node.setAttribute("cy", String(star.y * ORBIT_TILT)); node.setAttribute("cx", String(at.x));
node.setAttribute("cy", String(at.y));
node.setAttribute("r", String(7 + 22 * (1 - value))); node.setAttribute("r", String(7 + 22 * (1 - value)));
node.setAttribute("opacity", String(0.85 * 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"); 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; if (node.dataset.orbit !== rocket.id) node.dataset.orbit = rocket.id;
const sx = rocket.x; const { x: sx, y: sy } = project(rocket.x, rocket.y, view);
const sy = rocket.y * ORBIT_TILT;
// Heading follows the screen-space velocity, smoothed so an interruption turns the rocket instead of snapping it. // Heading follows the screen-space velocity, smoothed so an interruption turns the rocket instead of snapping it.
const vx = rocket.vx; const { x: vx, y: vy } = project(rocket.vx, rocket.vy, view);
const vy = rocket.vy * ORBIT_TILT;
const previous = headings.get(node) ?? Math.atan2(vy, vx); const previous = headings.get(node) ?? Math.atan2(vy, vx);
let heading = previous; let heading = previous;
if (Math.hypot(vx, vy) > 4) { 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 .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); } .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 */ /* 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 { 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); } .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; 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 .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-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) { @media (max-width: 900px) {
.big-screen { --edge: 24px; } .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-topbar-tools { top: auto; bottom: 84px; }
.big-screen .vault-overview { display: none; } .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 { cancelFrame, frame as frameLoop } from "motion/react";
import { elevationOf } from "../galaxyLayout.ts";
import { farthestCornerM, layoutFor } from "./layout"; import { farthestCornerM, layoutFor } from "./layout";
import { createLook, jumpLook, requestLook, stepLook, styleAt, waveParams, type Look } from "./look"; import { createLook, jumpLook, requestLook, stepLook, styleAt, waveParams, type Look } from "./look";
import { CALIBRATION_SAMPLES, QUALITY_TIERS, chooseTier, initialTier } from "./quality"; import { CALIBRATION_SAMPLES, QUALITY_TIERS, chooseTier, initialTier } from "./quality";
@@ -8,6 +9,9 @@ import { createBlackholeRenderer, defaultParams, type BlackholeParams } from "./
export type CoreSignal = { export type CoreSignal = {
time: number; time: number;
absorption: 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; wake?: () => void;
/** The look at a distance from the hole, in gravitational radii: 0 realistic .. 1 radar. Set by the renderer. */ /** The look at a distance from the hole, in gravitational radii: 0 realistic .. 1 radar. Set by the renderer. */
lookAt?: (radiusM: number) => number; lookAt?: (radiusM: number) => number;
@@ -63,6 +67,8 @@ export function createBlackholeController({ canvas, panel, frame, signal, onLost
const params: BlackholeParams = { ...defaultParams }; const params: BlackholeParams = { ...defaultParams };
let queued = false; let queued = false;
let lastDraw = 0; let lastDraw = 0;
let drawnYaw = 0;
let drawnLift = 0;
let trackUntil = 0; let trackUntil = 0;
let forced = true; let forced = true;
let frozenTime = signal.time; 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 radar = look.to === 1 || look.from === 1;
const motion = !reduced && preset.maxFps > 0; const motion = !reduced && preset.maxFps > 0;
const sweepTarget = radar && motion ? 1 : 0; const sweepTarget = radar && motion ? 1 : 0;
// The still tier freezes ambient motion, but a capture still plays out at a low rate. // 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
const cap = preset.maxFps > 0 ? preset.maxFps : signal.absorption > 0 ? 15 : 0; // 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; const free = tracking || waving;
if (!free && !forced && cap === 0 && Math.abs(sweepTarget - sweepAmount) < 0.004) return; if (!free && !forced && cap === 0 && Math.abs(sweepTarget - sweepAmount) < 0.004) return;
if (!free && !forced && now - lastDraw < 1000 / cap - 2) { 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; const time = preset.maxFps > 0 ? signal.time : frozenTime;
params.sway = 0.06 * Math.sin(time * 0.05); params.sway = 0.06 * Math.sin(time * 0.05);
params.absorb = signal.absorption; params.absorb = signal.absorption;
params.azimuth = signal.yaw ?? 0;
params.elevation = elevationOf(signal.lift ?? 0);
gpu.render(time, params); gpu.render(time, params);
drawnYaw = signal.yaw ?? 0;
drawnLift = signal.lift ?? 0;
lastDraw = now; lastDraw = now;
forced = false; forced = false;
if (tracking || look.running || sweepTarget > 0 || sweepAmount !== sweepTarget) schedule(); 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 * 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. * 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. */ /** 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; export const SCENE_UNITS_PER_M = SHADOW_SCENE_RADIUS / CRITICAL_IMPACT;
const PX_PER_M_SCENE = SCENE_UNITS_PER_M; 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 = { export type BlackholeParams = {
/** Camera elevation above the disk plane, radians. */ /** Camera elevation above the disk plane, radians. */
elevation: number; elevation: number;
/** Camera yaw round the hole, radians. */
azimuth: number;
diskIn: number; diskIn: number;
diskOut: number; diskOut: number;
diskGain: number; diskGain: number;
@@ -51,6 +53,7 @@ export type BlackholeParams = {
export const defaultParams: BlackholeParams = { export const defaultParams: BlackholeParams = {
elevation: (8 * Math.PI) / 180, elevation: (8 * Math.PI) / 180,
azimuth: 0,
diskIn: ISCO, diskIn: ISCO,
diskOut: 26, diskOut: 26,
diskGain: 2.1, diskGain: 2.1,
@@ -241,6 +244,7 @@ export function createBlackholeRenderer(canvas: HTMLCanvasElement, options: { sk
gl.uniform2f(scene.uniform("uCenter"), centerX * scale, centerY * scale); gl.uniform2f(scene.uniform("uCenter"), centerX * scale, centerY * scale);
gl.uniform1f(scene.uniform("uPxPerM"), pxPerM * scale); gl.uniform1f(scene.uniform("uPxPerM"), pxPerM * scale);
gl.uniform1f(scene.uniform("uElevation"), params.elevation); gl.uniform1f(scene.uniform("uElevation"), params.elevation);
gl.uniform1f(scene.uniform("uAzimuth"), params.azimuth);
gl.uniform1f(scene.uniform("uTime"), time); gl.uniform1f(scene.uniform("uTime"), time);
gl.uniform1f(scene.uniform("uSway"), params.sway); gl.uniform1f(scene.uniform("uSway"), params.sway);
gl.uniform1f(scene.uniform("uDiskIn"), params.diskIn); 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 vec2 uCenter; // hole centre in target pixels, y up
uniform float uPxPerM; // target pixels per gravitational radius uniform float uPxPerM; // target pixels per gravitational radius
uniform float uElevation; // camera elevation above the disk plane, radians 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 uTime; // disk clock, seconds
uniform float uSway; // sky yaw, radians uniform float uSway; // sky yaw, radians
uniform float uSky; // sky brightness uniform float uSky; // sky brightness
@@ -340,9 +341,13 @@ vec3 diskLight(vec3 hit, vec3 dir) {
void main() { void main() {
vec2 p = (gl_FragCoord.xy - uCenter) / uPxPerM; vec2 p = (gl_FragCoord.xy - uCenter) / uPxPerM;
vec3 camera = vec3(0.0, sin(uElevation), cos(uElevation)); // The camera stands on a sphere round the hole: uElevation above the disk plane, uAzimuth round it. At azimuth 0
vec3 right = vec3(1.0, 0.0, 0.0); // this is the original (0, sin e, cos e) view.
vec3 up = vec3(0.0, cos(uElevation), -sin(uElevation)); 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 pos = camera * START_RADIUS + right * p.x + up * p.y;
vec3 vel = -camera; vec3 vel = -camera;

View File

@@ -53,18 +53,56 @@ export function assignOrbitSlots(
return next; 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 { return {
x: Math.cos(angle) * slot.radius, 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. */ /** Screen direction, in radians, from a marker back along its orbit: where its trail points. */
export function trailAngle(slot: OrbitSlot, time: number): number { export function trailAngle(slot: OrbitSlot, time: number, view: View = DEFAULT_VIEW): number {
const angle = slot.angle + time * slot.speed; const angle = slot.angle + time * slot.speed + view.yaw;
return Math.atan2(-Math.cos(angle) * slot.radius * ORBIT_TILT, Math.sin(angle) * slot.radius); 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[] { export function moonPoses(star: Vec2, count: number, distance: number, obstacles: Vec2[] = []): Vec2[] {