Repository navigation
Expand file tree
/
Copy pathpointer_record.js
More file actions
72 lines (52 loc) · 2.67 KB
/
Copy pathpointer_record.js
File metadata and controls
72 lines (52 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class PointerRecord {
constructor(canvasRect, ptrEvent) {
// get the pressure reported in the event
// if it is pointer pen event, just use that pressure
// if it is any other kind of event, then just the maximum pressure
const pressureRaw = clampToRange(ptrEvent.pressure, PRESSURE_RANGE);
const canvasPosXRaw = ptrEvent.offsetX;
const canvasPosYRaw = ptrEvent.offsetY;
this.type = ptrEvent.type;
this.buttons = ptrEvent.buttons;
this.pointerType = ptrEvent.pointerType;
this.screenPosX = ptrEvent.clientX;
this.screenPosY = ptrEvent.clientY;
this.canvasPosXRaw = canvasPosXRaw;
this.canvasPosYRaw = canvasPosYRaw;
this.canvasPosXProcessed = processingSettings.posXSmoother.apply(canvasPosXRaw);
this.canvasPosYProcessed = processingSettings.posYSmoother.apply(canvasPosYRaw);
this.pressureRaw = pressureRaw;
this.pressureProcessed = processPressure(pressureRaw);
this.buttons = ptrEvent.buttons;
this.tiltX = ptrEvent.tiltX;
this.tiltY = ptrEvent.tiltY;
this.tiltAzimuth = radiansToDegrees(ptrEvent.azimuthAngle);
this.tiltAltitude = radiansToDegrees(ptrEvent.altitudeAngle);
this.tiltXProcessed = processingSettings.tiltXSmoother.apply(ptrEvent.tiltX);
this.tiltYProcessed = processingSettings.tiltYSmoother.apply(ptrEvent.tiltY);
this.tiltAzimuthProcessed = radiansToDegrees(processingSettings.tiltAzimuthSmoother.apply(ptrEvent.azimuthAngle));
this.tiltAltitudeProcessed = radiansToDegrees(processingSettings.tiltAltitudeSmoother.apply(ptrEvent.altitudeAngle));
this.barrelRotation = ptrEvent.twist;
this.time = performance.now();
this.velocity = 0;
this.direction = 0;
if (paintState.canvasPosOld != null) {
const dx = this.canvasPosXProcessed - paintState.canvasPosOldAllEvents.x;
const dy = this.canvasPosYProcessed - paintState.canvasPosOldAllEvents.y;
if (paintState.timeOld != null) {
const dt = (this.time - paintState.timeOld) / 1000.0;
if (dt > 0) {
const dist = Math.hypot(dx, dy);
const rawSpeed = dist / dt;
const smoothedSpeed = processingSettings.velocitySmoother.apply(rawSpeed);
var direction = Math.atan2(dy, dx) * 180.0 / Math.PI;
if (direction < 0) {
direction = 359 + direction;
}
this.velocity = smoothedSpeed;
this.direction = direction;
}
}
}
}
}