|
@@ -22,7 +22,8 @@
|
22
|
22
|
|
23
|
23
|
import Speedy from 'speedy-vision';
|
24
|
24
|
import { SpeedyPromise } from 'speedy-vision/types/core/speedy-promise';
|
25
|
|
-import { Trackable, TrackerResult, TrackerOutput, Tracker } from '../tracker';
|
|
25
|
+import { TrackerResult, TrackerOutput, Tracker } from '../tracker';
|
|
26
|
+import { TrackablePointer, TrackablePointerPhase } from './trackable-pointer';
|
26
|
27
|
import { PointerSource } from '../../sources/pointer-source';
|
27
|
28
|
import { Vector2 } from '../../geometry/vector2';
|
28
|
29
|
import { Utils, Nullable } from '../../utils/utils';
|
|
@@ -31,42 +32,6 @@ import { Session } from '../../core/session';
|
31
|
32
|
import { Viewport } from '../../core/viewport';
|
32
|
33
|
|
33
|
34
|
/**
|
34
|
|
- * The possible phases of a TrackablePointer
|
35
|
|
- */
|
36
|
|
-export type TrackablePointerPhase = 'began' | 'moved' | 'stationary' | 'ended' | 'canceled';
|
37
|
|
-
|
38
|
|
-/**
|
39
|
|
- * A trackable representing an instance of pointer-based input such as a mouse
|
40
|
|
- * click or a touch on the screen
|
41
|
|
- */
|
42
|
|
-export interface TrackablePointer extends Trackable
|
43
|
|
-{
|
44
|
|
- /** a unique identifier assigned to this trackable */
|
45
|
|
- readonly id: number;
|
46
|
|
-
|
47
|
|
- /** the phase of the trackable */
|
48
|
|
- readonly phase: TrackablePointerPhase;
|
49
|
|
-
|
50
|
|
- /** current position in normalized coordinates [-1,1]x[-1,1] */
|
51
|
|
- readonly position: Vector2;
|
52
|
|
-
|
53
|
|
- /** the position delta since the last frame */
|
54
|
|
- readonly deltaPosition: Vector2;
|
55
|
|
-
|
56
|
|
- /** the first position of this trackable, given in normalized coordinates */
|
57
|
|
- readonly initialPosition: Vector2;
|
58
|
|
-
|
59
|
|
- /** the current velocity, given in normalized coordinates per second */
|
60
|
|
- readonly velocity: Vector2;
|
61
|
|
-
|
62
|
|
- /** whether or not this is the primary pointer for this type */
|
63
|
|
- readonly isPrimary: boolean;
|
64
|
|
-
|
65
|
|
- /** the type of the originating device; typically "mouse", "touch" or "pen" */
|
66
|
|
- readonly type: string;
|
67
|
|
-}
|
68
|
|
-
|
69
|
|
-/**
|
70
|
35
|
* A result of a PointerTracker. It's meant to be consumed by the user/application
|
71
|
36
|
*/
|
72
|
37
|
export interface PointerTrackerResult extends TrackerResult
|
|
@@ -117,11 +82,11 @@ export class PointerTracker implements Tracker
|
117
|
82
|
/** new pointers */
|
118
|
83
|
private _newPointers: Map<number, TrackablePointer>;
|
119
|
84
|
|
120
|
|
- /** last output */
|
121
|
|
- private _lastOutput: PointerTrackerOutput;
|
|
85
|
+ /** previous output */
|
|
86
|
+ private _previousOutput: PointerTrackerOutput;
|
122
|
87
|
|
123
|
|
- /** time of the last update */
|
124
|
|
- private _lastUpdateTime: DOMHighResTimeStamp;
|
|
88
|
+ /** time of the previous update */
|
|
89
|
+ private _previousUpdateTime: DOMHighResTimeStamp;
|
125
|
90
|
|
126
|
91
|
|
127
|
92
|
|
|
@@ -134,8 +99,8 @@ export class PointerTracker implements Tracker
|
134
|
99
|
this._viewport = null;
|
135
|
100
|
this._activePointers = new Map();
|
136
|
101
|
this._newPointers = new Map();
|
137
|
|
- this._lastOutput = this._generateOutput();
|
138
|
|
- this._lastUpdateTime = Number.POSITIVE_INFINITY;
|
|
102
|
+ this._previousOutput = this._generateOutput();
|
|
103
|
+ this._previousUpdateTime = Number.POSITIVE_INFINITY;
|
139
|
104
|
}
|
140
|
105
|
|
141
|
106
|
/**
|
|
@@ -202,7 +167,7 @@ export class PointerTracker implements Tracker
|
202
|
167
|
const canvas = this._viewport!.canvas;
|
203
|
168
|
const rect = canvas.getBoundingClientRect(); // may be different in different frames!
|
204
|
169
|
|
205
|
|
- // find the time between this and the last update of this tracker
|
|
170
|
+ // find the time between this and the previous update of this tracker
|
206
|
171
|
const deltaTime = this._updateTime();
|
207
|
172
|
const inverseDeltaTime = (deltaTime > 1e-5) ? 1 / deltaTime : 60; // 1/dt = 1 / (1/60) with 60 fps
|
208
|
173
|
|
|
@@ -321,22 +286,22 @@ export class PointerTracker implements Tracker
|
321
|
286
|
this._newPointers.clear();
|
322
|
287
|
|
323
|
288
|
// generate output
|
324
|
|
- this._lastOutput = this._generateOutput();
|
|
289
|
+ this._previousOutput = this._generateOutput();
|
325
|
290
|
|
326
|
291
|
// test
|
327
|
|
- //console.log(JSON.stringify(this._lastOutput.exports.trackables, null, 4));
|
|
292
|
+ //console.log(JSON.stringify(this._prevOutput.exports.trackables, null, 4));
|
328
|
293
|
|
329
|
294
|
// done!
|
330
|
295
|
return Speedy.Promise.resolve();
|
331
|
296
|
}
|
332
|
297
|
|
333
|
298
|
/**
|
334
|
|
- * Output of the last frame
|
|
299
|
+ * Output of the previous frame
|
335
|
300
|
* @internal
|
336
|
301
|
*/
|
337
|
302
|
get _output(): PointerTrackerOutput
|
338
|
303
|
{
|
339
|
|
- return this._lastOutput;
|
|
304
|
+ return this._previousOutput;
|
340
|
305
|
}
|
341
|
306
|
|
342
|
307
|
/**
|
|
@@ -392,11 +357,11 @@ export class PointerTracker implements Tracker
|
392
|
357
|
{
|
393
|
358
|
const now = performance.now() * 0.001;
|
394
|
359
|
|
395
|
|
- if(this._lastUpdateTime > now)
|
396
|
|
- this._lastUpdateTime = now;
|
|
360
|
+ if(this._previousUpdateTime > now)
|
|
361
|
+ this._previousUpdateTime = now;
|
397
|
362
|
|
398
|
|
- const prev = this._lastUpdateTime;
|
399
|
|
- this._lastUpdateTime = now;
|
|
363
|
+ const prev = this._previousUpdateTime;
|
|
364
|
+ this._previousUpdateTime = now;
|
400
|
365
|
|
401
|
366
|
return now - prev;
|
402
|
367
|
}
|