@geoblocks/cesium-walk 0.2.1 → 0.2.2
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/cesium-walk.js +20 -6
- package/package.json +3 -3
package/cesium-walk.js
CHANGED
|
@@ -12,6 +12,9 @@ const LANDING = 0.15;
|
|
|
12
12
|
const BOB_TIME = 0.15;
|
|
13
13
|
// in meters: nearer its height, the camera stays, so that a walker standing still renders no frame
|
|
14
14
|
const SETTLED = 1e-3;
|
|
15
|
+
// at a concave corner the slide along one wall heads into the other: a step is checked again along its slide, this
|
|
16
|
+
// many times at most, before it is taken
|
|
17
|
+
const SLIDE_PASSES = 3;
|
|
15
18
|
|
|
16
19
|
// the default bindings: W, A, S, D or the arrows to walk, Shift to sprint and Space to jump; on a gamepad, the
|
|
17
20
|
// left stick, at any speed and in any direction, Cross to sprint and Square to jump, as in GTA 5. Keys by
|
|
@@ -322,18 +325,29 @@ export default class CesiumWalk {
|
|
|
322
325
|
}
|
|
323
326
|
|
|
324
327
|
/**
|
|
325
|
-
* Moves the camera a step, stopping at obstacles or sliding along them
|
|
328
|
+
* Moves the camera a step, stopping at obstacles or sliding along them; a slide is checked against the obstacles
|
|
329
|
+
* ahead of it in turn, so that at a concave corner it stops at the second wall rather than going through it.
|
|
326
330
|
* @param {Cartesian3} direction The unit direction of the step, level.
|
|
327
331
|
* @param {number} step The length of the step, negative backward, in meters.
|
|
328
332
|
* @param {string} kind Which steps these are, for the obstacle looked for last time.
|
|
329
333
|
*/
|
|
330
334
|
step_(direction, step, kind) {
|
|
331
335
|
const camera = this.viewer.camera;
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
336
|
+
let toward = Cartesian3.multiplyByScalar(direction, Math.sign(step), stepScratch);
|
|
337
|
+
let length = Math.abs(step);
|
|
338
|
+
for (let pass = 0; pass < SLIDE_PASSES && length > 0; pass++) {
|
|
339
|
+
// a slide's look is its own, not the step's: the probe keeps its last look in each direction by its key
|
|
340
|
+
const obstacle = this.collision ? this.obstacleAhead(toward, `${kind}${Math.sign(step)}${pass ? "slide" : ""}`) : undefined;
|
|
341
|
+
const allowed = blockedStep(toward, length, camera.positionWC, obstacle, allowedScratch);
|
|
342
|
+
const same = Cartesian3.equalsEpsilon(allowed.direction, toward, CesiumMath.EPSILON9);
|
|
343
|
+
length = allowed.length;
|
|
344
|
+
toward = Cartesian3.clone(allowed.direction, stepScratch);
|
|
345
|
+
if (same) {
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (length > 0) {
|
|
350
|
+
camera.move(toward, length);
|
|
337
351
|
}
|
|
338
352
|
}
|
|
339
353
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geoblocks/cesium-walk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@geoblocks/cesium-input": "^0.1.0",
|
|
25
|
-
"@geoblocks/cesium-obstacles": "^0.2.
|
|
25
|
+
"@geoblocks/cesium-obstacles": "^0.2.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@cesium/core": ">=0.1.0",
|
|
29
29
|
"@cesium/engine": ">=10"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "5c6ee12b4e35f46ff733cf628da105f55121fbf3"
|
|
32
32
|
}
|