tweaks
This commit is contained in:
parent
59bf820081
commit
0319df06cc
@ -109,7 +109,7 @@ export class Display {
|
||||
ctx.beginPath();
|
||||
let dash = false;
|
||||
for (let i = 0; i < obj.history.length ; i++) {
|
||||
// if (i % 2) continue;
|
||||
// if (i % 2 > 0) continue;
|
||||
const {position: {x, y}} = obj.history[i];
|
||||
if (dashedTraces) {
|
||||
if (dash) {
|
||||
|
||||
31
pointer.js
31
pointer.js
@ -14,7 +14,7 @@ export class Pointer {
|
||||
|
||||
pointerHistory = [];
|
||||
draggingElement = undefined;
|
||||
panning = undefined;
|
||||
panning = undefined; // { velocity: {x and y in sim coordinates}, paused: boolean }
|
||||
panTouchStart = undefined; // {x: undefined, y: undefined, t: undefined};
|
||||
panTouchLatest = undefined; // {x: undefined, y: undefined, t: undefined};
|
||||
suppressClick = false;
|
||||
@ -133,15 +133,15 @@ export class Pointer {
|
||||
handlePointerDown({x: clientX, y: clientY}) {
|
||||
this.clearPointerHistory(5);
|
||||
this.updatePointer({x: clientX, y: clientY});
|
||||
const {x, y} = this.sim.screenToSim(clientX, clientY)
|
||||
|
||||
if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) {
|
||||
const {x, y} = this.sim.screenToSim(clientX, clientY)
|
||||
this.sim.objects.handlePointerDown({x, y});
|
||||
|
||||
} else if (this.sim.isCurrentMode(MODE_PAN_VIEW)) {
|
||||
this.panTouchStart = {
|
||||
x,
|
||||
y,
|
||||
x: clientX,
|
||||
y: clientY,
|
||||
t: document.timeline.currentTime,
|
||||
viewOrigin: {...this.sim.display.viewOrigin},
|
||||
};
|
||||
@ -160,12 +160,15 @@ export class Pointer {
|
||||
} else if (this.sim.isCurrentMode(MODE_PAN_VIEW)) {
|
||||
// Set panning velocity
|
||||
if (this.panTouchStart && this.panTouchLatest) {
|
||||
const dt = this.panTouchLatest.t - this.panTouchStart.t;
|
||||
const current = this.panning?.velocity;
|
||||
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: (current?.x ?? 0) + (this.panTouchLatest.x - this.panTouchStart.x) / dt,
|
||||
y: (current?.y ?? 0) + (this.panTouchLatest.y - this.panTouchStart.y) / dt,
|
||||
x: 2 * (latest.x - start.x) / scale / dt,
|
||||
y: 2 * (latest.y - start.y) / scale / dt,
|
||||
}
|
||||
};
|
||||
this.panTouchStart = undefined;
|
||||
@ -186,18 +189,16 @@ export class Pointer {
|
||||
// v.x = v.x + a.x * v.dt / this.sim.display.scale / 2;
|
||||
// v.y = v.y + a.y * v.dt / this.sim.display.scale / 2;
|
||||
|
||||
const {x, y} = this.sim.screenToSim(clientX, clientY);
|
||||
|
||||
if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) {
|
||||
const {x, y} = this.sim.screenToSim(clientX, clientY);
|
||||
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,
|
||||
y,
|
||||
x: clientX,
|
||||
y: clientY,
|
||||
t: document.timeline.currentTime,
|
||||
viewOrigin: {...this.sim.display.viewOrigin},
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -212,8 +213,8 @@ export class Pointer {
|
||||
// Direct translate
|
||||
const start = this.panTouchStart;
|
||||
const latest = this.panTouchLatest;
|
||||
this.sim.display.viewOrigin.x -= latest.x - start.x;
|
||||
this.sim.display.viewOrigin.y -= latest.y - start.y;
|
||||
this.sim.display.viewOrigin.x = start.viewOrigin.x - (latest.x - start.x) / this.sim.display.scale;
|
||||
this.sim.display.viewOrigin.y = start.viewOrigin.y - (latest.y - start.y) / this.sim.display.scale;
|
||||
} else if (this.panning && !this.panning.paused) {
|
||||
// Apply update to viewOrigin based on panning
|
||||
const { velocity } = this.panning;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user