Browse Source

Introduce TrackablePointer.deltaPosition

customisations
alemart 10 months ago
parent
commit
2ee1b858ea
1 changed files with 13 additions and 6 deletions
  1. 13
    6
      src/trackers/pointer-tracker/pointer-tracker.ts

+ 13
- 6
src/trackers/pointer-tracker/pointer-tracker.ts View File

50
     /** current position in normalized coordinates [-1,1]x[-1,1] */
50
     /** current position in normalized coordinates [-1,1]x[-1,1] */
51
     readonly position: Vector2;
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
     readonly initialPosition: Vector2;
57
     readonly initialPosition: Vector2;
55
 
58
 
56
     /** whether or not this is the primary pointer for this type */
59
     /** whether or not this is the primary pointer for this type */
279
             const relY = -(2 * absY / rect.height - 1); // flip Y axis
282
             const relY = -(2 * absY / rect.height - 1); // flip Y axis
280
             const position = new Vector2(relX, relY);
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
             // determine the initial position
289
             // determine the initial position
283
             const initialPosition = previous ? previous.initialPosition :
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
             // determine whether or not this is the primary pointer for this type
293
             // determine whether or not this is the primary pointer for this type
290
             const isPrimary = event.isPrimary;
294
             const isPrimary = event.isPrimary;
291
 
295
 
296
+            // determine the type of the originating device
297
+            const type = event.pointerType;
298
+
292
             // we create new trackable instances on each frame;
299
             // we create new trackable instances on each frame;
293
             // these will be exported and consumed by the user
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
 

Loading…
Cancel
Save