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