smoothed out momentum at object creation
This commit is contained in:
parent
8cd706f910
commit
ca34843148
15
objects.js
15
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() {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user