Files
gods-eye-view/src/render/stub/math.js
T
Sameh Khamis 0349941b71 Read a moving icon's position and course through one shared evaluator
render/motion/iconMotion evaluates a draw item's motion segment and course
glide at a time on the set's motion clock, without a renderer: where the
item is drawn, the course it is drawn with, and when its motion ends. The app
can now read a moving icon back (to follow it, label it, judge a pick or
its horizon) the way the renderer draws it.

The stub renderer evaluates its segments with it, in place of its own copy,
and so now steps a lerp with no span 1 ms after t0, as the Cesium renderer
does. The Cesium GPU icon sets read the course shown before a write, a
blend's target and when rows stop moving through it, from copies of what
they wrote, and write each glide with the offset it computes, so an exact
half turn goes the way the app reads it.

norm360/norm180 and Position-to-ECEF move to geo for both to share.
Conformance gains a check that icons are drawn where the evaluator puts
them.
2026-11-07 02:36:39 -08:00

79 lines
2.2 KiB
JavaScript

/**
* @module render/stub/math
* @description The maths the stub renderer poses its camera with: the shared
* geodesy (`src/geo`) and the camera angle conventions of the contract
* (heading clockwise from north, pitch negative looking down).
*
* The formulas follow the default renderer's, step for step, so the stub's
* poses match its reference traces to floating-point noise.
*/
import {
PI_OVER_TWO,
TWO_PI,
acosClamped,
clamp,
equalsEpsilon,
negate,
rotate,
scale,
vec,
zeroToTwoPi,
} from '../../geo/index.js';
export * from '../../geo/index.js';
/** A contract `Position` (`Ecef` or `LonLatH`, degrees), as ECEF. */
export { positionToEcef as toEcef } from '../../geo/ellipsoid.js';
const EPSILON3 = 1e-3;
const EPSILON10 = 1e-10;
/**
* The rotation the contract's heading, pitch and roll describe in a local
* east-north-up frame, as its three columns: the direction, the left axis
* and the up vector.
*/
export function headingPitchRollColumns(heading, pitch, roll) {
const h = heading - PI_OVER_TWO;
const rotateAll = (v) =>
rotate(
rotate(rotate(v, vec(1, 0, 0), roll), vec(0, 1, 0), -pitch),
vec(0, 0, 1),
-h,
);
return {
direction: rotateAll(vec(1, 0, 0)),
left: rotateAll(vec(0, 1, 0)),
up: rotateAll(vec(0, 0, 1)),
};
}
/** Heading of a local direction and up, radians clockwise from north. */
export function headingOf(direction, up) {
const h = !equalsEpsilon(Math.abs(direction.z), 1.0, EPSILON3)
? Math.atan2(direction.y, direction.x) - PI_OVER_TWO
: Math.atan2(up.y, up.x) - PI_OVER_TWO;
return TWO_PI - zeroToTwoPi(h);
}
export const pitchOf = (direction) => PI_OVER_TWO - acosClamped(direction.z);
export function rollOf(direction, up, right) {
if (equalsEpsilon(Math.abs(direction.z), 1.0, EPSILON3)) return 0;
return zeroToTwoPi(Math.atan2(-right.z, up.z) + TWO_PI);
}
/** The local offset a heading, pitch and range puts the eye at. */
export function offsetFromHeadingPitchRange(heading, pitch, range) {
const p = clamp(pitch, -PI_OVER_TWO, PI_OVER_TWO);
const h = zeroToTwoPi(heading) - PI_OVER_TWO;
const offset = rotate(
rotate(vec(1, 0, 0), vec(0, 1, 0), -p),
vec(0, 0, 1),
-h,
);
return scale(negate(offset), range);
}
export { EPSILON10 };