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:
@@ -1,6 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
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";
|
||||
|
||||
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));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user