mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Merge pull request #159 from hexagonhexagon/better-mouse-drag
Fix camera inertia problem with mouse movement
This commit is contained in:
commit
3dca35ded4
@ -28,6 +28,7 @@ const velocitySmoothing = 0.5;
|
|||||||
const velocityFade = 0.98;
|
const velocityFade = 0.98;
|
||||||
const velocityStrength = 0.4;
|
const velocityStrength = 0.4;
|
||||||
const velocityMax = 20;
|
const velocityMax = 20;
|
||||||
|
const ticksBeforeErasingVelocity = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
@ -58,6 +59,8 @@ export class Camera extends BasicSerializableObject {
|
|||||||
// Input handling
|
// Input handling
|
||||||
this.currentlyMoving = false;
|
this.currentlyMoving = false;
|
||||||
this.lastMovingPosition = null;
|
this.lastMovingPosition = null;
|
||||||
|
this.lastMovingPositionLastTick = null;
|
||||||
|
this.numTicksStandingStill = null;
|
||||||
this.cameraUpdateTimeBucket = 0.0;
|
this.cameraUpdateTimeBucket = 0.0;
|
||||||
this.didMoveSinceTouchStart = false;
|
this.didMoveSinceTouchStart = false;
|
||||||
this.currentlyPinching = false;
|
this.currentlyPinching = false;
|
||||||
@ -667,6 +670,8 @@ export class Camera extends BasicSerializableObject {
|
|||||||
this.touchPostMoveVelocity = new Vector(0, 0);
|
this.touchPostMoveVelocity = new Vector(0, 0);
|
||||||
this.currentlyMoving = true;
|
this.currentlyMoving = true;
|
||||||
this.lastMovingPosition = pos;
|
this.lastMovingPosition = pos;
|
||||||
|
this.lastMovingPositionLastTick = null;
|
||||||
|
this.numTicksStandingStill = 0;
|
||||||
this.didMoveSinceTouchStart = false;
|
this.didMoveSinceTouchStart = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,6 +721,8 @@ export class Camera extends BasicSerializableObject {
|
|||||||
this.currentlyMoving = false;
|
this.currentlyMoving = false;
|
||||||
this.currentlyPinching = false;
|
this.currentlyPinching = false;
|
||||||
this.lastMovingPosition = null;
|
this.lastMovingPosition = null;
|
||||||
|
this.lastMovingPositionLastTick = null;
|
||||||
|
this.numTicksStandingStill = 0;
|
||||||
this.lastPinchPositions = null;
|
this.lastPinchPositions = null;
|
||||||
this.userInteraction.dispatch(USER_INTERACT_TOUCHEND);
|
this.userInteraction.dispatch(USER_INTERACT_TOUCHEND);
|
||||||
this.didMoveSinceTouchStart = false;
|
this.didMoveSinceTouchStart = false;
|
||||||
@ -813,6 +820,23 @@ export class Camera extends BasicSerializableObject {
|
|||||||
|
|
||||||
this.touchPostMoveVelocity = this.touchPostMoveVelocity.multiplyScalar(velocityFade);
|
this.touchPostMoveVelocity = this.touchPostMoveVelocity.multiplyScalar(velocityFade);
|
||||||
|
|
||||||
|
// Check if the camera is being dragged but standing still: if not, zero out `touchPostMoveVelocity`.
|
||||||
|
if (this.currentlyMoving && this.desiredCenter === null) {
|
||||||
|
if (
|
||||||
|
this.lastMovingPositionLastTick !== null &&
|
||||||
|
this.lastMovingPositionLastTick.equalsEpsilon(this.lastMovingPosition)
|
||||||
|
) {
|
||||||
|
this.numTicksStandingStill++;
|
||||||
|
} else {
|
||||||
|
this.numTicksStandingStill = 0;
|
||||||
|
}
|
||||||
|
this.lastMovingPositionLastTick = this.lastMovingPosition.copy();
|
||||||
|
|
||||||
|
if (this.numTicksStandingStill >= ticksBeforeErasingVelocity) {
|
||||||
|
this.touchPostMoveVelocity.x = 0;
|
||||||
|
this.touchPostMoveVelocity.y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Check influence of past points
|
// Check influence of past points
|
||||||
if (!this.currentlyMoving && !this.currentlyPinching) {
|
if (!this.currentlyMoving && !this.currentlyPinching) {
|
||||||
const len = this.touchPostMoveVelocity.length();
|
const len = this.touchPostMoveVelocity.length();
|
||||||
|
Loading…
Reference in New Issue
Block a user