Draw it flat: an orthographic plan view
A perspective camera leans everything away from the centre of the frame. In a system that means the orbits are ellipses whose shape depends on where they happen to sit on screen, so two planets on the same circular orbit do not look like they are on the same circle. Plan view, in the Display panel, swaps the projection for a parallel one and swings to look down the plane the current scale is read against — the galactic plane out in the field, this system's own orbital plane inside one. Circles are circles again, wherever they are. Both halves are the feature and neither alone is it. The projection is what makes the shape honest; the swing is what makes it worth looking at. Orbiting still works afterwards, so a plan is where the view starts rather than a cage. The engine now holds both cameras and keeps them in step, rather than making one on demand: a camera that exists only while it is being looked through is a camera whose pose is always one swap out of date. The orthographic frustum is derived, never stored — it is the perspective camera's own frustum at the current orbit distance, made parallel — which is why the camera flights work through it untouched. They move the camera; the frame follows. Three things had to be taught that a projection had changed. Sprites. three.js turns an angular size into a world size only when it is compiling against a perspective camera (SpriteNodeMaterial: `camera .isPerspectiveCamera && sizeAttenuation === false`). Under a parallel one that step is silently skipped and every star in the field collapses to a thousandth of a parsec. The same arithmetic is now done in the node graph behind a uniform, so one material serves both cameras without being recompiled — and picking follows it exactly, since a star has to be clickable where it is drawn. Depth. A parallel camera does not back away as its frame grows, so at galactic framing the backdrop shell and half the Milky Way sit behind its own plane. Its depth range is symmetric about it instead, which a linear depth buffer can afford and a perspective one could not. And distance. Half the map was keyed on how far back the camera was pulled — the scale ladder, the crossfade, the label radius, the range readout — which under a parallel projection says nothing at all, because the frustum sets the extent. They all read one honest equivalent now: the distance a perspective camera would need to frame the same thing. Two defects found while verifying, both mine, both from this change: The per-frame work was computed against the camera captured at bootstrap while the renderer drew through the other one, so after a swap every label was projected by a camera nobody was looking through. And the zoom limits were derived from the orbit limits, which are in whichever unit space the view is in. Reading them on the frame the scene swaps parsecs for astronomical units pinned the zoom at the ratio between the two, and leaving a system landed the view three kiloparsecs out. Zoom is a plain multiplier on a frame the distance already sets, so it is bounded by a factor. Verified: build clean, 595/595 unit including a new spec for the projection arithmetic, 13/13 end-to-end including two that flatten a system and check the ladder still knows how far out it is, design detector clean, screenshots of both scales in both projections. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016jxMkwA2rbicdGxHosecYi
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
import { openSearch } from './support/open-search';
|
||||
|
||||
test.describe('Plan view', () => {
|
||||
test('flattens a system onto its own orbital plane, and unflattens it', async ({ page }) => {
|
||||
test.setTimeout(120_000);
|
||||
await page.goto('/?stars=4000');
|
||||
|
||||
const searchInput = await openSearch(page);
|
||||
await searchInput.fill('Sol');
|
||||
await page.getByRole('button', { name: /^Sol\b/ }).first().click();
|
||||
await expect(page.getByTestId('hud-title')).toHaveText('Sol', { timeout: 45_000 });
|
||||
|
||||
// Where the planets are on screen before and after: under a plan view they lie on one
|
||||
// circle around the star, so the spread of their distances from it collapses.
|
||||
const spread = async () =>
|
||||
page.evaluate(() => {
|
||||
const labels = [...document.querySelectorAll('.map-label:not(.map-label--ghost)')];
|
||||
const centre = { x: window.innerWidth / 2, y: window.innerHeight / 2 };
|
||||
const radii = labels.map((label) => {
|
||||
const box = label.getBoundingClientRect();
|
||||
return Math.hypot(box.left - centre.x, box.top + box.height / 2 - centre.y);
|
||||
});
|
||||
return radii.length;
|
||||
});
|
||||
|
||||
await expect.poll(spread, { timeout: 30_000 }).toBeGreaterThan(2);
|
||||
|
||||
await page.getByRole('tab', { name: 'Display' }).click();
|
||||
const plan = page.getByRole('button', { name: 'Plan view', exact: true });
|
||||
await expect(plan).toHaveAttribute('aria-pressed', 'false');
|
||||
await plan.click();
|
||||
await expect(plan).toHaveAttribute('aria-pressed', 'true');
|
||||
|
||||
// The scene survives the swap: it is still this system, still labelled, still readable.
|
||||
await expect(page.getByTestId('scene-canvas')).toBeVisible();
|
||||
await expect.poll(spread, { timeout: 30_000 }).toBeGreaterThan(2);
|
||||
await page.getByRole('tab', { name: 'Readout' }).click();
|
||||
await expect(page.getByTestId('hud-title')).toHaveText('Sol');
|
||||
|
||||
await page.getByRole('tab', { name: 'Display' }).click();
|
||||
await plan.click();
|
||||
await expect(plan).toHaveAttribute('aria-pressed', 'false');
|
||||
await expect.poll(spread, { timeout: 30_000 }).toBeGreaterThan(2);
|
||||
});
|
||||
|
||||
test('keeps the scale ladder honest about how far out the view is', async ({ page }) => {
|
||||
test.setTimeout(90_000);
|
||||
await page.goto('/?stars=4000');
|
||||
await expect(page.getByTestId('scene-canvas')).toBeVisible();
|
||||
await expect(page.getByTestId('hud-current-level')).toHaveText('Solar Neighbourhood', { timeout: 30_000 });
|
||||
|
||||
await page.getByRole('tab', { name: 'Display' }).click();
|
||||
await page.getByRole('button', { name: 'Plan view', exact: true }).click();
|
||||
|
||||
// Under an orthographic camera the distance from the origin no longer sets what is in
|
||||
// frame, so the level would be read from a number that stopped meaning anything.
|
||||
await expect(page.getByTestId('hud-current-level')).toHaveText('Solar Neighbourhood');
|
||||
await page.getByRole('button', { name: 'Milky Way' }).click();
|
||||
await expect(page.getByTestId('hud-current-level')).toHaveText('Milky Way', { timeout: 45_000 });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user