garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/adr/019-planet-scale-floating-origin.md

raw

ADR-019: Planet-Scale Floating-Origin Coordinate Model


Metadata:


Context

Problem: The roadmap direction is a two-tier world: a planet-scale, read-only OSM map surface (streamed tiles + procedurally extruded OSM buildings) onto which discrete, mutable simulation regions are activated ("converting" a building turns a map area into an authoritative sim region). Today every entity renders in absolute f32 world space clustered near the origin (regions at sim_origin or a ±300 m grid; camera, avatar, and ground-height math all raw f32). That is fine at ±a few km and breaks at planet scale.

Bevy renders transforms in f32. Earth's circumference is ~40,000 km; the f32 ULP (smallest expressible position step) near 4×10⁷ m is ~4.7 m. Absolute planet coordinates in f32 therefore produce meter-scale jitter, z-fighting, and broken picking — the model in ADR-006 (region origins in sim units, "good enough" approximation) has no answer for content placed far from the origin.

Requirements:

Decision

Adopt a floating-origin (camera-relative) coordinate model: store each entity's true position in high precision (global frame) and continuously rebase the Bevy render origin near the camera so all rendered f32 transforms stay within a few km of (0,0,0), where f32 precision is ample.

Approach:

Rationale

Primary Reasoning:

  1. Measured, not assumed: a throwaway spike (--spike-floating-origin, module crates/cartopolis/src/systems/floating_origin.rs, 2026-06-19) directly measured the f32 ULP at planet scale and the floating-origin remedy. The result (below) closes the precision risk that gates the whole planet-scale direction.
  2. Minimal blast radius: rebasing keeps the existing f32 render/ECS/picking path; only placement and a per-frame sync are added. The spike confirmed the existing free camera cooperated.
  3. Honest scale: pairing a global frame with per-region ENU tangent frames keeps physics in real meters despite Mercator distortion (the unresolved tension in ADR-006).

Spike evidence (markers at global X = 0, 1e6, 1e7, 2e7 m):

ModeDistancef32 ULP (ulp_m)Observed
Absolute f32 (no rebase)1×10⁷ m~1.0 mvisible ~1 m jitter
Absolute f32 (no rebase)2×10⁷ m~2.0 m~2 m jitter; two cubes 0.1 m apart merged into one
Floating originup to 2×10⁷ m~2.4×10⁻⁷ msub-micron, rock stable

Alternatives Considered:

AlternativeProsConsRejected Because
Keep absolute f32 (ADR-006 as-is)No new code~1–2 m jitter at planet scale (measured)Fails the planet-scale requirement
f64 everywhere in renderConceptually simpleBevy renders f32; GPU is f32; pervasive conversionDoesn't remove the f32 GPU limit
Per-region local origins only (no global frame)Simple per islandNo continuous browsable planet surface between regionsMap tier needs a continuous global frame
Hand-rolled GlobalPos + syncFull control; exposes ULP for measurementReinvents grid/rebase machineryFallback the spike used; not needed once big_space fit
Adopt big_spaceGrid + rebase for freeNew dependency; must fit camera/picking/atmosphere; upstream lags BevyAdopted — vendored fork advanced to Bevy 0.19

Consequences

Positive:

Negative:

Related