Explorar el Código

Introduce TrackablePointer.totalDistance

customisations
alemart hace 9 meses
padre
commit
9f26b4d944

+ 7
- 1
docs/api/trackable-pointer.md Ver fichero

@@ -50,7 +50,7 @@ The difference between the position of the pointer in this and in the previous f
50 50
 
51 51
 `pointer.velocity: Vector2, read-only`
52 52
 
53
-The current velocity of the pointer, given in normalized units per second. You can get the speed of motion by calculating the [magnitude](vector2.md#length) of this vector.
53
+The current velocity of the pointer, given in normalized units per second. You can get the current speed of motion by calculating the [magnitude](vector2.md#length) of this vector.
54 54
 
55 55
 ### elapsedTime
56 56
 
@@ -58,6 +58,12 @@ The current velocity of the pointer, given in normalized units per second. You c
58 58
 
59 59
 The elapsed time, in seconds, since the tracking of this pointer began.
60 60
 
61
+### totalDistance
62
+
63
+`pointer.totalDistance: number, read-only`
64
+
65
+How much this pointer has moved, in normalized units, since its tracking began. You can get the average speed of motion by calculating the ratio `totalDistance / elapsedTime`.
66
+
61 67
 ### isPrimary
62 68
 
63 69
 `pointer.isPrimary: boolean, read-only`

+ 4
- 1
src/trackers/pointer-tracker/pointer-tracker.ts Ver fichero

@@ -304,6 +304,9 @@ export class PointerTracker implements Tracker
304 304
             // determine the elapsed time since the tracking began
305 305
             const elapsedTime = previous ? previous.elapsedTime + deltaTime : 0;
306 306
 
307
+            // determine how much this pointer has moved since its tracking began
308
+            const totalDistance = previous ? previous.totalDistance + deltaPosition.length() : 0;
309
+
307 310
             // determine whether or not this is the primary pointer for this type
308 311
             const isPrimary = event.isPrimary;
309 312
 
@@ -312,7 +315,7 @@ export class PointerTracker implements Tracker
312 315
 
313 316
             // we create new trackable instances on each frame;
314 317
             // these will be exported and consumed by the user
315
-            this._newPointers.set(id, { id, phase, position, deltaPosition, initialPosition, velocity, elapsedTime, isPrimary, kind });
318
+            this._newPointers.set(id, { id, phase, position, deltaPosition, initialPosition, velocity, elapsedTime, totalDistance, isPrimary, kind });
316 319
 
317 320
         }
318 321
 

+ 3
- 0
src/trackers/pointer-tracker/trackable-pointer.ts Ver fichero

@@ -59,6 +59,9 @@ export interface TrackablePointer extends Trackable
59 59
     /** elapsed time, in seconds, since the tracking of this pointer began */
60 60
     readonly elapsedTime: number;
61 61
 
62
+    /** how much this pointer has moved, in normalized units, since its tracking began */
63
+    readonly totalDistance: number;
64
+
62 65
     /** whether or not this is the primary pointer for this type */
63 66
     readonly isPrimary: boolean;
64 67
 

Loading…
Cancelar
Guardar