pointer history size
This commit is contained in:
parent
25796a5ec3
commit
1da0be3657
@ -29,7 +29,7 @@ export const PATH_TRACES_DASHED_OPACITY = 1.0;
|
||||
|
||||
// SCALING FACTORS
|
||||
export const MASS_CREATION_RATE = 1E1;
|
||||
export const POINTER_HISTORY_SIZE = 15;
|
||||
export const POINTER_HISTORY_SIZE = 10;
|
||||
export const MOTION_TIME_SCALE = 1E-4;
|
||||
export const PAN_ACCELERATION = 1E1;
|
||||
export const ARROWHEAD_LENGTH = 7;
|
||||
|
||||
12
objects.js
12
objects.js
@ -143,17 +143,17 @@ export class Objects {
|
||||
handlePointerMove({x, y, vx, vy}) {
|
||||
// If the cursor moves while creating an object, or while an object is selected,
|
||||
// update the position and velocity of the object
|
||||
// update the position using the pointer motion but the velocity using the pointer velocity
|
||||
const obj = this.getSelectedOrCreating();
|
||||
if (obj === undefined) return;
|
||||
if (this.sim.pointer.panning?.velocity) {
|
||||
vx += this.sim.pointer.panning.velocity.x;
|
||||
vy += this.sim.pointer.panning.velocity.y;
|
||||
}
|
||||
if (obj !== undefined) {
|
||||
obj.position.x = x;
|
||||
obj.position.y = y;
|
||||
obj.velocity.x = vx;
|
||||
obj.velocity.y = vy;
|
||||
}
|
||||
obj.position.x = x;
|
||||
obj.position.y = y;
|
||||
obj.velocity.x = vx;
|
||||
obj.velocity.y = vy;
|
||||
}
|
||||
|
||||
// cb: (obj, idx) => {}
|
||||
|
||||
@ -59,12 +59,12 @@ export class Pointer {
|
||||
});
|
||||
}
|
||||
|
||||
getPointerVelocity(points) {
|
||||
getPointerVelocity(points = POINTER_HISTORY_SIZE) {
|
||||
// Average over pointer history
|
||||
if (this.pointerHistory.length < 2) {
|
||||
return {x: 0, y: 0, dt: 1};
|
||||
}
|
||||
points = points || this.pointerHistory.length;
|
||||
points = Math.min(points, POINTER_HISTORY_SIZE, this.pointerHistory.length);
|
||||
const start = this.pointerHistory[this.pointerHistory.length - points];
|
||||
const end = this.pointerHistory[this.pointerHistory.length - 1];
|
||||
const dt = (end.t - start.t) / 1000;
|
||||
@ -122,7 +122,7 @@ export class Pointer {
|
||||
if (!dt) {
|
||||
this.panning = undefined;
|
||||
} else {
|
||||
const v = this.getPointerVelocity(10);
|
||||
const v = this.getPointerVelocity();
|
||||
// Convert pointer velocity to simulation scale
|
||||
v.x /= this.sim.display.scale;
|
||||
v.y /= this.sim.display.scale;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user