fixup pan touch

This commit is contained in:
Ladd 2025-12-28 16:00:10 -06:00
parent a6eda0226b
commit 8f0c0737fd

View File

@ -43,6 +43,10 @@ export class Pointer {
this.handlePointerUp({x: e.clientX, y: e.clientY});
});
el.addEventListener('pointerleave', e => {
this.handlePointerUp({x: e.clientX, y: e.clientY});
});
// Monitor wheel events
el.addEventListener('wheel', e => {
const factor = e.deltaY < 0 ? ZOOM_IN_FACTOR : ZOOM_OUT_FACTOR;
@ -126,16 +130,19 @@ export class Pointer {
// Set panning velocity
if (this.panTouchStart && this.panTouchLatest) {
const dt = (this.panTouchLatest.t - this.panTouchStart.t) / 1000;
const latest = this.panTouchLatest;
const start = this.panTouchStart;
// const speed = Math.sqrt((latest.x - start.x)**2 + (latest.y - start.y)**2) / dt;
const { scale } = this.sim.display;
this.panning = {
velocity: {
x: 2 * (latest.x - start.x) / scale / dt,
y: 2 * (latest.y - start.y) / scale / dt,
}
};
if (!dt) {
this.panning = undefined;
} else {
const { v } = this.pointerHistory[this.pointerHistory.length - 1];
// Convert pointer velocity to simulation scale
v.x /= this.sim.display.scale;
v.y /= this.sim.display.scale;
this.panning = {
velocity: v
};
}
this.panTouchStart = undefined;
}
}
@ -159,12 +166,14 @@ export class Pointer {
this.sim.objects.handlePointerMove({x, y, vx: v.x, vy: v.y});
} else if (this.sim.isCurrentMode(MODE_PAN_VIEW)) {
// Event loop should be able to read
this.panTouchLatest = {
x: clientX,
y: clientY,
t: document.timeline.currentTime,
};
if (this.panTouchStart) {
// Event loop should be able to read
this.panTouchLatest = {
x: clientX,
y: clientY,
t: document.timeline.currentTime,
};
}
}
}