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.sim.playing = false;
|
||||||
this.paused = true;
|
this.paused = true;
|
||||||
if (this.sim.pointer.panning?.velocity) {
|
if (this.sim.pointer.panning?.velocity) {
|
||||||
this.panVelocityPaused = {...this.sim.pointer.panning.velocity};
|
this.sim.pointer.panning.paused = true;
|
||||||
this.sim.pointer.panning = undefined;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -32,11 +31,8 @@ export class Objects {
|
|||||||
if (this.paused) {
|
if (this.paused) {
|
||||||
this.sim.playing = true;
|
this.sim.playing = true;
|
||||||
this.paused = false;
|
this.paused = false;
|
||||||
if (this.panVelocityPaused) {
|
if (this.sim.pointer.panning?.paused) {
|
||||||
this.sim.pointer.panning = {
|
this.sim.pointer.panning.paused = false;
|
||||||
velocity: {...this.panVelocityPaused},
|
|
||||||
};
|
|
||||||
this.panVelocityPaused = undefined;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -48,10 +44,13 @@ export class Objects {
|
|||||||
this.creatingObject = idx;
|
this.creatingObject = idx;
|
||||||
this.objects.push(obj);
|
this.objects.push(obj);
|
||||||
// Pause the simulation during mass creation; this avoids some complex local dynamics
|
// 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')) {
|
if (this.sim.getOption('pauseDuring.creation')) {
|
||||||
this.pause();
|
this.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.sim.pointer.panning?.velocity) {
|
||||||
|
obj.velocity = {...this.sim.pointer.panning.velocity};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
doneCreatingObject() {
|
doneCreatingObject() {
|
||||||
|
|||||||
@ -133,7 +133,6 @@ export class Pointer {
|
|||||||
handlePointerDown({x: clientX, y: clientY}) {
|
handlePointerDown({x: clientX, y: clientY}) {
|
||||||
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)) {
|
||||||
// this.panning = undefined;
|
|
||||||
const {x, y} = this.sim.screenToSim(clientX, clientY)
|
const {x, y} = this.sim.screenToSim(clientX, clientY)
|
||||||
this.sim.objects.handlePointerDown({x, y});
|
this.sim.objects.handlePointerDown({x, y});
|
||||||
|
|
||||||
@ -191,7 +190,7 @@ export class Pointer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Apply update to viewOrigin based on panning
|
// Apply update to viewOrigin based on panning
|
||||||
if (this.panning) {
|
if (this.panning && !this.panning.paused) {
|
||||||
const {velocity} = this.panning;
|
const {velocity} = this.panning;
|
||||||
// Convert pointer velocity to sim internal scale
|
// Convert pointer velocity to sim internal scale
|
||||||
this.sim.display.viewOrigin.x -= velocity.x * elapsedTime;
|
this.sim.display.viewOrigin.x -= velocity.x * elapsedTime;
|
||||||
|
|||||||
@ -82,9 +82,6 @@ export class Sim {
|
|||||||
this.pointer.clearPointerHistory();
|
this.pointer.clearPointerHistory();
|
||||||
|
|
||||||
if (this.playing && velocity) {
|
if (this.playing && velocity) {
|
||||||
// Switch to pan mode
|
|
||||||
this.setCurrentMode(MODE_PAN_VIEW);
|
|
||||||
|
|
||||||
this.pointer.panning = {
|
this.pointer.panning = {
|
||||||
velocity: {
|
velocity: {
|
||||||
x: -velocity.x,
|
x: -velocity.x,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user