浏览代码

Introduce TrackablePointer.movementDuration

customisations
alemart 8 个月前
父节点
当前提交
aabab0bef7

+ 6
- 0
docs/api/trackable-pointer.md 查看文件

@@ -64,6 +64,12 @@ The elapsed time, in seconds, since the tracking of this pointer began.
64 64
 
65 65
 How much this pointer has moved, in space units, since its tracking began. You can get the average speed of motion by calculating the ratio `movementLength / duration`.
66 66
 
67
+### movementDuration
68
+
69
+`pointer.movementDuration: number, read-only`
70
+
71
+The total time, in seconds, in which this pointer has moved. You can get the average speed of motion, excluding the times in which this pointer has not moved, by calculating the ratio `movementLength / movementDuration`.
72
+
67 73
 ### isPrimary
68 74
 
69 75
 `pointer.isPrimary: boolean, read-only`

+ 4
- 1
src/trackers/pointer-tracker/pointer-tracker.ts 查看文件

@@ -383,6 +383,9 @@ export class PointerTracker implements Tracker
383 383
             // determine how much this pointer has moved since its tracking began
384 384
             const movementLength = previous ? previous.movementLength + deltaPosition.length() : 0;
385 385
 
386
+            // determine the duration of the movement
387
+            const movementDuration = !previous ? 0 : previous.movementDuration + (movementLength > previous.movementLength ? deltaTime : 0);
388
+
386 389
             // determine whether or not this is the primary pointer for this type
387 390
             const isPrimary = event.isPrimary;
388 391
 
@@ -391,7 +394,7 @@ export class PointerTracker implements Tracker
391 394
 
392 395
             // we create new trackable instances on each frame;
393 396
             // these will be exported and consumed by the user
394
-            this._newPointers.set(id, { id, phase, position, deltaPosition, initialPosition, velocity, duration, movementLength, isPrimary, kind });
397
+            this._newPointers.set(id, { id, phase, position, deltaPosition, initialPosition, velocity, duration, movementDuration, movementLength, isPrimary, kind });
395 398
 
396 399
         }
397 400
 

+ 3
- 0
src/trackers/pointer-tracker/trackable-pointer.ts 查看文件

@@ -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 duration: number;
61 61
 
62
+    /** the total time, in seconds, in which this pointer has moved */
63
+    readonly movementDuration: number;
64
+
62 65
     /** how much this pointer has moved, in space units, since its tracking began */
63 66
     readonly movementLength: number;
64 67
 

正在加载...
取消
保存