Align motion, look and corridor on +Z (forward)

Camera was moving in (1, 0.7) but looking mostly in +Z — 55
deg between them meant tiles collected along motion weren't in
the user's forward view. Now:
- ro = (0, 2.2, drift) \u2014 motion purely in +Z
- GROUND_TRAVEL_COS/SIN = (0, 1) \u2014 corridor runs along +Z
- rd = mostly forward +Z, with downward tilt for the ground view

Everything (motion, look, tile collection) is now on the same
+Z axis. Tiles appear directly in front of the camera as it
moves forward, no more 45-55 deg offset.
This commit is contained in:
Richard Zink committed 2026-10-07 21:08:48 +02:00
1 parent 930fd2b2f1
commit 587c8f4a19
1 file changed
+7 -7
+7 -7
View File
@@ -139,7 +139,7 @@ var FRAG_SRC = [
'float drift = uTime * uSpeed * 0.45;',
// Fixed altitude well above the cloud ceiling (y=1.5).
'float camY = 2.2;',
'vec3 ro = vec3(drift, camY, drift * 0.7);',
'vec3 ro = vec3(0.0, camY, drift);',
// Ray direction: tilt more downward so the visible ground fits
// within the mosaic. At uv.y = 0 the ray goes ~26° below
// horizontal, putting the visible ground at tGround < 5
@@ -271,12 +271,10 @@ function init(canvas) {
var GROUND_TILE_URL = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/';
var GROUND_TILE_Z = 11;
var GROUND_TILE_SIZE = 256;
// Camera travels at uTime * uSpeed * 0.45 in +X (and +X*0.7 in +Z).
// Travel angle: atan2(0.7, 1) ~ 35 deg. Normalised: cos=0.82, sin=0.57.
// The corridor is ROTATED to follow the actual travel direction so
// tiles aren't wasted in regions the camera never reaches.
var GROUND_TRAVEL_COS = 0.82; // cos(35 deg), = 1 / sqrt(1 + 0.49)
var GROUND_TRAVEL_SIN = 0.57; // sin(35 deg), = 0.7 / sqrt(1.49)
// Camera travels in +Z (forward) and looks in +Z (also forward).
// The corridor is aligned with both motion and look direction.
var GROUND_TRAVEL_COS = 0.0; // cos(90 deg)
var GROUND_TRAVEL_SIN = 1.0; // sin(90 deg)
var GROUND_CORRIDOR_LONG = 15; // tiles along the travel direction
var GROUND_CORRIDOR_PERP = 5; // tiles perpendicular to travel
var GROUND_BUFFER_LONG = 2; // refetch when this close to forward edge
@@ -369,6 +367,8 @@ function maybeRefetchGround(cameraWorldX, cameraWorldZ, gl) {
var cameraTileX = GROUND_BASE_X + Math.floor(cameraWorldX);
var cameraTileY = GROUND_BASE_Y + Math.floor(cameraWorldZ);
// Project camera offset onto the corridor's rotated axes.
// With GROUND_TRAVEL_COS/SIN = (0, 1) the corridor runs along
// +Z (camera's motion + look direction).
var dx = cameraTileX - groundCenterTile.x;
var dy = cameraTileY - groundCenterTile.y;
var projLong = dx * GROUND_TRAVEL_COS + dy * GROUND_TRAVEL_SIN;