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,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[] {