inconsequential tweaks

This commit is contained in:
Ladd 2025-12-27 22:21:12 -06:00
parent 213525c3dd
commit 7796b96226

View File

@ -113,8 +113,8 @@ export class Pointer {
};
}
clearPointerHistory() {
this.pointerHistory = [];
clearPointerHistory(keep = 0) {
this.pointerHistory.splice(0, this.pointerHistory.length - keep)
}
updatePointer({x, y}) {
@ -122,12 +122,13 @@ export class Pointer {
while (this.pointerHistory.length >= POINTER_HISTORY_SIZE) {
this.pointerHistory.shift();
}
// const v = this.getPointerVelocity();
const v = this.getPointerVelocity();
// const a = this.getPointerAcceleration();
this.pointerHistory.push({t, x, y});
this.pointerHistory.push({t, x, y, v});
}
handlePointerDown({x: clientX, y: clientY}) {
this.clearPointerHistory(5);
this.updatePointer({x: clientX, y: clientY});
if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) {
const {x, y} = this.sim.screenToSim(clientX, clientY)
@ -141,8 +142,6 @@ export class Pointer {
}
handlePointerUp({x: clientX, y: clientY}) {
this.clearPointerHistory();
if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) {
const {x, y} = this.sim.screenToSim(clientX, clientY);
this.sim.objects.handlePointerUp({x, y});
@ -158,20 +157,21 @@ export class Pointer {
// TODO: If e.touches.length > 1, user may be engaging pinch to zoom
handlePointerMove({x: clientX, y: clientY}) {
this.updatePointer({x: clientX, y: clientY});
const {v} = this.pointerHistory[this.pointerHistory.length - 1];
// const a = this.getPointerAcceleration();
v.x /= this.sim.display.scale;
v.y /= this.sim.display.scale;
// 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;
if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) {
const {x, y} = this.sim.screenToSim(clientX, clientY);
const velocity = this.getPointerVelocity();
// Convert pointer velocity to sim internal scale
const vx = velocity.x / this.sim.display.scale;
const vy = velocity.y / this.sim.display.scale;
this.sim.objects.handlePointerMove({x, y, vx, vy});
this.sim.objects.handlePointerMove({x, y, vx: v.x, vy: v.y});
} else if (this.sim.isCurrentMode(MODE_PAN_VIEW)) {
if (this.panning?.gathering) {
const velocity = this.getPointerVelocity();
// Convet to sim coordinates
this.panning.velocity.x = velocity.x / this.sim.display.scale;
this.panning.velocity.y = velocity.y / this.sim.display.scale;
this.panning.velocity.x = v.x;
this.panning.velocity.y = v.x;
}
}
}