Browse Source

Introduce TrackablePointer.totalDistance

customisations
alemart 9 months ago
parent
commit
9f26b4d944

+ 7
- 1
docs/api/trackable-pointer.md View File

50
 
50
 
51
 `pointer.velocity: Vector2, read-only`
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
 ### elapsedTime
55
 ### elapsedTime
56
 
56
 
58
 
58
 
59
 The elapsed time, in seconds, since the tracking of this pointer began.
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
 ### isPrimary
67
 ### isPrimary
62
 
68
 
63
 `pointer.isPrimary: boolean, read-only`
69
 `pointer.isPrimary: boolean, read-only`

+ 4
- 1
src/trackers/pointer-tracker/pointer-tracker.ts View File

304
             // determine the elapsed time since the tracking began
304
             // determine the elapsed time since the tracking began
305
             const elapsedTime = previous ? previous.elapsedTime + deltaTime : 0;
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
             // determine whether or not this is the primary pointer for this type
310
             // determine whether or not this is the primary pointer for this type
308
             const isPrimary = event.isPrimary;
311
             const isPrimary = event.isPrimary;
309
 
312
 
312
 
315
 
313
             // we create new trackable instances on each frame;
316
             // we create new trackable instances on each frame;
314
             // these will be exported and consumed by the user
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 View File

59
     /** elapsed time, in seconds, since the tracking of this pointer began */
59
     /** elapsed time, in seconds, since the tracking of this pointer began */
60
     readonly elapsedTime: number;
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
     /** whether or not this is the primary pointer for this type */
65
     /** whether or not this is the primary pointer for this type */
63
     readonly isPrimary: boolean;
66
     readonly isPrimary: boolean;
64
 
67
 

Loading…
Cancel
Save