ソースを参照

Introduce TrackablePointer.deltaPosition

customisations
alemart 10ヶ月前
コミット
2ee1b858ea
1個のファイルの変更13行の追加6行の削除
  1. 13
    6
      src/trackers/pointer-tracker/pointer-tracker.ts

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

@@ -50,7 +50,10 @@ export interface TrackablePointer extends Trackable
50 50
     /** current position in normalized coordinates [-1,1]x[-1,1] */
51 51
     readonly position: Vector2;
52 52
 
53
-    /** the first position, given in normalized coordinates */
53
+    /** the position delta since the last frame */
54
+    readonly deltaPosition: Vector2;
55
+
56
+    /** the first position of this trackable, given in normalized coordinates */
54 57
     readonly initialPosition: Vector2;
55 58
 
56 59
     /** whether or not this is the primary pointer for this type */
@@ -279,19 +282,23 @@ export class PointerTracker implements Tracker
279 282
             const relY = -(2 * absY / rect.height - 1); // flip Y axis
280 283
             const position = new Vector2(relX, relY);
281 284
 
285
+            // determine the position delta
286
+            const deltaPosition = !previous ? Vector2.Zero() :
287
+                                  new Vector2(position.x, position.y)._subtract(previous.position);
288
+
282 289
             // determine the initial position
283 290
             const initialPosition = previous ? previous.initialPosition :
284
-                                    Object.freeze(new Vector2()._copyFrom(position));
285
-
286
-            // determine the type of the originating device
287
-            const type = event.pointerType;
291
+                                    Object.freeze(new Vector2(position.x, position.y));
288 292
 
289 293
             // determine whether or not this is the primary pointer for this type
290 294
             const isPrimary = event.isPrimary;
291 295
 
296
+            // determine the type of the originating device
297
+            const type = event.pointerType;
298
+
292 299
             // we create new trackable instances on each frame;
293 300
             // these will be exported and consumed by the user
294
-            this._newPointers.set(id, { id, phase, position, initialPosition, isPrimary, type });
301
+            this._newPointers.set(id, { id, phase, position, deltaPosition, initialPosition, isPrimary, type });
295 302
 
296 303
         }
297 304
 

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