ソースを参照

Add TrackablePointer.elapsedTime

customisations
alemart 11ヶ月前
コミット
ef4e38ba0e

+ 6
- 0
docs/api/trackable-pointer.md ファイルの表示

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 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
 ### isPrimary
61
 ### isPrimary
56
 
62
 
57
 `pointer.isPrimary: boolean, read-only`
63
 `pointer.isPrimary: boolean, read-only`

+ 4
- 1
src/trackers/pointer-tracker/pointer-tracker.ts ファイルの表示

269
             // determine the velocity
269
             // determine the velocity
270
             const velocity = deltaPosition._clone()._scale(inverseDeltaTime);
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
             // determine whether or not this is the primary pointer for this type
275
             // determine whether or not this is the primary pointer for this type
273
             const isPrimary = event.isPrimary;
276
             const isPrimary = event.isPrimary;
274
 
277
 
277
 
280
 
278
             // we create new trackable instances on each frame;
281
             // we create new trackable instances on each frame;
279
             // these will be exported and consumed by the user
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 ファイルの表示

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

読み込み中…
キャンセル
保存