@johnmorrisdotca/wakusei-planets 0.46.0 → 0.48.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 +9 -0
- package/NOTICE.md +1 -0
- package/README.md +4 -3
- package/dist/element.d.ts +38 -0
- package/dist/element.js +49 -5
- package/dist/scene/body.d.ts +1 -1
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +47 -1
- package/dist/space/element.js +101 -1
- package/dist/space/face.d.ts +132 -0
- package/dist/space/face.js +156 -0
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/dist/surface/detail.d.ts +17 -0
- package/dist/surface/detail.js +25 -1
- package/dist/surface/element.d.ts +13 -0
- package/dist/surface/element.js +218 -15
- package/dist/surface/glsl.d.ts +11 -5
- package/dist/surface/glsl.js +55 -1
- package/dist/surface/index.d.ts +3 -1
- package/dist/surface/index.js +3 -1
- package/dist/surface/objects-apollo-17.d.ts +4 -0
- package/dist/surface/objects-apollo-17.js +19 -0
- package/dist/surface/objects.d.ts +127 -0
- package/dist/surface/objects.js +179 -0
- package/dist/surface/scene.d.ts +8 -0
- package/dist/surface/scene.js +169 -4
- package/dist/surface/shapes.d.ts +62 -0
- package/dist/surface/shapes.js +247 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Which face of the centred body the space view looks at, and the turn that brings a face to the middle: the camera's direction in the body's own fixed frame. Pure.
|
|
2
|
+
import { orientation } from "../scene/orient.js";
|
|
3
|
+
import { cross, dot, RAD, unit } from "../vec.js";
|
|
4
|
+
import { groundDirection } from "./aim.js";
|
|
5
|
+
import { besideMoon } from "./beside.js";
|
|
6
|
+
const wrap = (deg) => ((((deg + 180) % 360) + 360) % 360) - 180;
|
|
7
|
+
/**
|
|
8
|
+
* The longitude and latitude, on the body in the middle of the space view, of the point under the camera: the camera looks along the line from that point through the body's centre. It is the camera's
|
|
9
|
+
* direction (the Earth's ground direction of `center` less the yaw and tilt, as the stars saw it at `anchor`) put into the body's own frame (its pole and prime meridian at `time`, which carry its spin
|
|
10
|
+
* and, for the Moon, its libration). A body that turns with the clock moves under a camera held in the stars, so the same view names another face a minute later.
|
|
11
|
+
*
|
|
12
|
+
* @param body - The body in the middle of the view.
|
|
13
|
+
* @param view - The view's yaw and tilt, degrees.
|
|
14
|
+
* @param centre - The view's `center` (longitude and latitude, degrees).
|
|
15
|
+
* @param anchor - The moment the camera was last pointed, in milliseconds since the Unix epoch.
|
|
16
|
+
* @param time - The moment shown.
|
|
17
|
+
* @returns The point under the camera, longitude from -180 to 180 and latitude from -90 to 90.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { subCameraPoint } from "@johnmorrisdotca/wakusei-planets/space";
|
|
22
|
+
*
|
|
23
|
+
* const at = subCameraPoint("moon", { yaw: 0, tilt: 0 }, { lon: 0, lat: 0 }, Date.UTC(2026, 10, 2), Date.UTC(2026, 10, 2));
|
|
24
|
+
* console.log(at.lon.toFixed(0), at.lat.toFixed(0));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function subCameraPoint(body, view, centre, anchor, time) {
|
|
28
|
+
const d = groundDirection(centre.lon - view.yaw, Math.max(-90, Math.min(90, centre.lat - view.tilt)), anchor);
|
|
29
|
+
const { pole, meridian } = orientation(body, time);
|
|
30
|
+
const east = cross(pole, meridian);
|
|
31
|
+
return { lon: Math.atan2(dot(d, east), dot(d, meridian)) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, dot(d, pole)))) / RAD };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The yaw and tilt that put a point of the body under the camera: the other way round from {@link subCameraPoint}, for the same centre, anchor and moment. The yaw is the shorter way round from `from`.
|
|
35
|
+
*
|
|
36
|
+
* @param body - The body in the middle of the view.
|
|
37
|
+
* @param face - The point to bring to the middle.
|
|
38
|
+
* @param centre - The view's `center`.
|
|
39
|
+
* @param anchor - The moment the camera was last pointed.
|
|
40
|
+
* @param time - The moment shown.
|
|
41
|
+
* @param from - The yaw the view has now, so that the turn is the shorter way (0 when left out).
|
|
42
|
+
* @returns The yaw and tilt to give the view.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { faceView, subCameraPoint } from "@johnmorrisdotca/wakusei-planets/space";
|
|
47
|
+
*
|
|
48
|
+
* const ms = Date.UTC(2026, 10, 2);
|
|
49
|
+
* const turn = faceView("mars", { lon: 100, lat: 20 }, { lon: 0, lat: 0 }, ms, ms);
|
|
50
|
+
* console.log(subCameraPoint("mars", turn, { lon: 0, lat: 0 }, ms, ms));
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function faceView(body, face, centre, anchor, time, from = 0) {
|
|
54
|
+
const { pole, meridian } = orientation(body, time);
|
|
55
|
+
const east = cross(pole, meridian);
|
|
56
|
+
const c = Math.cos(face.lat * RAD);
|
|
57
|
+
const d = [0, 1, 2].map((i) => c * Math.cos(face.lon * RAD) * meridian[i] + c * Math.sin(face.lon * RAD) * east[i] + Math.sin(face.lat * RAD) * pole[i]);
|
|
58
|
+
const earth = orientation("earth", anchor);
|
|
59
|
+
const lat = Math.asin(Math.max(-1, Math.min(1, dot(d, earth.pole)))) / RAD;
|
|
60
|
+
const lon = Math.atan2(dot(d, cross(earth.pole, earth.meridian)), dot(d, earth.meridian)) / RAD;
|
|
61
|
+
const yaw = centre.lon - lon;
|
|
62
|
+
return { yaw: from + wrap(yaw - from), tilt: centre.lat - lat };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The longitude and latitude on a body of a direction from its centre in the scene's axes: what a camera standing along that direction has under it. The body's pole and prime meridian are those at `time`.
|
|
66
|
+
*
|
|
67
|
+
* @param body - The body.
|
|
68
|
+
* @param direction - A direction from the body's centre (any length).
|
|
69
|
+
* @param time - The moment, in milliseconds since the Unix epoch.
|
|
70
|
+
* @returns The point on the body under that direction.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { facingPoint } from "@johnmorrisdotca/wakusei-planets/space";
|
|
75
|
+
*
|
|
76
|
+
* const ms = Date.UTC(2026, 10, 2);
|
|
77
|
+
* console.log(facingPoint("moon", [0, 1, 0], ms));
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export function facingPoint(body, direction, time) {
|
|
81
|
+
const d = unit(direction);
|
|
82
|
+
const { pole, meridian } = orientation(body, time);
|
|
83
|
+
const east = cross(pole, meridian);
|
|
84
|
+
return { lon: Math.atan2(dot(d, east), dot(d, meridian)) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, dot(d, pole)))) / RAD };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The direction from a body's centre, in the scene's axes, of a point on its surface at a moment: the unit vector the other way from {@link facingPoint}.
|
|
88
|
+
*
|
|
89
|
+
* @param body - The body.
|
|
90
|
+
* @param face - The point on its surface.
|
|
91
|
+
* @param time - The moment, in milliseconds since the Unix epoch.
|
|
92
|
+
* @returns The unit direction.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { surfaceDirection } from "@johnmorrisdotca/wakusei-planets/space";
|
|
97
|
+
*
|
|
98
|
+
* console.log(surfaceDirection("moon", { lon: 0, lat: 0 }, Date.UTC(2026, 10, 2)).map((n) => n.toFixed(2)));
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function surfaceDirection(body, face, time) {
|
|
102
|
+
const { pole, meridian } = orientation(body, time);
|
|
103
|
+
const east = cross(pole, meridian);
|
|
104
|
+
const c = Math.cos(face.lat * RAD);
|
|
105
|
+
return [0, 1, 2].map((i) => c * Math.cos(face.lon * RAD) * meridian[i] + c * Math.sin(face.lon * RAD) * east[i] + Math.sin(face.lat * RAD) * pole[i]);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The yaw and tilt of a camera beside a moon (the view `ride(moon, { view: "beside" })` gives) that put it on the side of the moon the point is on: the camera stands along the direction from the moon's
|
|
109
|
+
* centre through the point. The camera there is placed by `besideMoon` (beyond the moon, off the line to its planet), so not every point can be reached: the pair returned brings the camera as near as
|
|
110
|
+
* the view goes, and `error` says by how many degrees it is still off.
|
|
111
|
+
*
|
|
112
|
+
* @param input - What `besideMoon` is given, without the yaw and tilt.
|
|
113
|
+
* @param body - The moon.
|
|
114
|
+
* @param face - The point to bring under the camera.
|
|
115
|
+
* @param time - The moment shown.
|
|
116
|
+
* @returns The yaw and tilt, and the angle in degrees between the camera's direction and the wanted one.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { besideFace } from "@johnmorrisdotca/wakusei-planets/space";
|
|
121
|
+
*
|
|
122
|
+
* const input = { moon: [60, 0, 0], moonRadius: 0.273, host: [0, 0, 0], hostRadius: 1, sun: [-23000, 0, 0], aspect: 1.6, zoom: 1 } as const;
|
|
123
|
+
* console.log(besideFace(input, "moon", { lon: 180, lat: 0 }, Date.UTC(2026, 10, 2)).error < 90);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export function besideFace(input, body, face, time) {
|
|
127
|
+
const wanted = unit(surfaceDirection(body, face, time));
|
|
128
|
+
const at = (yaw, tilt) => {
|
|
129
|
+
const camera = besideMoon({ ...input, yaw, tilt });
|
|
130
|
+
const away = unit([camera.position[0] - input.moon[0], camera.position[1] - input.moon[1], camera.position[2] - input.moon[2]]);
|
|
131
|
+
return Math.acos(Math.max(-1, Math.min(1, dot(away, wanted)))) / RAD;
|
|
132
|
+
};
|
|
133
|
+
let best = { yaw: 0, tilt: 0, error: Infinity };
|
|
134
|
+
for (let yaw = -180; yaw < 180; yaw += 15) {
|
|
135
|
+
for (let tilt = -60; tilt <= 80; tilt += 10) {
|
|
136
|
+
const error = at(yaw, tilt);
|
|
137
|
+
if (error < best.error)
|
|
138
|
+
best = { yaw, tilt, error };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (let step = 8; step > 0.01; step *= 0.6) {
|
|
142
|
+
for (let round = 0; round < 6; round += 1) {
|
|
143
|
+
let moved = false;
|
|
144
|
+
for (const [dy, dt] of [[step, 0], [-step, 0], [0, step], [0, -step]]) {
|
|
145
|
+
const error = at(best.yaw + dy, best.tilt + dt);
|
|
146
|
+
if (error < best.error) {
|
|
147
|
+
best = { yaw: best.yaw + dy, tilt: best.tilt + dt, error };
|
|
148
|
+
moved = true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!moved)
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { yaw: wrap(best.yaw), tilt: best.tilt, error: best.error };
|
|
156
|
+
}
|
package/dist/space/index.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, type CoverArrow,
|
|
|
11
11
|
export { TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose, type ArrivalCompanion, type TravelBody, type TravelInput, type TravelKind, type TravelPlan, type TravelSample, type TravelSight, type TravelView } from "./travel.ts";
|
|
12
12
|
export { regionOrbits, regionView, SUN_REGIONS, type SunRegion } from "./regions.ts";
|
|
13
13
|
export { SIGHT_STEP_PX, sightChanged, sightOf, type Sight, type SightEdge, type SightInput } from "./sight.ts";
|
|
14
|
+
export { besideFace, facingPoint, faceView, subCameraPoint, surfaceDirection, type Face, type FaceView } from "./face.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -12,3 +12,4 @@ export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy } from "./covered
|
|
|
12
12
|
export { TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose } from "./travel.js";
|
|
13
13
|
export { regionOrbits, regionView, SUN_REGIONS } from "./regions.js";
|
|
14
14
|
export { SIGHT_STEP_PX, sightChanged, sightOf } from "./sight.js";
|
|
15
|
+
export { besideFace, facingPoint, faceView, subCameraPoint, surfaceDirection } from "./face.js";
|
package/dist/surface/detail.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
import { type SiteObject } from "./objects.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Say which objects the made craters and rocks keep away from (the ones `objectsOf` gives for the site), or none. The shader holds the same list.
|
|
4
|
+
*
|
|
5
|
+
* @param objects - The objects.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { madeGround, objectsOf, setKeepOut } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
10
|
+
*
|
|
11
|
+
* const [lander] = objectsOf("apollo-17");
|
|
12
|
+
* setKeepOut(objectsOf("apollo-17"));
|
|
13
|
+
* console.log(madeGround(lander!.east, lander!.north, 0.35).h);
|
|
14
|
+
* setKeepOut([]);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function setKeepOut(objects: readonly SiteObject[]): void;
|
|
1
18
|
/** The smallest crater's nominal diameter in metres: each octave doubles it, up to `OCTAVES` octaves (0.5, 1, 2, 4, 8, 16). A crater in an octave is between 1 and 2 times its nominal diameter. */
|
|
2
19
|
export declare const D0 = 0.5;
|
|
3
20
|
export declare const OCTAVES = 6;
|
package/dist/surface/detail.js
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
// age), laid on a seeded grid of cells, so the same place is always the same. It is MADE, not measured, and the page says so. The shader (glsl.ts) holds the same formulas; this is the same
|
|
3
3
|
// maths in JS, for the feet (the eyes follow the made ground too), for the rocks (placed on the ground and denser by fresh rims) and for the tests that hold the two together.
|
|
4
4
|
// Every random number is an integer hash (PCG, 32 bit) cut to 24 bits, so the two agree exactly.
|
|
5
|
+
import { keepAway } from "./objects.js";
|
|
6
|
+
/** The objects the made ground keeps away from: set for the site being stood on (`setKeepOut`), none until then. */
|
|
7
|
+
let keepObjects = [];
|
|
8
|
+
/**
|
|
9
|
+
* Say which objects the made craters and rocks keep away from (the ones `objectsOf` gives for the site), or none. The shader holds the same list.
|
|
10
|
+
*
|
|
11
|
+
* @param objects - The objects.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { madeGround, objectsOf, setKeepOut } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
16
|
+
*
|
|
17
|
+
* const [lander] = objectsOf("apollo-17");
|
|
18
|
+
* setKeepOut(objectsOf("apollo-17"));
|
|
19
|
+
* console.log(madeGround(lander!.east, lander!.north, 0.35).h);
|
|
20
|
+
* setKeepOut([]);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export function setKeepOut(objects) {
|
|
24
|
+
keepObjects = objects;
|
|
25
|
+
}
|
|
5
26
|
/** The smallest crater's nominal diameter in metres: each octave doubles it, up to `OCTAVES` octaves (0.5, 1, 2, 4, 8, 16). A crater in an octave is between 1 and 2 times its nominal diameter. */
|
|
6
27
|
export const D0 = 0.5;
|
|
7
28
|
export const OCTAVES = 6;
|
|
@@ -156,7 +177,8 @@ export function madeGround(x, y, fromDiameter) {
|
|
|
156
177
|
}
|
|
157
178
|
}
|
|
158
179
|
}
|
|
159
|
-
|
|
180
|
+
const keep = keepAway(x, y, keepObjects);
|
|
181
|
+
return { h: h * keep, gx: gx * keep, gy: gy * keep };
|
|
160
182
|
}
|
|
161
183
|
/** The rocks of a class are `ROCK_MIN * 2 ** class` metres: 0.05, 0.1, 0.2, 0.4, 0.8, 1.6; a rock of a class is between 1 and 1.4 times that. */
|
|
162
184
|
export const ROCK_MIN = 0.05;
|
|
@@ -242,6 +264,8 @@ export function rocksAround(cx, cy, radius, pixel) {
|
|
|
242
264
|
const boost = rimBoost(x, y);
|
|
243
265
|
if (unit24(pcg2d(c, d)[0]) > 0.3 * boost)
|
|
244
266
|
continue;
|
|
267
|
+
if (keepAway(x, y, keepObjects) < 0.5)
|
|
268
|
+
continue;
|
|
245
269
|
const [e, f] = pcg2d(c ^ 0x9e3779b9, d + 17);
|
|
246
270
|
out.push({ x, y, size, shape: e % 3, turn: unit24(f) * Math.PI * 2, tone: 0.75 + 0.5 * unit24(e >>> 3), flat: 0.45 + 0.4 * unit24(f >>> 5) });
|
|
247
271
|
}
|
|
@@ -4,6 +4,7 @@ import { setThreeLoader } from "../scene/shared.ts";
|
|
|
4
4
|
import { type HeightLevel, type TerrainManifest } from "./height.ts";
|
|
5
5
|
import { type TerrainProgress } from "./load.ts";
|
|
6
6
|
import { type SurfaceScene } from "./scene.ts";
|
|
7
|
+
import { type SiteObject } from "./objects.ts";
|
|
7
8
|
import { type MoonSky } from "./sky.ts";
|
|
8
9
|
import { type Look } from "./view.ts";
|
|
9
10
|
export { setThreeLoader };
|
|
@@ -74,6 +75,8 @@ export declare class WakuseiSurface extends HTMLElement {
|
|
|
74
75
|
renderer: SharedRenderer<ThreeParts>["stats"] | undefined;
|
|
75
76
|
mesh: SurfaceScene["mesh"] | undefined;
|
|
76
77
|
quality: string;
|
|
78
|
+
scale: number;
|
|
79
|
+
scaled: number;
|
|
77
80
|
drawMs: number | undefined;
|
|
78
81
|
rocks: number;
|
|
79
82
|
};
|
|
@@ -87,4 +90,14 @@ export declare class WakuseiSurface extends HTMLElement {
|
|
|
87
90
|
* @param aside - Metres to the right.
|
|
88
91
|
*/
|
|
89
92
|
walk(ahead: number, aside?: number): void;
|
|
93
|
+
/** The things at the site, at their published places (none where the site has none or `objects="off"`). */
|
|
94
|
+
get objects(): readonly SiteObject[];
|
|
95
|
+
/**
|
|
96
|
+
* Choose a thing at the site: the eyes go to a few metres from it, looking at it, its button is pressed and a line says what it is and that it was placed by this package. `wakusei-surface-object` is sent
|
|
97
|
+
* with its id. Choosing the same one again, or `undefined`, puts the line away.
|
|
98
|
+
*
|
|
99
|
+
* @param id - A thing's id (`lm`, `rover`, `flag`, `alsep`, `sep`), or `undefined` for none.
|
|
100
|
+
* @returns Whether there is such a thing here.
|
|
101
|
+
*/
|
|
102
|
+
choose(id: string | undefined): boolean;
|
|
90
103
|
}
|
package/dist/surface/element.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { createGate, frameCap } from "../gate.js";
|
|
2
2
|
import { setThreeLoader, takeRenderer } from "../scene/shared.js";
|
|
3
3
|
import { TILES_BASE } from "../scene/textures.js";
|
|
4
|
-
import { madeGround, standingPlace } from "./detail.js";
|
|
4
|
+
import { madeGround, setKeepOut, standingPlace } from "./detail.js";
|
|
5
5
|
import { drop, groundAt } from "./height.js";
|
|
6
6
|
import { loadTerrain } from "./load.js";
|
|
7
7
|
import { createSurfaceItem } from "./scene.js";
|
|
8
|
+
import { objectsOf, traverseOf } from "./objects.js";
|
|
8
9
|
import { moonSky } from "./sky.js";
|
|
9
10
|
import { siteById } from "./site.js";
|
|
10
|
-
import { clampLook, EYE_HEIGHT, stepOver, WALK_SPEED } from "./view.js";
|
|
11
|
+
import { clampLook, EYE_HEIGHT, stepOver, viewProjection, WALK_SPEED } from "./view.js";
|
|
11
12
|
export { setThreeLoader };
|
|
12
13
|
const TEMPLATE = `<style>
|
|
13
14
|
:host { display: block; width: var(--wakusei-size, 960px); max-width: 100%; aspect-ratio: var(--wakusei-ratio, 16 / 9); position: relative; overflow: hidden; background: #000; contain: layout style; touch-action: none; user-select: none; cursor: grab; }
|
|
@@ -17,7 +18,17 @@ const TEMPLATE = `<style>
|
|
|
17
18
|
#note { position: absolute; left: 8px; right: 8px; bottom: 6px; margin: 0; font: 400 11px/1.35 system-ui, sans-serif; color: #c8ccd4; text-shadow: 0 1px 2px #000; pointer-events: none; }
|
|
18
19
|
#status { position: absolute; inset: 0; display: grid; place-items: center; font: 500 13px system-ui, sans-serif; color: #c8ccd4; pointer-events: none; }
|
|
19
20
|
#status[hidden] { display: none; }
|
|
20
|
-
|
|
21
|
+
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
|
|
22
|
+
.label { position: absolute; left: 0; top: 0; margin: 0; padding: 3px 8px; border: 1px solid rgba(255, 255, 255, 0.45); border-radius: 12px; background: rgba(0, 0, 0, 0.55); color: #e8ecf2; font: 500 11px/1.3 system-ui, sans-serif; white-space: nowrap; pointer-events: auto; cursor: pointer; will-change: transform; touch-action: manipulation; }
|
|
23
|
+
.label:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
|
|
24
|
+
.label[hidden] { display: none; }
|
|
25
|
+
.label[aria-pressed="true"] { background: rgba(255, 255, 255, 0.85); color: #10141c; }
|
|
26
|
+
#about { position: absolute; left: 8px; right: 8px; top: 8px; margin: 0; padding: 6px 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.62); color: #e8ecf2; font: 400 12px/1.4 system-ui, sans-serif; pointer-events: none; max-width: 32em; }
|
|
27
|
+
#about[hidden] { display: none; }
|
|
28
|
+
#stick { position: absolute; left: 18px; bottom: 44px; width: 104px; height: 104px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.4); background: rgba(255, 255, 255, 0.08); touch-action: none; }
|
|
29
|
+
#stick[hidden] { display: none; }
|
|
30
|
+
#knob { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(255, 255, 255, 0.55); pointer-events: none; }
|
|
31
|
+
</style><div id="stage"></div><p id="note"></p><p id="status" role="status"></p><div id="labels"></div><p id="about" role="status" hidden></p><div id="stick" part="stick" role="group" aria-label="Walk" hidden><div id="knob"></div></div>`;
|
|
21
32
|
const num = (value, fallback) => {
|
|
22
33
|
const n = value === null || value.trim() === "" ? NaN : Number(value);
|
|
23
34
|
return Number.isFinite(n) ? n : fallback;
|
|
@@ -42,7 +53,7 @@ const num = (value, fallback) => {
|
|
|
42
53
|
* ```
|
|
43
54
|
*/
|
|
44
55
|
export class WakuseiSurface extends HTMLElement {
|
|
45
|
-
static observedAttributes = ["quality", "shadows", "detail", "exposure", "site", "time", "heading", "pitch", "fov", "tiles", "lang", "body", "standby"];
|
|
56
|
+
static observedAttributes = ["quality", "shadows", "detail", "exposure", "site", "time", "heading", "pitch", "fov", "tiles", "lang", "body", "standby", "scale", "stick", "objects"];
|
|
46
57
|
#root;
|
|
47
58
|
#stage;
|
|
48
59
|
#noteEl;
|
|
@@ -76,6 +87,19 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
76
87
|
#restQuality = "full";
|
|
77
88
|
#drawMs;
|
|
78
89
|
#measured = 0;
|
|
90
|
+
/** The share the ground is drawn at while the view moves (1, or a half where the machine is slow), and the moving draws timed to decide it. */
|
|
91
|
+
#moveScale = 1;
|
|
92
|
+
#movingTimes = [];
|
|
93
|
+
#movingPending = false;
|
|
94
|
+
#drawScale = 1;
|
|
95
|
+
#scaled = 0;
|
|
96
|
+
/** The walking stick's push, east and north, each -1 to 1, and the finger that holds it. */
|
|
97
|
+
#push = { x: 0, y: 0 };
|
|
98
|
+
/** The things at the site and the buttons that name them, and the one chosen. */
|
|
99
|
+
#objects = [];
|
|
100
|
+
#labelEls = new Map();
|
|
101
|
+
#chosen;
|
|
102
|
+
#stickPointer = -1;
|
|
79
103
|
#pointers = new Map();
|
|
80
104
|
#pinch = 0;
|
|
81
105
|
#draws = 0;
|
|
@@ -126,7 +150,7 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
126
150
|
/** Numbers for a test or a status line: the draws, the tiles, the renderer's own counts, the mesh, the quality of the last draw and the milliseconds of the last measured one. */
|
|
127
151
|
get stats() {
|
|
128
152
|
const scene = this.#view?.scene;
|
|
129
|
-
return { state: this.#state, draws: this.#draws, tiles: this.#progress, renderer: this.#renderer?.stats, mesh: scene?.mesh, quality: this.#quality(), drawMs: scene?.drawMs ?? this.#drawMs, rocks: scene?.rocks ?? 0 };
|
|
153
|
+
return { state: this.#state, draws: this.#draws, tiles: this.#progress, renderer: this.#renderer?.stats, mesh: scene?.mesh, quality: this.#quality(), scale: this.#drawScale, scaled: this.#scaled, drawMs: scene?.drawMs ?? this.#drawMs, rocks: scene?.rocks ?? 0 };
|
|
130
154
|
}
|
|
131
155
|
/** The quality of the next draw: the `quality` attribute, or in `auto` the quality of motion while the view moves and the machine's own quality of rest otherwise. */
|
|
132
156
|
#quality() {
|
|
@@ -156,6 +180,12 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
156
180
|
this.addEventListener("keydown", this.#onKeyDown);
|
|
157
181
|
this.addEventListener("keyup", this.#onKeyUp);
|
|
158
182
|
this.addEventListener("blur", this.#onBlur);
|
|
183
|
+
const stick = this.#root.getElementById("stick");
|
|
184
|
+
stick.addEventListener("pointerdown", this.#onStickDown);
|
|
185
|
+
stick.addEventListener("pointermove", this.#onStickMove);
|
|
186
|
+
stick.addEventListener("pointerup", this.#onStickUp);
|
|
187
|
+
stick.addEventListener("pointercancel", this.#onStickUp);
|
|
188
|
+
this.#showStick();
|
|
159
189
|
if (typeof IntersectionObserver === "function") {
|
|
160
190
|
this.#io = new IntersectionObserver((entries) => {
|
|
161
191
|
const last = entries[entries.length - 1];
|
|
@@ -189,12 +219,16 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
189
219
|
attributeChangedCallback(name) {
|
|
190
220
|
if (!this.isConnected)
|
|
191
221
|
return;
|
|
222
|
+
if (name === "stick") {
|
|
223
|
+
this.#showStick();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
192
226
|
if (name === "standby") {
|
|
193
227
|
if (!this.hasAttribute("standby"))
|
|
194
228
|
void this.#start();
|
|
195
229
|
return;
|
|
196
230
|
}
|
|
197
|
-
if (name === "site" || name === "body" || name === "tiles") {
|
|
231
|
+
if (name === "site" || name === "body" || name === "tiles" || name === "objects") {
|
|
198
232
|
this.#terrain = undefined;
|
|
199
233
|
this.#loading = undefined;
|
|
200
234
|
this.#pending.clear();
|
|
@@ -263,6 +297,9 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
263
297
|
// on standby the ground is loaded and nothing more: the renderer is another view's until the attribute goes
|
|
264
298
|
if (this.hasAttribute("standby"))
|
|
265
299
|
return;
|
|
300
|
+
// the things at the site (and the made ground keeping away from them) are known before the place the eyes start from is chosen
|
|
301
|
+
this.#objects = this.getAttribute("objects") === "off" ? [] : objectsOf(site.id);
|
|
302
|
+
setKeepOut(this.#objects);
|
|
266
303
|
if (!this.#placed) {
|
|
267
304
|
// a step or two from the landing point, out of any made crater
|
|
268
305
|
const stand = this.getAttribute("detail") === "off" ? { x: 0, y: 0 } : standingPlace(0, 0);
|
|
@@ -275,7 +312,8 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
275
312
|
this.#renderer = taken.renderer;
|
|
276
313
|
this.#release = taken.release;
|
|
277
314
|
}
|
|
278
|
-
|
|
315
|
+
this.#makeLabels();
|
|
316
|
+
const item = createSurfaceItem({ objects: this.#objects, traverse: this.#objects.length > 0 ? traverseOf(site.id) : [], levels: this.#terrain.levels, pictures: this.#terrain.pictures, horizons: this.#terrain.horizons, manifest: this.#terrain.manifest, groundY: (east, north) => this.#groundAt(east, north), key: `surface:${site.id}` });
|
|
279
317
|
this.#view = this.#renderer.view(this.#stage, item, { still: null });
|
|
280
318
|
}
|
|
281
319
|
const ok = await this.#view.focus();
|
|
@@ -341,8 +379,9 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
341
379
|
if (m === undefined)
|
|
342
380
|
return "";
|
|
343
381
|
const made = this.getAttribute("detail") === "off" ? "" : this.#lang() === "ja" ? "5 m より細かい地形(小さなクレーター、砂塵、岩)は計算で作ったもので、実測ではありません。" : "Detail finer than the 5 m grid (small craters, dust, rocks) is made, not measured.";
|
|
382
|
+
const things = this.#objects.length === 0 ? "" : this.#lang() === "ja" ? " 地面の物は、公表された座標の位置にこのパッケージが置いたもので、形は簡単な絵です。" : " The things on the ground are placed by this package at published positions, as plain drawings.";
|
|
344
383
|
const picture = m.picture === null || m.picture === undefined ? "" : ` ${m.picture.credit}.`;
|
|
345
|
-
return this.#lang() === "ja" ? `高さの実測: ${m.accuracy}。${m.credit}。${made}` : `Heights measured: ${m.accuracy}. ${m.credit}.${picture} ${made}`;
|
|
384
|
+
return this.#lang() === "ja" ? `高さの実測: ${m.accuracy}。${m.credit}。${made}${things}` : `Heights measured: ${m.accuracy}. ${m.credit}.${picture} ${made}${things}`;
|
|
346
385
|
}
|
|
347
386
|
/** The ground's height at a point over the site's: the measured heights, the made craters on them (if the page has them on) and the Moon's curve taken off. */
|
|
348
387
|
#groundAt(east, north) {
|
|
@@ -386,13 +425,176 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
386
425
|
else if (was > 250 && this.#restQuality === "medium")
|
|
387
426
|
this.#restQuality = "fast";
|
|
388
427
|
}
|
|
389
|
-
|
|
390
|
-
|
|
428
|
+
// the draws while the view moves are timed too (the first few), and a machine that takes over 24 ms for one is given a half size for them: a quarter of the pixels, stretched
|
|
429
|
+
const scaleAttr = this.getAttribute("scale");
|
|
430
|
+
if (this.#movingPending && was !== undefined) {
|
|
431
|
+
this.#movingPending = false;
|
|
432
|
+
this.#movingTimes.push(was);
|
|
433
|
+
if (this.#movingTimes.length >= 2 && this.#moveScale === 1) {
|
|
434
|
+
const sorted = [...this.#movingTimes].sort((a, b) => a - b);
|
|
435
|
+
if (sorted[Math.floor(sorted.length / 2)] > 24)
|
|
436
|
+
this.#moveScale = 0.5;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
const forced = scaleAttr === null || scaleAttr === "auto" ? undefined : Number(scaleAttr);
|
|
440
|
+
const timeMoving = auto && this.#moving && this.#movingTimes.length < 4 && forced === undefined;
|
|
441
|
+
if (timeMoving)
|
|
442
|
+
this.#movingPending = true;
|
|
443
|
+
this.#drawScale = forced !== undefined && Number.isFinite(forced) ? Math.min(1, Math.max(0.25, forced)) : this.#moving ? this.#moveScale : 1;
|
|
444
|
+
const measure = (auto && !this.#moving && this.#measured < 4) || timeMoving;
|
|
445
|
+
if (measure && !this.#moving)
|
|
391
446
|
this.#measured += 1;
|
|
392
|
-
|
|
447
|
+
if (this.#drawScale < 1)
|
|
448
|
+
this.#scaled += 1;
|
|
449
|
+
scene.apply({ eye: { east: this.#at.east, north: this.#at.north, up: this.#eyeUp() }, look: this.#look, sky: this.#sky, shadows: this.getAttribute("shadows") !== "off", detail: this.getAttribute("detail") !== "off", exposure: num(this.getAttribute("exposure"), 1.6), quality: this.#quality(), scale: this.#drawScale, objects: this.#objects.length > 0, measure: measure || this.getAttribute("measure") !== null });
|
|
393
450
|
this.#view.invalidate();
|
|
394
451
|
this.#draws += 1;
|
|
452
|
+
this.#placeLabels();
|
|
453
|
+
}
|
|
454
|
+
// --- the things at the site: a small button on each, which goes to it and says what it is ----------------------------------------------------------------------------------------------------
|
|
455
|
+
/** The things at the site, at their published places (none where the site has none or `objects="off"`). */
|
|
456
|
+
get objects() {
|
|
457
|
+
return this.#objects;
|
|
458
|
+
}
|
|
459
|
+
/** The words on a thing's button and in the line that says what it is. */
|
|
460
|
+
#objectWords(o) {
|
|
461
|
+
const ja = this.#lang() === "ja";
|
|
462
|
+
const short = { lander: ["Lunar module", "月着陸船"], rover: ["Rover", "月面車"], flag: ["Flag", "旗"], station: ["ALSEP", "ALSEP"], instrument: ["Transmitter", "送信機"] };
|
|
463
|
+
const placed = ja
|
|
464
|
+
? "このパッケージが、公表された座標(Haase ほか 2019)の位置に置きました。形はこちらで描いた簡単なもので、スキャンではありません。"
|
|
465
|
+
: "Placed by this package at its published position (Haase et al. 2019). The shape is a plain one drawn here, not a scan.";
|
|
466
|
+
const rover = ja ? "月面車は、最後の走行の記録の終点に置いています。向きと形はこちらで決めたものです。" : "The rover stands where the record of its last traverse ends; its heading and shape are ours.";
|
|
467
|
+
return { short: short[o.kind][ja ? 1 : 0], about: `${o.name[ja ? "ja" : "en"]}. ${o.kind === "rover" ? rover : placed}` };
|
|
468
|
+
}
|
|
469
|
+
#makeLabels() {
|
|
470
|
+
const box = this.#root.getElementById("labels");
|
|
471
|
+
box.replaceChildren();
|
|
472
|
+
this.#labelEls.clear();
|
|
473
|
+
for (const o of this.#objects) {
|
|
474
|
+
const button = document.createElement("button");
|
|
475
|
+
button.type = "button";
|
|
476
|
+
button.className = "label";
|
|
477
|
+
button.hidden = true;
|
|
478
|
+
button.setAttribute("aria-pressed", "false");
|
|
479
|
+
button.textContent = this.#objectWords(o).short;
|
|
480
|
+
button.addEventListener("click", (event) => {
|
|
481
|
+
event.stopPropagation();
|
|
482
|
+
this.choose(o.id);
|
|
483
|
+
});
|
|
484
|
+
// a press on the button is not a drag of the view
|
|
485
|
+
button.addEventListener("pointerdown", (event) => event.stopPropagation());
|
|
486
|
+
box.append(button);
|
|
487
|
+
this.#labelEls.set(o.id, button);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/** Put each button on its thing in the picture, or hide it behind the viewer, off the picture or too far to tell. Done at each draw: nothing moves by itself. */
|
|
491
|
+
#placeLabels() {
|
|
492
|
+
if (this.#labelEls.size === 0)
|
|
493
|
+
return;
|
|
494
|
+
const box = this.getBoundingClientRect();
|
|
495
|
+
const [w, h] = [box.width, box.height];
|
|
496
|
+
const vp = viewProjection([this.#at.east, this.#eyeUp(), -this.#at.north], this.#look, w / Math.max(1, h));
|
|
497
|
+
for (const o of this.#objects) {
|
|
498
|
+
const el = this.#labelEls.get(o.id);
|
|
499
|
+
const up = this.#groundAt(o.east, o.north) + (o.kind === "lander" ? 3.4 : o.kind === "flag" ? 2.6 : o.kind === "rover" ? 2.0 : 0.9);
|
|
500
|
+
const [x, y, z] = [o.east, up, -o.north];
|
|
501
|
+
const cw = vp[3] * x + vp[7] * y + vp[11] * z + vp[15];
|
|
502
|
+
const nx = (vp[0] * x + vp[4] * y + vp[8] * z + vp[12]) / cw;
|
|
503
|
+
const ny = (vp[1] * x + vp[5] * y + vp[9] * z + vp[13]) / cw;
|
|
504
|
+
const distance = Math.hypot(o.east - this.#at.east, o.north - this.#at.north);
|
|
505
|
+
const shown = cw > 0 && Math.abs(nx) < 1 && Math.abs(ny) < 1 && distance < 400 && distance > 1.5;
|
|
506
|
+
el.hidden = !shown;
|
|
507
|
+
if (shown)
|
|
508
|
+
el.style.transform = `translate(${((nx + 1) / 2) * w - el.offsetWidth / 2}px, ${((1 - ny) / 2) * h - el.offsetHeight - 4}px)`;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Choose a thing at the site: the eyes go to a few metres from it, looking at it, its button is pressed and a line says what it is and that it was placed by this package. `wakusei-surface-object` is sent
|
|
513
|
+
* with its id. Choosing the same one again, or `undefined`, puts the line away.
|
|
514
|
+
*
|
|
515
|
+
* @param id - A thing's id (`lm`, `rover`, `flag`, `alsep`, `sep`), or `undefined` for none.
|
|
516
|
+
* @returns Whether there is such a thing here.
|
|
517
|
+
*/
|
|
518
|
+
choose(id) {
|
|
519
|
+
const about = this.#root.getElementById("about");
|
|
520
|
+
const o = id === undefined ? undefined : this.#objects.find((x) => x.id === id);
|
|
521
|
+
if (id !== undefined && o === undefined)
|
|
522
|
+
return false;
|
|
523
|
+
if (o === undefined || this.#chosen === id) {
|
|
524
|
+
this.#chosen = undefined;
|
|
525
|
+
about.hidden = true;
|
|
526
|
+
for (const el of this.#labelEls.values())
|
|
527
|
+
el.setAttribute("aria-pressed", "false");
|
|
528
|
+
this.#changed(false);
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
this.#chosen = id;
|
|
532
|
+
for (const [key, el] of this.#labelEls)
|
|
533
|
+
el.setAttribute("aria-pressed", String(key === id));
|
|
534
|
+
about.textContent = this.#objectWords(o).about;
|
|
535
|
+
about.hidden = false;
|
|
536
|
+
// stand a few metres off, on the side the eyes are on, and look at it
|
|
537
|
+
const near = { lander: 14, rover: 7, flag: 5, station: 8, instrument: 6 };
|
|
538
|
+
const [dx, dy] = [this.#at.east - o.east, this.#at.north - o.north];
|
|
539
|
+
const length = Math.hypot(dx, dy) || 1;
|
|
540
|
+
const stand = near[o.kind];
|
|
541
|
+
const [east, north] = length < 1 ? [o.east - stand, o.north] : [o.east + (dx / length) * stand, o.north + (dy / length) * stand];
|
|
542
|
+
this.#at = { east, north };
|
|
543
|
+
const azimuth = ((Math.atan2(o.east - east, o.north - north) * 180) / Math.PI + 360) % 360;
|
|
544
|
+
this.#look = clampLook({ azimuth, pitch: o.kind === "lander" ? 8 : 5, fov: this.#look.fov });
|
|
545
|
+
this.dispatchEvent(new CustomEvent("wakusei-surface-object", { detail: { id: o.id, name: o.name }, bubbles: true, composed: true }));
|
|
546
|
+
this.#changed();
|
|
547
|
+
return true;
|
|
395
548
|
}
|
|
549
|
+
// --- the walking stick: for a touch screen, where there are no keys. One finger on the view looks, two fingers pinch to zoom, and the finger on the stick walks ----------------------------------------
|
|
550
|
+
/** Whether the stick is shown: `stick="on"` or `off`, and left out it is shown where the main pointer is a finger (`pointer: coarse`). */
|
|
551
|
+
#showStick() {
|
|
552
|
+
const own = this.getAttribute("stick");
|
|
553
|
+
const coarse = typeof matchMedia === "function" && matchMedia("(pointer: coarse)").matches;
|
|
554
|
+
const on = own === "on" || (own !== "off" && coarse);
|
|
555
|
+
const stick = this.#root?.getElementById("stick");
|
|
556
|
+
if (stick !== null && stick !== undefined)
|
|
557
|
+
stick.hidden = !on;
|
|
558
|
+
}
|
|
559
|
+
#onStickDown = (event) => {
|
|
560
|
+
event.stopPropagation(); // the view's own hands (look, pinch) never hear the finger that walks
|
|
561
|
+
if (this.#stickPointer !== -1)
|
|
562
|
+
return;
|
|
563
|
+
this.#stickPointer = event.pointerId;
|
|
564
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
565
|
+
this.#onStickMove(event);
|
|
566
|
+
};
|
|
567
|
+
#onStickMove = (event) => {
|
|
568
|
+
if (event.pointerId !== this.#stickPointer)
|
|
569
|
+
return;
|
|
570
|
+
event.stopPropagation();
|
|
571
|
+
const stick = event.currentTarget;
|
|
572
|
+
const box = stick.getBoundingClientRect();
|
|
573
|
+
const reach = box.width / 2;
|
|
574
|
+
let x = (event.clientX - (box.left + reach)) / reach;
|
|
575
|
+
let y = (event.clientY - (box.top + reach)) / reach;
|
|
576
|
+
const length = Math.hypot(x, y);
|
|
577
|
+
if (length > 1) {
|
|
578
|
+
x /= length;
|
|
579
|
+
y /= length;
|
|
580
|
+
}
|
|
581
|
+
// a small dead centre: a finger resting on the stick does not creep
|
|
582
|
+
this.#push = length < 0.12 ? { x: 0, y: 0 } : { x, y: -y };
|
|
583
|
+
const knob = this.#root.getElementById("knob");
|
|
584
|
+
knob.style.transform = `translate(${x * reach * 0.6}px, ${y * reach * 0.6}px)`;
|
|
585
|
+
if (this.#push.x !== 0 || this.#push.y !== 0) {
|
|
586
|
+
this.#walkAt = performance.now();
|
|
587
|
+
this.#walkTick();
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
#onStickUp = (event) => {
|
|
591
|
+
if (event.pointerId !== this.#stickPointer)
|
|
592
|
+
return;
|
|
593
|
+
event.stopPropagation();
|
|
594
|
+
this.#stickPointer = -1;
|
|
595
|
+
this.#push = { x: 0, y: 0 };
|
|
596
|
+
this.#root.getElementById("knob").style.transform = "";
|
|
597
|
+
};
|
|
396
598
|
// --- hands ---------------------------------------------------------------------------------------------------------------------------------------
|
|
397
599
|
#onPointerDown = (event) => {
|
|
398
600
|
this.#pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
|
|
@@ -461,19 +663,20 @@ export class WakuseiSurface extends HTMLElement {
|
|
|
461
663
|
/** While a key is held: a step every frame at a walking pace (and a turn at a quarter turn a second), at most thirty a second; nothing when no key is held. */
|
|
462
664
|
#walkTick = () => {
|
|
463
665
|
clearTimeout(this.#walkTimer);
|
|
464
|
-
if (this.#keys.size === 0)
|
|
666
|
+
if (this.#keys.size === 0 && this.#push.x === 0 && this.#push.y === 0)
|
|
465
667
|
return;
|
|
466
668
|
const now = performance.now();
|
|
467
669
|
const dt = Math.min(0.1, (now - this.#walkAt) / 1000);
|
|
468
670
|
this.#walkAt = now;
|
|
469
671
|
const k = this.#keys;
|
|
470
|
-
const ahead = (k.has("w") || k.has("ArrowUp") ? 1 : 0) - (k.has("s") || k.has("ArrowDown") ? 1 : 0);
|
|
471
|
-
const aside = (k.has("d") ? 1 : 0) - (k.has("a") ? 1 : 0);
|
|
672
|
+
const ahead = (k.has("w") || k.has("ArrowUp") ? 1 : 0) - (k.has("s") || k.has("ArrowDown") ? 1 : 0) + this.#push.y;
|
|
673
|
+
const aside = (k.has("d") ? 1 : 0) - (k.has("a") ? 1 : 0) + this.#push.x;
|
|
472
674
|
const turn = (k.has("e") || k.has("ArrowRight") ? 1 : 0) - (k.has("q") || k.has("ArrowLeft") ? 1 : 0);
|
|
473
675
|
if (turn !== 0)
|
|
474
676
|
this.#look = clampLook({ ...this.#look, azimuth: this.#look.azimuth + turn * 60 * dt });
|
|
677
|
+
const speed = Math.min(1, Math.hypot(ahead, aside)) / Math.max(1e-9, Math.hypot(ahead, aside));
|
|
475
678
|
if (ahead !== 0 || aside !== 0)
|
|
476
|
-
this.#at = stepOver(this.#at, this.#look.azimuth, ahead * WALK_SPEED * dt, aside * WALK_SPEED * dt);
|
|
679
|
+
this.#at = stepOver(this.#at, this.#look.azimuth, ahead * speed * WALK_SPEED * dt, aside * speed * WALK_SPEED * dt);
|
|
477
680
|
this.#changed();
|
|
478
681
|
this.#walkTimer = setTimeout(this.#walkTick, 33);
|
|
479
682
|
};
|