Parcourir la source

Add TrackablePointer.elapsedTime

customisations
alemart il y a 10 mois
Parent
révision
ef4e38ba0e

+ 6
- 0
docs/api/trackable-pointer.md Voir le fichier

@@ -52,6 +52,12 @@ The difference between the position of the pointer in this and in the previous f
52 52
 
53 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.
54 54
 
55
+### elapsedTime
56
+
57
+`pointer.elapsedTime: number, read-only`
58
+
59
+The elapsed time, in seconds, since the tracking of this pointer began.
60
+
55 61
 ### isPrimary
56 62
 
57 63
 `pointer.isPrimary: boolean, read-only`

+ 4
- 1
src/trackers/pointer-tracker/pointer-tracker.ts Voir le fichier

@@ -269,6 +269,9 @@ export class PointerTracker implements Tracker
269 269
             // determine the velocity
270 270
             const velocity = deltaPosition._clone()._scale(inverseDeltaTime);
271 271
 
272
+            // determine the elapsed time since the tracking began
273
+            const elapsedTime = previous ? previous.elapsedTime + deltaTime : 0;
274
+
272 275
             // determine whether or not this is the primary pointer for this type
273 276
             const isPrimary = event.isPrimary;
274 277
 
@@ -277,7 +280,7 @@ export class PointerTracker implements Tracker
277 280
 
278 281
             // we create new trackable instances on each frame;
279 282
             // these will be exported and consumed by the user
280
-            this._newPointers.set(id, { id, phase, position, deltaPosition, initialPosition, velocity, isPrimary, type });
283
+            this._newPointers.set(id, { id, phase, position, deltaPosition, initialPosition, velocity, elapsedTime, isPrimary, type });
281 284
 
282 285
         }
283 286
 

+ 3
- 0
src/trackers/pointer-tracker/trackable-pointer.ts Voir le fichier

@@ -56,6 +56,9 @@ export interface TrackablePointer extends Trackable
56 56
     /** current velocity, given in normalized units per second */
57 57
     readonly velocity: Vector2;
58 58
 
59
+    /** elapsed time, in seconds, since the tracking of this pointer began */
60
+    readonly elapsedTime: number;
61
+
59 62
     /** whether or not this is the primary pointer for this type */
60 63
     readonly isPrimary: boolean;
61 64
 

Chargement…
Annuler
Enregistrer