inconsequential tweaks
This commit is contained in:
parent
213525c3dd
commit
7796b96226
28
pointer.js
28
pointer.js
@ -113,8 +113,8 @@ export class Pointer {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
clearPointerHistory() {
|
clearPointerHistory(keep = 0) {
|
||||||
this.pointerHistory = [];
|
this.pointerHistory.splice(0, this.pointerHistory.length - keep)
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePointer({x, y}) {
|
updatePointer({x, y}) {
|
||||||
@ -122,12 +122,13 @@ export class Pointer {
|
|||||||
while (this.pointerHistory.length >= POINTER_HISTORY_SIZE) {
|
while (this.pointerHistory.length >= POINTER_HISTORY_SIZE) {
|
||||||
this.pointerHistory.shift();
|
this.pointerHistory.shift();
|
||||||
}
|
}
|
||||||
// const v = this.getPointerVelocity();
|
const v = this.getPointerVelocity();
|
||||||
// const a = this.getPointerAcceleration();
|
// const a = this.getPointerAcceleration();
|
||||||
this.pointerHistory.push({t, x, y});
|
this.pointerHistory.push({t, x, y, v});
|
||||||
}
|
}
|
||||||
|
|
||||||
handlePointerDown({x: clientX, y: clientY}) {
|
handlePointerDown({x: clientX, y: clientY}) {
|
||||||
|
this.clearPointerHistory(5);
|
||||||
this.updatePointer({x: clientX, y: clientY});
|
this.updatePointer({x: clientX, y: clientY});
|
||||||
if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) {
|
if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) {
|
||||||
const {x, y} = this.sim.screenToSim(clientX, clientY)
|
const {x, y} = this.sim.screenToSim(clientX, clientY)
|
||||||
@ -141,8 +142,6 @@ export class Pointer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handlePointerUp({x: clientX, y: clientY}) {
|
handlePointerUp({x: clientX, y: clientY}) {
|
||||||
this.clearPointerHistory();
|
|
||||||
|
|
||||||
if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) {
|
if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) {
|
||||||
const {x, y} = this.sim.screenToSim(clientX, clientY);
|
const {x, y} = this.sim.screenToSim(clientX, clientY);
|
||||||
this.sim.objects.handlePointerUp({x, y});
|
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
|
// TODO: If e.touches.length > 1, user may be engaging pinch to zoom
|
||||||
handlePointerMove({x: clientX, y: clientY}) {
|
handlePointerMove({x: clientX, y: clientY}) {
|
||||||
this.updatePointer({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)) {
|
if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) {
|
||||||
const {x, y} = this.sim.screenToSim(clientX, clientY);
|
const {x, y} = this.sim.screenToSim(clientX, clientY);
|
||||||
const velocity = this.getPointerVelocity();
|
|
||||||
// Convert pointer velocity to sim internal scale
|
// Convert pointer velocity to sim internal scale
|
||||||
const vx = velocity.x / this.sim.display.scale;
|
this.sim.objects.handlePointerMove({x, y, vx: v.x, vy: v.y});
|
||||||
const vy = velocity.y / this.sim.display.scale;
|
|
||||||
this.sim.objects.handlePointerMove({x, y, vx, vy});
|
|
||||||
|
|
||||||
} else if (this.sim.isCurrentMode(MODE_PAN_VIEW)) {
|
} else if (this.sim.isCurrentMode(MODE_PAN_VIEW)) {
|
||||||
if (this.panning?.gathering) {
|
if (this.panning?.gathering) {
|
||||||
const velocity = this.getPointerVelocity();
|
this.panning.velocity.x = v.x;
|
||||||
// Convet to sim coordinates
|
this.panning.velocity.y = v.x;
|
||||||
this.panning.velocity.x = velocity.x / this.sim.display.scale;
|
|
||||||
this.panning.velocity.y = velocity.y / this.sim.display.scale;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user