@johnmorrisdotca/wakusei-planets 0.45.0 → 0.46.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.
- package/CHANGELOG.md +11 -0
- package/NOTICE.md +11 -0
- package/README.md +4 -3
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +7 -0
- package/dist/space/element.js +12 -0
- package/dist/surface/detail.d.ts +169 -0
- package/dist/surface/detail.js +292 -0
- package/dist/surface/element.d.ts +90 -0
- package/dist/surface/element.js +482 -0
- package/dist/surface/glsl.d.ts +20 -0
- package/dist/surface/glsl.js +403 -0
- package/dist/surface/height.d.ts +257 -0
- package/dist/surface/height.js +232 -0
- package/dist/surface/index.d.ts +8 -0
- package/dist/surface/index.js +8 -0
- package/dist/surface/land.d.ts +111 -0
- package/dist/surface/land.js +261 -0
- package/dist/surface/load.d.ts +133 -0
- package/dist/surface/load.js +183 -0
- package/dist/surface/rocks.d.ts +45 -0
- package/dist/surface/rocks.js +166 -0
- package/dist/surface/scene.d.ts +64 -0
- package/dist/surface/scene.js +323 -0
- package/dist/surface/site.d.ts +58 -0
- package/dist/surface/site.js +38 -0
- package/dist/surface/sky.d.ts +81 -0
- package/dist/surface/sky.js +60 -0
- package/dist/surface/view.d.ts +129 -0
- package/dist/surface/view.js +139 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +23 -1
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type Vec3 } from "../vec.ts";
|
|
2
|
+
/**
|
|
3
|
+
* A direction in the viewer's own sky: a unit vector east, north and up (`enu`), and the same as an azimuth (degrees clockwise from north) and an altitude (degrees above the horizon).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { moonSky, type SkyDirection } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
8
|
+
*
|
|
9
|
+
* const sun: SkyDirection = moonSky(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54)).sun;
|
|
10
|
+
* console.log(`${sun.azimuth.toFixed(0)} degrees clockwise from north, ${sun.altitude.toFixed(0)} degrees up`);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface SkyDirection {
|
|
14
|
+
enu: Vec3;
|
|
15
|
+
azimuth: number;
|
|
16
|
+
altitude: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* What the sky holds at one place and moment.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { moonSky, type MoonSky } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
24
|
+
*
|
|
25
|
+
* const sky: MoonSky = moonSky(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54));
|
|
26
|
+
* console.log(`the Earth is ${(sky.earthIllumination * 100).toFixed(0)}% lit and ${sky.earthDiameter.toFixed(1)} degrees across`);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export interface MoonSky {
|
|
30
|
+
/** The Sun's centre. */
|
|
31
|
+
sun: SkyDirection;
|
|
32
|
+
/** The Sun's angular diameter in degrees (about 0.53 from the Moon). */
|
|
33
|
+
sunDiameter: number;
|
|
34
|
+
/** The Earth's centre. */
|
|
35
|
+
earth: SkyDirection;
|
|
36
|
+
/** The Earth's angular diameter in degrees (about 1.9). */
|
|
37
|
+
earthDiameter: number;
|
|
38
|
+
/** The share of the Earth's disc that is lit, 0 (new) to 1 (full). It is the opposite of the Moon's phase from the Earth: a full Moon is a new Earth. */
|
|
39
|
+
earthIllumination: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The local frame of a point on the Moon at a moment: its east, north and up as unit vectors in the frame of `apparent`, in which `[0, 0, 1]` is toward the Earth.
|
|
43
|
+
*
|
|
44
|
+
* @param lat - Latitude in degrees, positive north.
|
|
45
|
+
* @param lon - Longitude in degrees, positive east.
|
|
46
|
+
* @param time - Milliseconds since 1970.
|
|
47
|
+
* @returns The axes, and `toLocal`, which turns a vector of that frame into east, north and up.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { localFrame } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
52
|
+
*
|
|
53
|
+
* const frame = localFrame(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54));
|
|
54
|
+
* console.log(frame.toLocal([0, 0, 1]).map((n) => n.toFixed(2)).join(", "));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare function localFrame(lat: number, lon: number, time: number): {
|
|
58
|
+
east: Vec3;
|
|
59
|
+
north: Vec3;
|
|
60
|
+
up: Vec3;
|
|
61
|
+
toLocal(v: Vec3): Vec3;
|
|
62
|
+
light: Vec3;
|
|
63
|
+
distanceKm: number;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* The Sun and the Earth in the sky of a point on the Moon at a moment, from the package's own ephemeris: the Moon's real turn and libration, the Sun's real place.
|
|
67
|
+
*
|
|
68
|
+
* @param lat - Latitude in degrees, positive north.
|
|
69
|
+
* @param lon - Longitude in degrees, positive east.
|
|
70
|
+
* @param time - Milliseconds since 1970.
|
|
71
|
+
* @returns The two directions, their sizes and the Earth's lit share.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { moonSky } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
76
|
+
*
|
|
77
|
+
* const sky = moonSky(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54));
|
|
78
|
+
* console.log(`the Sun is ${sky.sun.altitude.toFixed(0)} degrees up, the Earth ${sky.earth.altitude.toFixed(0)}`);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function moonSky(lat: number, lon: number, time: number): MoonSky;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// The sky as a person standing on the Moon sees it: where the Sun and the Earth are, and how much of the Earth is lit. Pure: no DOM, no clock; the date is an argument.
|
|
2
|
+
import { apparent } from "../ephemeris.js";
|
|
3
|
+
import { surfacePoint } from "../pose.js";
|
|
4
|
+
import { cross, dot, unit, DEG } from "../vec.js";
|
|
5
|
+
const direction = (enu) => ({
|
|
6
|
+
enu,
|
|
7
|
+
azimuth: (Math.atan2(enu[0], enu[1]) * DEG + 360) % 360,
|
|
8
|
+
altitude: Math.asin(Math.max(-1, Math.min(1, enu[2]))) * DEG,
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* The local frame of a point on the Moon at a moment: its east, north and up as unit vectors in the frame of `apparent`, in which `[0, 0, 1]` is toward the Earth.
|
|
12
|
+
*
|
|
13
|
+
* @param lat - Latitude in degrees, positive north.
|
|
14
|
+
* @param lon - Longitude in degrees, positive east.
|
|
15
|
+
* @param time - Milliseconds since 1970.
|
|
16
|
+
* @returns The axes, and `toLocal`, which turns a vector of that frame into east, north and up.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { localFrame } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
21
|
+
*
|
|
22
|
+
* const frame = localFrame(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54));
|
|
23
|
+
* console.log(frame.toLocal([0, 0, 1]).map((n) => n.toFixed(2)).join(", "));
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function localFrame(lat, lon, time) {
|
|
27
|
+
const moon = apparent("moon", time);
|
|
28
|
+
const up = surfacePoint(moon, lon, lat);
|
|
29
|
+
const east = unit(cross(moon.pole, up));
|
|
30
|
+
const north = cross(up, east);
|
|
31
|
+
return { east, north, up, toLocal: (v) => [dot(v, east), dot(v, north), dot(v, up)], light: moon.light, distanceKm: moon.distanceKm };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The Sun and the Earth in the sky of a point on the Moon at a moment, from the package's own ephemeris: the Moon's real turn and libration, the Sun's real place.
|
|
35
|
+
*
|
|
36
|
+
* @param lat - Latitude in degrees, positive north.
|
|
37
|
+
* @param lon - Longitude in degrees, positive east.
|
|
38
|
+
* @param time - Milliseconds since 1970.
|
|
39
|
+
* @returns The two directions, their sizes and the Earth's lit share.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { moonSky } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
44
|
+
*
|
|
45
|
+
* const sky = moonSky(20.1911, 30.7723, Date.UTC(1972, 11, 11, 19, 54));
|
|
46
|
+
* console.log(`the Sun is ${sky.sun.altitude.toFixed(0)} degrees up, the Earth ${sky.earth.altitude.toFixed(0)}`);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function moonSky(lat, lon, time) {
|
|
50
|
+
const frame = localFrame(lat, lon, time);
|
|
51
|
+
const sun = frame.toLocal(unit(frame.light));
|
|
52
|
+
const earth = frame.toLocal([0, 0, 1]);
|
|
53
|
+
return {
|
|
54
|
+
sun: direction(sun),
|
|
55
|
+
sunDiameter: 0.533,
|
|
56
|
+
earth: direction(earth),
|
|
57
|
+
earthDiameter: (2 * Math.asin(6371 / frame.distanceKm)) * DEG,
|
|
58
|
+
earthIllumination: (1 - dot(sun, earth)) / 2,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { Vec3 } from "../vec.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Eye height of a standing person in metres.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { EYE_HEIGHT } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
8
|
+
*
|
|
9
|
+
* console.log(`eyes ${EYE_HEIGHT} m above the ground`);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const EYE_HEIGHT = 1.7;
|
|
13
|
+
/**
|
|
14
|
+
* The widest and the narrowest view, in degrees from the top of the picture to its bottom: zoom is the field of view.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { FOV_LIMITS } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
19
|
+
*
|
|
20
|
+
* console.log(`zoom runs from ${FOV_LIMITS.min} to ${FOV_LIMITS.max} degrees`);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const FOV_LIMITS: {
|
|
24
|
+
readonly min: 8;
|
|
25
|
+
readonly max: 100;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* A person's walking pace, metres a second.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { WALK_SPEED } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
33
|
+
*
|
|
34
|
+
* console.log(`${(WALK_SPEED * 10).toFixed(0)} m in ten seconds`);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare const WALK_SPEED = 1.4;
|
|
38
|
+
/**
|
|
39
|
+
* Where the eyes look: an azimuth (degrees clockwise from north), a pitch (degrees above the horizon) and a field of view (degrees, top to bottom).
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { siteById, type Look } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
44
|
+
*
|
|
45
|
+
* const look: Look = siteById("apollo-17")!.look;
|
|
46
|
+
* console.log(`toward ${look.azimuth} degrees, ${look.pitch} up, ${look.fov} wide`);
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export interface Look {
|
|
50
|
+
azimuth: number;
|
|
51
|
+
pitch: number;
|
|
52
|
+
fov: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A look held within what makes sense: the azimuth round the compass, the pitch short of straight up and down, the field of view within `FOV_LIMITS`.
|
|
56
|
+
*
|
|
57
|
+
* @param look - Any look, however far out of range.
|
|
58
|
+
* @returns A new look: the azimuth from 0 up to but not including 360, the pitch from -85 to 85 and the field of view within `FOV_LIMITS`.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { clampLook } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
63
|
+
*
|
|
64
|
+
* console.log(clampLook({ azimuth: -90, pitch: 120, fov: 200 }));
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function clampLook(look: Look): Look;
|
|
68
|
+
/**
|
|
69
|
+
* The direction a look points, in the scene's frame: x to the east, y up and z to the south (so north is -z and a camera looking north has the east on its right).
|
|
70
|
+
*
|
|
71
|
+
* @param look - The look.
|
|
72
|
+
* @returns A unit vector.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { forward } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
77
|
+
*
|
|
78
|
+
* console.log(forward({ azimuth: 90, pitch: 0, fov: 60 }).map((n) => n.toFixed(2)).join(", "));
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare function forward(look: Look): Vec3;
|
|
82
|
+
/** The camera's right, up and forward axes in the scene's frame for a look: what a flat thing that faces the viewer is drawn along. */
|
|
83
|
+
export declare function cameraAxes(look: Look): {
|
|
84
|
+
right: Vec3;
|
|
85
|
+
up: Vec3;
|
|
86
|
+
forward: Vec3;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* The view and projection together, as a column-major 4 x 4 matrix (a float array of sixteen numbers) for a vertex shader: eyes at `eye` in the scene's frame, looking along `look`.
|
|
90
|
+
*
|
|
91
|
+
* @param eye - Where the eyes are, in the scene's frame (east, up, south), in metres.
|
|
92
|
+
* @param look - Which way they look and how wide.
|
|
93
|
+
* @param aspect - The picture's width over its height.
|
|
94
|
+
* @param near - The nearest distance drawn, in metres.
|
|
95
|
+
* @param far - The farthest distance drawn, in metres.
|
|
96
|
+
* @returns The sixteen numbers of the matrix, column by column.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { viewProjection } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
101
|
+
*
|
|
102
|
+
* const matrix = viewProjection([0, 1.7, 0], { azimuth: 0, pitch: 0, fov: 60 }, 16 / 9);
|
|
103
|
+
* console.log(matrix.length);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function viewProjection(eye: Vec3, look: Look, aspect: number, near?: number, far?: number): Float32Array;
|
|
107
|
+
/**
|
|
108
|
+
* A position moved over the ground by a walk: `ahead` metres along the look's heading (negative backs up) and `aside` to its right, in the site's plane (east, north).
|
|
109
|
+
*
|
|
110
|
+
* @param position - Where the walker is, in metres east and north of the site.
|
|
111
|
+
* @param azimuth - The heading, in degrees clockwise from north.
|
|
112
|
+
* @param ahead - Metres along the heading; negative backs up.
|
|
113
|
+
* @param aside - Metres to the right of the heading; negative goes left.
|
|
114
|
+
* @returns The new position, in metres east and north of the site.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* import { stepOver } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
119
|
+
*
|
|
120
|
+
* console.log(stepOver({ east: 0, north: 0 }, 0, 10, 0));
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function stepOver(position: {
|
|
124
|
+
east: number;
|
|
125
|
+
north: number;
|
|
126
|
+
}, azimuth: number, ahead: number, aside: number): {
|
|
127
|
+
east: number;
|
|
128
|
+
north: number;
|
|
129
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Eye height of a standing person in metres.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { EYE_HEIGHT } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
7
|
+
*
|
|
8
|
+
* console.log(`eyes ${EYE_HEIGHT} m above the ground`);
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export const EYE_HEIGHT = 1.7;
|
|
12
|
+
/**
|
|
13
|
+
* The widest and the narrowest view, in degrees from the top of the picture to its bottom: zoom is the field of view.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { FOV_LIMITS } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
18
|
+
*
|
|
19
|
+
* console.log(`zoom runs from ${FOV_LIMITS.min} to ${FOV_LIMITS.max} degrees`);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const FOV_LIMITS = { min: 8, max: 100 };
|
|
23
|
+
/**
|
|
24
|
+
* A person's walking pace, metres a second.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { WALK_SPEED } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
29
|
+
*
|
|
30
|
+
* console.log(`${(WALK_SPEED * 10).toFixed(0)} m in ten seconds`);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const WALK_SPEED = 1.4;
|
|
34
|
+
/**
|
|
35
|
+
* A look held within what makes sense: the azimuth round the compass, the pitch short of straight up and down, the field of view within `FOV_LIMITS`.
|
|
36
|
+
*
|
|
37
|
+
* @param look - Any look, however far out of range.
|
|
38
|
+
* @returns A new look: the azimuth from 0 up to but not including 360, the pitch from -85 to 85 and the field of view within `FOV_LIMITS`.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { clampLook } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
43
|
+
*
|
|
44
|
+
* console.log(clampLook({ azimuth: -90, pitch: 120, fov: 200 }));
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export function clampLook(look) {
|
|
48
|
+
return {
|
|
49
|
+
azimuth: ((look.azimuth % 360) + 360) % 360,
|
|
50
|
+
pitch: Math.max(-85, Math.min(85, look.pitch)),
|
|
51
|
+
fov: Math.max(FOV_LIMITS.min, Math.min(FOV_LIMITS.max, look.fov)),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The direction a look points, in the scene's frame: x to the east, y up and z to the south (so north is -z and a camera looking north has the east on its right).
|
|
56
|
+
*
|
|
57
|
+
* @param look - The look.
|
|
58
|
+
* @returns A unit vector.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { forward } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
63
|
+
*
|
|
64
|
+
* console.log(forward({ azimuth: 90, pitch: 0, fov: 60 }).map((n) => n.toFixed(2)).join(", "));
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export function forward(look) {
|
|
68
|
+
const az = (look.azimuth * Math.PI) / 180;
|
|
69
|
+
const p = (look.pitch * Math.PI) / 180;
|
|
70
|
+
return [Math.sin(az) * Math.cos(p), Math.sin(p), -Math.cos(az) * Math.cos(p)];
|
|
71
|
+
}
|
|
72
|
+
/** The camera's right, up and forward axes in the scene's frame for a look: what a flat thing that faces the viewer is drawn along. */
|
|
73
|
+
export function cameraAxes(look) {
|
|
74
|
+
const f = forward(look);
|
|
75
|
+
// right = forward x (0, 1, 0), up = right x forward
|
|
76
|
+
let rx = -f[2];
|
|
77
|
+
let rz = f[0];
|
|
78
|
+
const rl = Math.hypot(rx, rz) || 1;
|
|
79
|
+
rx /= rl;
|
|
80
|
+
rz /= rl;
|
|
81
|
+
return { right: [rx, 0, rz], up: [-rz * f[1], rz * f[0] - rx * f[2], rx * f[1]], forward: f };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The view and projection together, as a column-major 4 x 4 matrix (a float array of sixteen numbers) for a vertex shader: eyes at `eye` in the scene's frame, looking along `look`.
|
|
85
|
+
*
|
|
86
|
+
* @param eye - Where the eyes are, in the scene's frame (east, up, south), in metres.
|
|
87
|
+
* @param look - Which way they look and how wide.
|
|
88
|
+
* @param aspect - The picture's width over its height.
|
|
89
|
+
* @param near - The nearest distance drawn, in metres.
|
|
90
|
+
* @param far - The farthest distance drawn, in metres.
|
|
91
|
+
* @returns The sixteen numbers of the matrix, column by column.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { viewProjection } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
96
|
+
*
|
|
97
|
+
* const matrix = viewProjection([0, 1.7, 0], { azimuth: 0, pitch: 0, fov: 60 }, 16 / 9);
|
|
98
|
+
* console.log(matrix.length);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function viewProjection(eye, look, aspect, near = 0.3, far = 600_000) {
|
|
102
|
+
const { right: r, up: u, forward: f } = cameraAxes(look);
|
|
103
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
104
|
+
const view = [r[0], u[0], -f[0], 0, r[1], u[1], -f[1], 0, r[2], u[2], -f[2], 0, -dot(r, eye), -dot(u, eye), dot(f, eye), 1];
|
|
105
|
+
const t = 1 / Math.tan((look.fov * Math.PI) / 360);
|
|
106
|
+
const proj = [t / aspect, 0, 0, 0, 0, t, 0, 0, 0, 0, (far + near) / (near - far), -1, 0, 0, (2 * far * near) / (near - far), 0];
|
|
107
|
+
const out = new Float32Array(16);
|
|
108
|
+
for (let c = 0; c < 4; c += 1) {
|
|
109
|
+
for (let row = 0; row < 4; row += 1) {
|
|
110
|
+
let sum = 0;
|
|
111
|
+
for (let k = 0; k < 4; k += 1)
|
|
112
|
+
sum += proj[k * 4 + row] * view[c * 4 + k];
|
|
113
|
+
out[c * 4 + row] = sum;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A position moved over the ground by a walk: `ahead` metres along the look's heading (negative backs up) and `aside` to its right, in the site's plane (east, north).
|
|
120
|
+
*
|
|
121
|
+
* @param position - Where the walker is, in metres east and north of the site.
|
|
122
|
+
* @param azimuth - The heading, in degrees clockwise from north.
|
|
123
|
+
* @param ahead - Metres along the heading; negative backs up.
|
|
124
|
+
* @param aside - Metres to the right of the heading; negative goes left.
|
|
125
|
+
* @returns The new position, in metres east and north of the site.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* import { stepOver } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
130
|
+
*
|
|
131
|
+
* console.log(stepOver({ east: 0, north: 0 }, 0, 10, 0));
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export function stepOver(position, azimuth, ahead, aside) {
|
|
135
|
+
const az = (azimuth * Math.PI) / 180;
|
|
136
|
+
const sin = Math.sin(az);
|
|
137
|
+
const cos = Math.cos(az);
|
|
138
|
+
return { east: position.east + ahead * sin + aside * cos, north: position.north + ahead * cos - aside * sin };
|
|
139
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.46.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.46.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/wakusei-planets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"planets",
|
|
@@ -92,6 +92,8 @@
|
|
|
92
92
|
"./dist/lineup/element.js",
|
|
93
93
|
"./dist/space/element.js",
|
|
94
94
|
"./dist/plan/element.js",
|
|
95
|
+
"./dist/surface/element.js",
|
|
96
|
+
"./dist/surface/land.js",
|
|
95
97
|
"./dist/earth-places.js",
|
|
96
98
|
"./dist/bodies/*.js",
|
|
97
99
|
"./dist/tables/*.js",
|
|
@@ -101,6 +103,8 @@
|
|
|
101
103
|
"./src/lineup/element.ts",
|
|
102
104
|
"./src/space/element.ts",
|
|
103
105
|
"./src/plan/element.ts",
|
|
106
|
+
"./src/surface/element.ts",
|
|
107
|
+
"./src/surface/land.ts",
|
|
104
108
|
"./src/earth-places.ts",
|
|
105
109
|
"./src/bodies/*.ts",
|
|
106
110
|
"./src/tables/*.ts",
|
|
@@ -150,6 +154,21 @@
|
|
|
150
154
|
"import": "./dist/plan/element.js",
|
|
151
155
|
"default": "./dist/plan/element.js"
|
|
152
156
|
},
|
|
157
|
+
"./surface": {
|
|
158
|
+
"types": "./dist/surface/index.d.ts",
|
|
159
|
+
"import": "./dist/surface/index.js",
|
|
160
|
+
"default": "./dist/surface/index.js"
|
|
161
|
+
},
|
|
162
|
+
"./surface/element": {
|
|
163
|
+
"types": "./dist/surface/element.d.ts",
|
|
164
|
+
"import": "./dist/surface/element.js",
|
|
165
|
+
"default": "./dist/surface/element.js"
|
|
166
|
+
},
|
|
167
|
+
"./surface/land": {
|
|
168
|
+
"types": "./dist/surface/land.d.ts",
|
|
169
|
+
"import": "./dist/surface/land.js",
|
|
170
|
+
"default": "./dist/surface/land.js"
|
|
171
|
+
},
|
|
153
172
|
"./time": {
|
|
154
173
|
"types": "./dist/time.d.ts",
|
|
155
174
|
"import": "./dist/time.js",
|
|
@@ -586,6 +605,9 @@
|
|
|
586
605
|
"tiles:moon": ".cache/venv/bin/python -I scripts/make-body-tiles.py sharp --bodies moon",
|
|
587
606
|
"tiles:mars": ".cache/venv/bin/python -I scripts/make-body-tiles.py sharp --bodies mars",
|
|
588
607
|
"test:tiles": ".cache/venv/bin/python -I scripts/make-body-tiles.py selftest",
|
|
608
|
+
"terrain": ".cache/venv/bin/python -I scripts/make-moon-terrain.py build",
|
|
609
|
+
"terrain:fetch": ".cache/venv/bin/python -I scripts/make-moon-terrain.py fetch",
|
|
610
|
+
"test:terrain": ".cache/venv/bin/python -I scripts/make-moon-terrain.py selftest",
|
|
589
611
|
"orbiters:refresh": "python3 -I scripts/make-orbiter-data.py --brief --cache \"$HOME/.cache/wakusei-planets/horizons-orbiters\"",
|
|
590
612
|
"family:readme": "node scripts/family-readme.mjs",
|
|
591
613
|
"readme:images": "node scripts/readme-images.mjs",
|