@geoblocks/cesium-walk 0.2.0 → 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.
Files changed (2) hide show
  1. package/cesium-walk.js +24 -11
  2. 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
@@ -269,12 +272,11 @@ export default class CesiumWalk {
269
272
  // walk along the view direction projected onto the ground plane,
270
273
  // so that looking down does not push the camera into the terrain
271
274
  const normal = this.surfaceNormal_();
272
- const along = Cartesian3.multiplyByScalar(
273
- normal,
274
- Cartesian3.dot(camera.direction, normal),
275
+ const along = Cartesian3.subtract(
276
+ camera.direction,
277
+ Cartesian3.projectVector(camera.direction, normal, forwardScratch),
275
278
  forwardScratch
276
279
  );
277
- Cartesian3.subtract(camera.direction, along, along);
278
280
  const level = Cartesian3.magnitude(along) > CesiumMath.EPSILON6;
279
281
  if (level) {
280
282
  Cartesian3.normalize(along, along);
@@ -318,23 +320,34 @@ export default class CesiumWalk {
318
320
  if (this.landing_ < 1e-3) {
319
321
  this.landing_ = 0;
320
322
  }
321
- this.stepPhase_ += (Cartesian3.magnitude(this.velocity_) * deltaTime / STEP_LENGTH) * Math.PI;
323
+ this.stepPhase_ += (Cartesian3.magnitude(this.velocity_) * deltaTime / STEP_LENGTH) * CesiumMath.PI;
322
324
  this.clampCameraToTerrain_();
323
325
  }
324
326
 
325
327
  /**
326
- * 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.
327
330
  * @param {Cartesian3} direction The unit direction of the step, level.
328
331
  * @param {number} step The length of the step, negative backward, in meters.
329
332
  * @param {string} kind Which steps these are, for the obstacle looked for last time.
330
333
  */
331
334
  step_(direction, step, kind) {
332
335
  const camera = this.viewer.camera;
333
- const toward = Cartesian3.multiplyByScalar(direction, Math.sign(step), stepScratch);
334
- const obstacle = this.collision ? this.obstacleAhead(toward, `${kind}${Math.sign(step)}`) : undefined;
335
- const allowed = blockedStep(toward, Math.abs(step), camera.positionWC, obstacle, allowedScratch);
336
- if (allowed.length > 0) {
337
- camera.move(allowed.direction, allowed.length);
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);
338
351
  }
339
352
  }
340
353
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoblocks/cesium-walk",
3
- "version": "0.2.0",
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.0"
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": "a4cb0a96ab6cadc09a8a2347acfa9f28b5648d03"
31
+ "gitHead": "5c6ee12b4e35f46ff733cf628da105f55121fbf3"
32
32
  }