fixup panning
This commit is contained in:
parent
f53a82f594
commit
bfaa2b2437
21
object.js
21
object.js
@ -174,17 +174,28 @@ export class MassObject {
|
||||
if (sim.getOption('display.velocity')) {
|
||||
// If this object is being dragged by the user,
|
||||
// show the pointer velocity instead of object velocity
|
||||
const vecScale = this.sim.getOption('param.velocityScale');
|
||||
const vecScale = this.sim.getOption('display.velocityScale');
|
||||
const selected = this.sim.system.getSelectedOrCreating();
|
||||
const velocity = selected?.id === this.id ?
|
||||
this.sim.pointer.latestVelocity ?? {x: 0, y: 0} :
|
||||
{x: vx, y: vy};
|
||||
const isSelected = selected?.id === this.id;
|
||||
let velocity = {x: vx, y: vy};
|
||||
if (isSelected) {
|
||||
const pointerV = this.sim.pointer.latestVelocity;
|
||||
const scale = this.sim.display.scale;
|
||||
// const panning = this.sim.panning?.velocity ?? {x: 0, y: 0};
|
||||
// velocity.x = vx + (pointerV.x + panning.x) * scale;
|
||||
// velocity.y = vy + (pointerV.y + panning.y) * scale;
|
||||
velocity.x = vx + pointerV.x * scale;
|
||||
velocity.y = vy + pointerV.y * scale;
|
||||
}
|
||||
const speed = Math.sqrt(velocity.x ** 2, velocity.y ** 2);
|
||||
const arrowDirection = Math.atan2(velocity.y, velocity.x);
|
||||
// Prevent negative numbers by adding 1
|
||||
const arrowLength = Math.log(speed + 1) * vecScale / this.sim.display.scale;
|
||||
const arrowLength = Math.log(speed + 1) * vecScale;
|
||||
const endVx = x + arrowLength * Math.cos(arrowDirection);
|
||||
const endVy = y + arrowLength * Math.sin(arrowDirection);
|
||||
if (sim.getOption('debug.panningInfo')) {
|
||||
console.log('velocity', {vecScale, isSelected, velocity, speed, arrowDirection, arrowLength, endVx, endVy});
|
||||
}
|
||||
const style = VELOCITY_VECTOR_COLOR === 'object color' ?
|
||||
`rgb(${r}, ${g}, ${b})` : VELOCITY_VECTOR_COLOR;
|
||||
sim.display.drawArrow(x, y, endVx, endVy, {
|
||||
|
||||
@ -157,8 +157,8 @@ export class System {
|
||||
// Convert pointer velocity to simulation scale
|
||||
// Including time scale - if time is slow, our motion is relatively faster
|
||||
const pointer = {...this.sim.pointer.latestVelocity};
|
||||
obj.velocity.x = pointer.x / this.sim.display.scale / this.sim.timeScale;
|
||||
obj.velocity.y = pointer.y / this.sim.display.scale / this.sim.timeScale;
|
||||
obj.velocity.x = pointer.x / this.sim.display.scale;
|
||||
obj.velocity.y = pointer.y / this.sim.display.scale;
|
||||
if (this.sim.panning?.velocity) {
|
||||
obj.velocity.x += this.sim.panning.velocity.x;
|
||||
obj.velocity.y += this.sim.panning.velocity.y;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user