瀏覽代碼

Introduce TrackablePointer.movementDuration

customisations
alemart 8 月之前
父節點
當前提交
aabab0bef7

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

64
 
64
 
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`.
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
 ### isPrimary
73
 ### isPrimary
68
 
74
 
69
 `pointer.isPrimary: boolean, read-only`
75
 `pointer.isPrimary: boolean, read-only`

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

383
             // determine how much this pointer has moved since its tracking began
383
             // determine how much this pointer has moved since its tracking began
384
             const movementLength = previous ? previous.movementLength + deltaPosition.length() : 0;
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
             // determine whether or not this is the primary pointer for this type
389
             // determine whether or not this is the primary pointer for this type
387
             const isPrimary = event.isPrimary;
390
             const isPrimary = event.isPrimary;
388
 
391
 
391
 
394
 
392
             // we create new trackable instances on each frame;
395
             // we create new trackable instances on each frame;
393
             // these will be exported and consumed by the user
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
     /** 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 duration: number;
60
     readonly duration: number;
61
 
61
 
62
+    /** the total time, in seconds, in which this pointer has moved */
63
+    readonly movementDuration: number;
64
+
62
     /** how much this pointer has moved, in space units, since its tracking began */
65
     /** how much this pointer has moved, in space units, since its tracking began */
63
     readonly movementLength: number;
66
     readonly movementLength: number;
64
 
67
 

Loading…
取消
儲存