From ca34843148e66d57af1f3f7fd98d61e4439ba9f1 Mon Sep 17 00:00:00 2001 From: Ladd Date: Sat, 27 Dec 2025 20:18:00 -0600 Subject: [PATCH] smoothed out momentum at object creation --- objects.js | 15 +++++++-------- pointer.js | 3 +-- simulator.js | 3 --- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/objects.js b/objects.js index 5a37857..0bd153c 100644 --- a/objects.js +++ b/objects.js @@ -22,8 +22,7 @@ export class Objects { this.sim.playing = false; this.paused = true; if (this.sim.pointer.panning?.velocity) { - this.panVelocityPaused = {...this.sim.pointer.panning.velocity}; - this.sim.pointer.panning = undefined; + this.sim.pointer.panning.paused = true; } } } @@ -32,11 +31,8 @@ export class Objects { if (this.paused) { this.sim.playing = true; this.paused = false; - if (this.panVelocityPaused) { - this.sim.pointer.panning = { - velocity: {...this.panVelocityPaused}, - }; - this.panVelocityPaused = undefined; + if (this.sim.pointer.panning?.paused) { + this.sim.pointer.panning.paused = false; } } } @@ -48,10 +44,13 @@ export class Objects { this.creatingObject = idx; this.objects.push(obj); // Pause the simulation during mass creation; this avoids some complex local dynamics - // TODO: Make this optional (toolbar item to enable) if (this.sim.getOption('pauseDuring.creation')) { this.pause(); } + + if (this.sim.pointer.panning?.velocity) { + obj.velocity = {...this.sim.pointer.panning.velocity}; + } } doneCreatingObject() { diff --git a/pointer.js b/pointer.js index ea3d76e..752ac0d 100644 --- a/pointer.js +++ b/pointer.js @@ -133,7 +133,6 @@ export class Pointer { handlePointerDown({x: clientX, y: clientY}) { this.updatePointer({x: clientX, y: clientY}); if (this.sim.isCurrentMode(MODE_MASS_GENERATION)) { - // this.panning = undefined; const {x, y} = this.sim.screenToSim(clientX, clientY) this.sim.objects.handlePointerDown({x, y}); @@ -191,7 +190,7 @@ export class Pointer { } // Apply update to viewOrigin based on panning - if (this.panning) { + if (this.panning && !this.panning.paused) { const {velocity} = this.panning; // Convert pointer velocity to sim internal scale this.sim.display.viewOrigin.x -= velocity.x * elapsedTime; diff --git a/simulator.js b/simulator.js index 306a66e..38ff023 100644 --- a/simulator.js +++ b/simulator.js @@ -82,9 +82,6 @@ export class Sim { this.pointer.clearPointerHistory(); if (this.playing && velocity) { - // Switch to pan mode - this.setCurrentMode(MODE_PAN_VIEW); - this.pointer.panning = { velocity: { x: -velocity.x,