@johnmorrisdotca/chikyu-earth 0.52.0 → 0.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +4 -2
  3. package/dist/flat/colours.d.ts +55 -0
  4. package/dist/flat/colours.js +71 -0
  5. package/dist/flat/define.d.ts +3 -0
  6. package/dist/flat/define.js +6 -0
  7. package/dist/flat/element.d.ts +188 -0
  8. package/dist/flat/element.js +1541 -0
  9. package/dist/flat/facts.d.ts +172 -0
  10. package/dist/flat/facts.js +168 -0
  11. package/dist/flat/geometry.d.ts +160 -0
  12. package/dist/flat/geometry.js +156 -0
  13. package/dist/flat/index.d.ts +6 -0
  14. package/dist/flat/index.js +7 -0
  15. package/dist/flat/track-state.d.ts +174 -0
  16. package/dist/flat/track-state.js +223 -0
  17. package/dist/flat/words.d.ts +25 -0
  18. package/dist/flat/words.js +78 -0
  19. package/dist/passes/index.d.ts +2 -1
  20. package/dist/passes/index.js +1 -1
  21. package/dist/passes/passes.d.ts +34 -0
  22. package/dist/passes/passes.js +43 -2
  23. package/dist/realistic/element-base.d.ts +6 -0
  24. package/dist/realistic/element-base.js +15 -2
  25. package/dist/space/compass.d.ts +36 -0
  26. package/dist/space/compass.js +72 -0
  27. package/dist/space/element-base.d.ts +48 -1
  28. package/dist/space/element-base.js +95 -6
  29. package/dist/space/index.d.ts +2 -1
  30. package/dist/space/index.js +1 -0
  31. package/dist/space/north-up.d.ts +86 -0
  32. package/dist/space/north-up.js +104 -0
  33. package/dist/space/path-controls.d.ts +1 -1
  34. package/dist/space/path-controls.js +13 -2
  35. package/dist/space/path-ribbons.d.ts +4 -0
  36. package/dist/space/path-ribbons.js +8 -4
  37. package/dist/space/satellite-layer.d.ts +5 -0
  38. package/dist/space/satellite-layer.js +16 -4
  39. package/dist/space/scene.d.ts +23 -0
  40. package/dist/space/scene.js +18 -1
  41. package/package.json +13 -1
@@ -0,0 +1,104 @@
1
+ import { satelliteAxes } from "./satellite-model.js";
2
+ const RAD = Math.PI / 180;
3
+ /**
4
+ * How close to a pole, in degrees of arc, a satellite must be for north-up to give way to travel-up: inside this, north's direction on the ground swings round faster than a picture can follow (and at the pole itself it has none), so the way it is going is at the top.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { NORTH_UP_POLE_DEG } from "@johnmorrisdotca/chikyu-earth/space";
9
+ *
10
+ * console.log(NORTH_UP_POLE_DEG);
11
+ * ```
12
+ */
13
+ export const NORTH_UP_POLE_DEG = 3;
14
+ /**
15
+ * How many more degrees from a pole north-up takes to come back in: travel-up holds inside {@link NORTH_UP_POLE_DEG}, north-up holds beyond that many degrees more, and between them the two are mixed by a smooth step so the picture turns, never jumps.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { NORTH_UP_BLEND_DEG } from "@johnmorrisdotca/chikyu-earth/space";
20
+ *
21
+ * console.log(NORTH_UP_BLEND_DEG);
22
+ * ```
23
+ */
24
+ export const NORTH_UP_BLEND_DEG = 3;
25
+ /**
26
+ * Which way north is at a place, as a unit vector in the scene's axes (y is north): the way along the ground that goes towards the pole. `null` at the poles themselves and at the centre, where it is not defined.
27
+ *
28
+ * @param position - Where the place is, from the Earth's centre, in any unit.
29
+ * @returns A unit vector level with the ground there, or `null`.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { localNorth } from "@johnmorrisdotca/chikyu-earth/space";
34
+ *
35
+ * console.log(localNorth([1.066, 0, 0]));
36
+ * ```
37
+ */
38
+ export function localNorth(position) {
39
+ const length = Math.hypot(position[0], position[1], position[2]);
40
+ if (!(length > 0))
41
+ return null;
42
+ const up = [position[0] / length, position[1] / length, position[2] / length];
43
+ const level = [-up[1] * up[0], 1 - up[1] * up[1], -up[1] * up[2]];
44
+ const size = Math.hypot(level[0], level[1], level[2]);
45
+ return size > 1e-9 ? [level[0] / size, level[1] / size, level[2] / size] : null;
46
+ }
47
+ /**
48
+ * The turn that puts north at the top of the picture of the view above a satellite (`aboveAxes` turns the picture by its `yaw`, from the way the satellite is going at the top), and how much of it holds. Add `yaw * weight` to the picture's own turn. The weight is 1 away from the poles,
49
+ * 0 within {@link NORTH_UP_POLE_DEG} degrees of one (the way it is going stays at the top), and a smooth step between, over {@link NORTH_UP_BLEND_DEG} degrees. A satellite that is not moving has no way to turn from, and gives a weight of 0.
50
+ *
51
+ * @param position - Where the satellite is, from the Earth's centre.
52
+ * @param velocity - The way it is going.
53
+ * @returns The yaw in radians (positive turns the top towards the left of the way it goes) and its weight, 0 to 1.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { northUpYaw } from "@johnmorrisdotca/chikyu-earth/space";
58
+ *
59
+ * // over the equator going east: north is on the left, a quarter turn
60
+ * const turn = northUpYaw([1.066, 0, 0], [0, 0, -7.66]);
61
+ * console.log((turn.yaw / (Math.PI / 180)).toFixed(0), turn.weight);
62
+ * ```
63
+ */
64
+ export function northUpYaw(position, velocity) {
65
+ const axes = satelliteAxes(position, velocity);
66
+ const north = localNorth(position);
67
+ if (!axes || !north)
68
+ return { yaw: 0, weight: 0 };
69
+ const yaw = Math.atan2(north[0] * axes.y[0] + north[1] * axes.y[1] + north[2] * axes.y[2], north[0] * axes.x[0] + north[1] * axes.x[1] + north[2] * axes.x[2]);
70
+ // the angle from the nearer pole: the up vector's component along y is the cosine of the colatitude
71
+ const polar = Math.acos(Math.min(1, Math.abs(axes.z[1]))) / RAD;
72
+ const k = Math.min(1, Math.max(0, (polar - NORTH_UP_POLE_DEG) / NORTH_UP_BLEND_DEG));
73
+ return { yaw, weight: k * k * (3 - 2 * k) };
74
+ }
75
+ /**
76
+ * Where north points in a picture: the angle, clockwise from the top of the picture, of a direction as the camera sees it (the part of it in the picture's plane). 0 means north is at the top, 90 to the right. `null` when the direction points along the camera's line of sight (or away), where it has no direction in the picture.
77
+ *
78
+ * @param quaternion - The camera's turn, `[x, y, z, w]` as three.js has it (the camera looks along its own -z, with +y up and +x to the right).
79
+ * @param direction - The direction in the scene's axes, such as `localNorth`.
80
+ * @returns Degrees clockwise from the top of the picture, 0 up to 360, or `null`.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * import { screenAngle } from "@johnmorrisdotca/chikyu-earth/space";
85
+ *
86
+ * // a camera that is not turned: +y is at the top, +x to the right
87
+ * console.log(screenAngle([0, 0, 0, 1], [0, 1, 0]), screenAngle([0, 0, 0, 1], [1, 0, 0]));
88
+ * ```
89
+ */
90
+ export function screenAngle(quaternion, direction) {
91
+ // the direction in the camera's own axes: turned by the inverse of the camera's turn
92
+ const [qx, qy, qz, w] = quaternion;
93
+ const px = -qx;
94
+ const py = -qy;
95
+ const pz = -qz;
96
+ const tx = 2 * (py * direction[2] - pz * direction[1]);
97
+ const ty = 2 * (pz * direction[0] - px * direction[2]);
98
+ const tz = 2 * (px * direction[1] - py * direction[0]);
99
+ const x = direction[0] + w * tx + (py * tz - pz * ty);
100
+ const y = direction[1] + w * ty + (pz * tx - px * tz);
101
+ if (Math.hypot(x, y) < 1e-6)
102
+ return null;
103
+ return (((Math.atan2(x, y) / RAD) % 360) + 360) % 360;
104
+ }
@@ -2,7 +2,7 @@ import type { SatelliteRef } from "../satellites/types.ts";
2
2
  import type { SatelliteState } from "./satellite-layer.ts";
3
3
  import { MAX_PATHS, type PathHit, type PathRequest, type PathStyle } from "./paths.ts";
4
4
  /** The attributes the paths add to an element. */
5
- export declare const PATH_ATTRIBUTES: readonly ["selected-path", "path-hit", "path-priority"];
5
+ export declare const PATH_ATTRIBUTES: readonly ["selected-path", "path-light", "path-hit", "path-priority"];
6
6
  /** Which comes first under a pointer: a satellite's `dots` (the default), or `paths` (a path of the page's, unless the dot is of a satellite whose path is listed or that is chosen). Anything else is `dots`. */
7
7
  export type PathPriority = "dots" | "paths";
8
8
  export declare const readPathPriority: (value: string | null) => PathPriority;
@@ -1,6 +1,9 @@
1
+ // What the two satellite elements share for the page's paths: the list and the look table, the attributes `selected-path` and `path-hit`, the test of which path a pointer is on, and the events `chikyu-path-hover` and `chikyu-path-click`.
2
+ // One press means one thing, in this order: a satellite's dot, then a path, then the sky. The element asks {@link PathControls.press} after the dot and before anything else, and what it answers `true` to is not given to the sky.
3
+ import { TRACK_SHADOW, TRACK_SUNLIT } from "../flat/colours.js";
1
4
  import { capPaths, hitRadius, MAX_PATHS, readPathHit, styleTable } from "./paths.js";
2
5
  /** The attributes the paths add to an element. */
3
- export const PATH_ATTRIBUTES = ["selected-path", "path-hit", "path-priority"];
6
+ export const PATH_ATTRIBUTES = ["selected-path", "path-light", "path-hit", "path-priority"];
4
7
  export const readPathPriority = (value) => (value === "paths" ? "paths" : "dots");
5
8
  export const pointerOf = (event) => (event.pointerType === "touch" ? "touch" : event.pointerType === "pen" ? "pen" : "mouse");
6
9
  export function bindPaths(host) {
@@ -90,9 +93,17 @@ export function bindPaths(host) {
90
93
  },
91
94
  sync() {
92
95
  const on = element.getAttribute("selected-path") !== "off";
93
- if (on === state.paths.selectedOn)
96
+ // the chosen orbit in sunlight and in the Earth's shadow: `path-light="off"` keeps it one colour; the colours are the page's `--chikyu-path-sun` and `--chikyu-path-shadow`
97
+ const lightOn = !/^(off|false|no|0)$/i.test((element.getAttribute("path-light") ?? "").trim());
98
+ const style = getComputedStyle(element);
99
+ const sun = style.getPropertyValue("--chikyu-path-sun").trim() || TRACK_SUNLIT;
100
+ const shadow = style.getPropertyValue("--chikyu-path-shadow").trim() || TRACK_SHADOW;
101
+ const light = state.paths.light;
102
+ const lightChanged = lightOn !== light.on || sun !== light.sun || shadow !== light.shadow;
103
+ if (on === state.paths.selectedOn && !lightChanged)
94
104
  return;
95
105
  state.paths.selectedOn = on;
106
+ state.paths.light = { on: lightOn, sun, shadow };
96
107
  state.paths.version += 1;
97
108
  host.request();
98
109
  },
@@ -23,6 +23,10 @@ export interface RibbonPath {
23
23
  style: PathStyle;
24
24
  /** Earth radii from the camera over which the path fades in (nothing at the camera, all of its opacity at this distance); 0 or missing draws it at its look everywhere. */
25
25
  fade?: number;
26
+ /** One flag a point ({@link PATH_POINTS}): 1 where the segment that starts at the point is drawn in `darkInk` instead of the look's colour (the part of an orbit in the Earth's shadow). */
27
+ dark?: Uint8Array;
28
+ /** Any CSS colour: what the flagged segments are drawn in. Needed with `dark`. */
29
+ darkInk?: string;
26
30
  }
27
31
  export interface PathRibbons {
28
32
  /** Write the paths into the buffers, none for an empty list. Costs nothing on the GPU until the next draw, and nothing is drawn while there are no paths. */
@@ -134,13 +134,16 @@ export function createPathRibbons(three, scene) {
134
134
  mesh.visible = false;
135
135
  scene.add(mesh);
136
136
  const colour = new three.Color();
137
+ const shade = new three.Color();
137
138
  let count = 0;
138
139
  return {
139
140
  set(paths) {
140
141
  count = Math.min(PATH_SLOTS, paths.length);
141
142
  for (let p = 0; p < count; p += 1) {
142
- const { positions, style, fade = 0 } = paths[p];
143
+ const { positions, style, fade = 0, dark, darkInk } = paths[p];
143
144
  colour.set(style.color);
145
+ if (dark && darkInk)
146
+ shade.set(darkInk);
144
147
  // the arc length at each point, in Earth radii, for the dashes
145
148
  let along = 0;
146
149
  for (let i = 0; i < PATH_POINTS; i += 1) {
@@ -153,6 +156,7 @@ export function createPathRibbons(three, scene) {
153
156
  const bz = positions[j * 3 + 2];
154
157
  const length = Math.hypot(bx - ax, by - ay, bz - az);
155
158
  const q = p * PATH_POINTS + i;
159
+ const ink0 = dark && darkInk && dark[i] === 1 ? shade : colour;
156
160
  for (let k = 0; k < 4; k += 1) {
157
161
  const v = q * 4 + k;
158
162
  position[v * 3] = ax;
@@ -161,9 +165,9 @@ export function createPathRibbons(three, scene) {
161
165
  other[v * 3] = bx;
162
166
  other[v * 3 + 1] = by;
163
167
  other[v * 3 + 2] = bz;
164
- ink[v * 4] = colour.r;
165
- ink[v * 4 + 1] = colour.g;
166
- ink[v * 4 + 2] = colour.b;
168
+ ink[v * 4] = ink0.r;
169
+ ink[v * 4 + 1] = ink0.g;
170
+ ink[v * 4 + 2] = ink0.b;
167
171
  ink[v * 4 + 3] = style.opacity;
168
172
  look[v * 4] = style.width;
169
173
  look[v * 4 + 1] = style.dash ? style.dash[0] : 0;
@@ -48,6 +48,11 @@ export interface SatelliteState {
48
48
  requests: PathRequest[];
49
49
  overrides: Record<string, Partial<PathStyle> | null>;
50
50
  selectedOn: boolean;
51
+ light: {
52
+ on: boolean;
53
+ sun: string;
54
+ shadow: string;
55
+ };
51
56
  version: number;
52
57
  info: PathInfo[];
53
58
  dropped: number;
@@ -1,6 +1,8 @@
1
1
  import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
2
2
  import { satelliteEmphasis } from "./satellite-focus.js";
3
3
  import { BUILT_IN_PATH_STYLES, capPaths, nearestLoop, resolvePathId, styleOf, styleTable } from "./paths.js";
4
+ import { shadowFlags, sunDirectionScene } from "../flat/track-state.js";
5
+ import { TRACK_SHADOW, TRACK_SUNLIT } from "../flat/colours.js";
4
6
  import { createPathRibbons, RIDE_PATH_FADE_KM } from "./path-ribbons.js";
5
7
  /**
6
8
  * The longest a streak may be along its orbit, in Earth radii: 0.025, about 160 km, which is what a low satellite covers in a frame at 10 minutes a second (150 km). On the screen that is a share of the Earth's drawn radius, so a streak
@@ -56,7 +58,7 @@ export function longestStreak(segments, count, earthPx) {
56
58
  }
57
59
  return longest * earthPx;
58
60
  }
59
- export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, hover: { ref: null, fade: 0, enabled: true, color: "#ffffff", opacity: HOVER_PATH_OPACITY }, paths: { requests: [], overrides: {}, selectedOn: true, version: 0, info: [], dropped: 0, unresolved: 0 }, ridden: null, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false, hoverPath: false, hoverOpacity: 0, selectedOpacity: 0, orbitLines: 0, pathsDrawn: 0, pathDraws: 0, estimated: 0 } });
61
+ export const newSatelliteState = () => ({ groups: new Map(), selected: null, marked: new Set(), pinned: [], orbitTint: false, focus: null, modelOver: null, hover: { ref: null, fade: 0, enabled: true, color: "#ffffff", opacity: HOVER_PATH_OPACITY }, paths: { requests: [], overrides: {}, selectedOn: true, light: { on: true, sun: TRACK_SUNLIT, shadow: TRACK_SHADOW }, version: 0, info: [], dropped: 0, unresolved: 0 }, ridden: null, streakMax: DEFAULT_STREAK_MAX, drawn: { placed: 0, segments: 0, tooFast: false, dotScale: 1, longestStreakPx: 0, streakCapPx: 0, weight: 1, fade: 1, earthPx: 0, updateMs: 0, maxUpdateMs: 0, updates: 0, totalMs: 0, selectedRing: false, hoverPath: false, hoverOpacity: 0, selectedOpacity: 0, orbitLines: 0, pathsDrawn: 0, pathDraws: 0, estimated: 0 } });
60
62
  /** The most orbits a group may draw all at once, one line each. */
61
63
  export const MAX_ORBIT_GROUP = 40;
62
64
  const ORBIT_POINTS = 120;
@@ -410,7 +412,8 @@ export function createSatelliteLayer(three, scene, state, ratio) {
410
412
  wanted.push({ id: norad ?? refKey(ref), ref, name: "selected", style: table["selected"], fade: riding ? RIDE_PATH_FADE_KM / EARTH_KM : 0 });
411
413
  }
412
414
  }
413
- const signature = wanted.map((w) => `${refKey(w.ref)}|${w.name}|${w.style.color}|${w.style.width}|${w.style.opacity}|${w.style.dash ? w.style.dash.join(",") : "-"}|${w.fade}`).join(";");
415
+ const light = pathState.light;
416
+ const signature = `${light.on ? `${light.sun}|${light.shadow}` : "-"};` + wanted.map((w) => `${refKey(w.ref)}|${w.name}|${w.style.color}|${w.style.width}|${w.style.opacity}|${w.style.dash ? w.style.dash.join(",") : "-"}|${w.fade}`).join(";");
414
417
  let dirty = signature !== slotsSignature;
415
418
  const old = new Map(slots.map((slot) => [slot.key, slot]));
416
419
  let empty = 0;
@@ -420,7 +423,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
420
423
  let slot = old.get(key);
421
424
  const set = find(w.ref);
422
425
  if (!slot) {
423
- slot = { key, info: { id: w.id, ref: w.ref, style: w.name }, style: w.style, fade: w.fade, positions: new Float32Array(ORBIT_POINTS * 3), screen: new Float32Array(ORBIT_POINTS * 2), seen: new Uint8Array(ORBIT_POINTS), at: Number.NaN, wall: 0, empty: false };
426
+ slot = { key, info: { id: w.id, ref: w.ref, style: w.name }, style: w.style, fade: w.fade, positions: new Float32Array(ORBIT_POINTS * 3), screen: new Float32Array(ORBIT_POINTS * 2), seen: new Uint8Array(ORBIT_POINTS), at: Number.NaN, wall: 0, dark: new Uint8Array(ORBIT_POINTS), darkFor: "", empty: false };
424
427
  dirty = true;
425
428
  }
426
429
  old.delete(key);
@@ -434,6 +437,15 @@ export function createSatelliteLayer(three, scene, state, ratio) {
434
437
  slot.empty = slot.positions.every((v) => v === 0);
435
438
  dirty = true;
436
439
  }
440
+ // the chosen satellite's own orbit, coloured by where the Earth's shadow lies on it (the Sun is fixed over the one revolution it is)
441
+ const shaded = light.on && w.name === "selected" && !slot.empty;
442
+ const darkFor = shaded ? `${slot.at}|${light.sun}|${light.shadow}` : "";
443
+ if (darkFor !== slot.darkFor) {
444
+ slot.darkFor = darkFor;
445
+ if (shaded)
446
+ shadowFlags(slot.positions, ORBIT_POINTS, sunDirectionScene(slot.at), slot.dark);
447
+ dirty = true;
448
+ }
437
449
  if (slot.empty)
438
450
  empty += 1;
439
451
  next.push(slot);
@@ -441,7 +453,7 @@ export function createSatelliteLayer(three, scene, state, ratio) {
441
453
  slots = next;
442
454
  if (dirty) {
443
455
  slotsSignature = signature;
444
- ribbons.set(slots.filter((slot) => !slot.empty).map((slot) => ({ positions: slot.positions, style: slot.style, fade: slot.fade })));
456
+ ribbons.set(slots.filter((slot) => !slot.empty).map((slot) => ({ positions: slot.positions, style: slot.darkFor ? { ...slot.style, color: light.sun } : slot.style, fade: slot.fade, ...(slot.darkFor ? { dark: slot.dark, darkInk: light.shadow } : {}) })));
445
457
  }
446
458
  const own = wanted.filter((w) => w.name === "selected" && pathState.selectedOn);
447
459
  pathState.info = slots.filter((slot) => !slot.empty).map((slot) => ({ ...slot.info }));
@@ -14,6 +14,8 @@ import type { PlaceView } from "../markers/places.ts";
14
14
  import { type PlaceSpriteData } from "../markers/place-sprites.ts";
15
15
  import type { CountryFrame } from "../country-names/geometry.ts";
16
16
  import type { GeoPoint } from "../types.ts";
17
+ import { type RideUp } from "./north-up.ts";
18
+ import { type GroundTrackState } from "../flat/track-state.ts";
17
19
  import type { PathHit } from "./paths.ts";
18
20
  import { type SatelliteScreen, type SatelliteState } from "./satellite-layer.ts";
19
21
  import { type BodyLabelState } from "../realistic/body-label.ts";
@@ -124,6 +126,25 @@ export interface RideState {
124
126
  modelSize: RideModelSize;
125
127
  /** What a drag does in an outside ride from the satellite: `head` turns the view where the camera is, `orbit` takes the camera round the satellite. */
126
128
  drag: RideDrag;
129
+ /** Which way is up in the view above a satellite: the way it is going (`travel`), or north. */
130
+ up: RideUp;
131
+ }
132
+ /**
133
+ * Where the ridden satellite is over the ground and how it is going, and where north is in the picture, as of the last draw.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import type { RideTrack } from "@johnmorrisdotca/chikyu-earth/space";
138
+ *
139
+ * const say = (track: RideTrack): string => `heading ${track.bearingDeg.toFixed(0)} degrees, north ${track.northDeg === null ? "out of sight" : `${track.northDeg.toFixed(0)} degrees round`}`;
140
+ * console.log(typeof say);
141
+ * ```
142
+ */
143
+ export interface RideTrack extends GroundTrackState {
144
+ /** Where north points in the picture, degrees clockwise from its top (0 north at the top, 90 to the right), or `null` when it points along the line of sight. */
145
+ northDeg: number | null;
146
+ /** The way the satellite goes over the ground in the picture, degrees clockwise from its top: the picture's north angle plus the bearing; or `null` with north. */
147
+ travelDeg: number | null;
127
148
  }
128
149
  /** The camera as the last draw left it, for the next one to start from when the ride changes. */
129
150
  export interface Pose {
@@ -239,6 +260,8 @@ export interface SpaceModel {
239
260
  rideMotion: number;
240
261
  /** The heading of a riding camera in degrees, added up change by change from the controls' wrapped yaw (`rideTurnDegrees`): a drag the whole way round is a turn the whole way round, and a change of zoom swings nothing. */
241
262
  rideTurn: number;
263
+ /** The ridden satellite's ground state and where north is in the picture, as of the last draw, or `null` when no satellite is ridden or followed. */
264
+ rideTrack: RideTrack | null;
242
265
  /** How far the riding camera is from the Earth's centre in Earth radii as of the last draw, or null when none rides: the range of tilt that does something follows it. */
243
266
  rideDistance: number | null;
244
267
  /**
@@ -13,6 +13,8 @@ import { genericSatellite, satelliteKind } from "./generic-satellite.js";
13
13
  import { followSpin } from "./follow.js";
14
14
  import { coverBody, covers } from "../sky/cover.js";
15
15
  import { beginPlaceSprites, createPlaceSprites } from "../markers/place-sprites.js";
16
+ import { localNorth, northUpYaw, screenAngle } from "./north-up.js";
17
+ import { trackStateOfScene } from "../flat/track-state.js";
16
18
  import { ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
17
19
  import { createSatelliteLayer, newSatelliteState } from "./satellite-layer.js";
18
20
  import { paintMinute } from "../paint/buffer.js";
@@ -133,6 +135,7 @@ export const newSpaceModel = () => ({
133
135
  pose: { p: [0, 0, 0], q: [0, 0, 0, 1], fov: FOV, valid: false },
134
136
  rideMotion: 0,
135
137
  rideTurn: 0,
138
+ rideTrack: null,
136
139
  rideDistance: null,
137
140
  satellites: newSatelliteState(),
138
141
  meteors: newMeteorState(),
@@ -698,7 +701,9 @@ export function createSpaceItem(model, deps) {
698
701
  // A facing puts the camera ahead, behind, left, right, down or up; a drag turns and tips from there.
699
702
  distance = Math.max(1e-4, ride.distanceKm / 6371 / Math.max(1e-9, model.view.zoom));
700
703
  const base = ride.face ? faceOffset(ride.face) : { yaw: 0, tilt: 0 };
701
- const up = aboveAxes(followed.place, followed.velocity, base.yaw + model.view.yaw * RAD, base.tilt + Math.max(-80, Math.min(80, model.view.tilt)) * RAD);
704
+ // north up (the view above a satellite only): the picture is turned so north is at the top, less near a pole; a drag turns it from there
705
+ const north = ride.view === "above" && ride.up === "north" ? northUpYaw(followed.place, followed.velocity) : null;
706
+ const up = aboveAxes(followed.place, followed.velocity, base.yaw + (north ? north.yaw * north.weight : 0) + model.view.yaw * RAD, base.tilt + Math.max(-80, Math.min(80, model.view.tilt)) * RAD);
702
707
  target.set(focusPos[0], focusPos[1], focusPos[2]);
703
708
  camera.position.set(target.x + up.offset[0] * distance, target.y + up.offset[1] * distance, target.z + up.offset[2] * distance);
704
709
  camera.up.set(up.up[0], up.up[1], up.up[2]);
@@ -755,6 +760,18 @@ export function createSpaceItem(model, deps) {
755
760
  camera.clearViewOffset();
756
761
  camera.updateProjectionMatrix();
757
762
  camera.updateMatrixWorld();
763
+ // the ridden satellite's heading and where north is in the picture, worked out with the draw that is being made, never on a timer
764
+ {
765
+ const sat = followed ?? ridden;
766
+ if (sat && ride) {
767
+ const state = trackStateOfScene(sat.place, sat.velocity, model.time);
768
+ const north = localNorth(sat.place);
769
+ const northDeg = north ? screenAngle([camera.quaternion.x, camera.quaternion.y, camera.quaternion.z, camera.quaternion.w], north) : null;
770
+ model.rideTrack = { ...state, northDeg, travelDeg: northDeg === null ? null : (northDeg + state.bearingDeg) % 360 };
771
+ }
772
+ else
773
+ model.rideTrack = null;
774
+ }
758
775
  // always lit: the light comes from the camera's side of the Earth (the Sun, Moon and planets stay where they are)
759
776
  if (model.light === "lit")
760
777
  sunEarth.value.set(camera.position.x, camera.position.y, camera.position.z).normalize();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.52.0",
3
+ "version": "0.54.0",
4
4
  "description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on the place you give it, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
5
5
  "keywords": [
6
6
  "earth",
@@ -75,6 +75,8 @@
75
75
  "./src/element.ts",
76
76
  "./dist/passes/element.js",
77
77
  "./src/passes/element.ts",
78
+ "./dist/flat/define.js",
79
+ "./src/flat/define.ts",
78
80
  "./dist/realistic/element.js",
79
81
  "./src/realistic/element.ts",
80
82
  "./dist/realistic/element-base.js",
@@ -164,6 +166,16 @@
164
166
  "import": "./dist/passes/index.js",
165
167
  "default": "./dist/passes/index.js"
166
168
  },
169
+ "./flat": {
170
+ "types": "./dist/flat/index.d.ts",
171
+ "import": "./dist/flat/index.js",
172
+ "default": "./dist/flat/index.js"
173
+ },
174
+ "./flat/define": {
175
+ "types": "./dist/flat/define.d.ts",
176
+ "import": "./dist/flat/define.js",
177
+ "default": "./dist/flat/define.js"
178
+ },
167
179
  "./sheets": {
168
180
  "types": "./dist/sheets/index.d.ts",
169
181
  "import": "./dist/sheets/index.js",