From 8752d47e017d9608999ef49cd9d76ac4e7b0bf16 Mon Sep 17 00:00:00 2001 From: Uwe Oestermeier Date: Fri, 31 May 2019 10:15:50 +0200 Subject: [PATCH] Fixed velocity computation in Throwable --- dist/iwmlib.js | 35 +++++++++++++++++++++++------------ dist/iwmlib.pixi.js | 35 +++++++++++++++++++++++------------ lib/scatter.js | 2 +- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/dist/iwmlib.js b/dist/iwmlib.js index 1e5704a..ebbf69a 100644 --- a/dist/iwmlib.js +++ b/dist/iwmlib.js @@ -1687,12 +1687,23 @@ } class InteractionDelta { - constructor(x, y, zoom, rotate, about) { + /** + *Creates an instance of InteractionDelta. + * @param {*} x + * @param {*} y + * @param {*} zoom + * @param {*} rotate + * @param {*} about + * @param {*} number - number of involved pointer + * @memberof InteractionDelta + */ + constructor(x, y, zoom, rotate, about, number) { this.x = x; this.y = y; this.zoom = zoom; this.rotate = rotate; this.about = about; + this.number = number; } toString() { @@ -1766,16 +1777,13 @@ let p1 = this.previous.get(c1.key); let p2 = this.previous.get(c2.key); - //let p1 = previous[0] - //let p2 = previous[1] - let d1 = Points.subtract(c1, p1); let d2 = Points.subtract(c2, p2); let cm = Points.mean(c1, c2); - //let pm = Points.mean(p1, p2) - // UO: Using the mean lead to jumps between time slices with 3 and 2 fingers + + // Using the mean leads to jumps between time slices with 3 and 2 fingers // We use the mean of deltas instead - let delta = Points.mean(d1, d2); //Points.subtract(cm, pm) + let delta = Points.mean(d1, d2); let zoom = 1.0; let distance1 = Points.distance(p1, p2); let distance2 = Points.distance(c1, c2); @@ -1785,13 +1793,14 @@ let currentAngle = Points.angle(c1, c2); let previousAngle = Points.angle(p1, p2); let alpha = this.diffAngle(currentAngle, previousAngle); - return new InteractionDelta(delta.x, delta.y, zoom, alpha, cm) + return new InteractionDelta(delta.x, delta.y, zoom, alpha, cm, csize) } else if (csize == 1 && psize == 1 && this.current.firstKey() == this.previous.firstKey()) { - // We need to ensure that the keys are the same + // We need to ensure that the keys are the same, since single points with different keys + // can jump let current = this.current.first(); let previous = this.previous.first(); let delta = Points.subtract(current, previous); - return new InteractionDelta(delta.x, delta.y, 1.0, 0.0, current) + return new InteractionDelta(delta.x, delta.y, 1.0, 0.0, current, csize) } return null } @@ -2940,7 +2949,9 @@ this.lastframe = t; if (dt > 0) { // Avoid division by zero errors later on - let velocity = { t: t, dt: dt, dx: delta.x, dy: delta.y }; + // and consider the number of involved pointers sind addVelocity will be called by the + // onMove events + let velocity = { t: t, dt: dt, dx: delta.x / delta.number, dy: delta.y / delta.number}; this.velocities.push(velocity); while (this.velocities.length > buffer) { this.velocities.shift(); @@ -2949,7 +2960,7 @@ } meanVelocity(milliseconds = 30) { - this.addVelocity({ x: 0, y: 0 }); + this.addVelocity({ x: 0, y: 0, number: 1 }); let sum = { x: 0, y: 0 }; let count = 0; let t = 0; diff --git a/dist/iwmlib.pixi.js b/dist/iwmlib.pixi.js index cbefb04..6840a1b 100644 --- a/dist/iwmlib.pixi.js +++ b/dist/iwmlib.pixi.js @@ -4851,12 +4851,23 @@ } class InteractionDelta { - constructor(x, y, zoom, rotate, about) { + /** + *Creates an instance of InteractionDelta. + * @param {*} x + * @param {*} y + * @param {*} zoom + * @param {*} rotate + * @param {*} about + * @param {*} number - number of involved pointer + * @memberof InteractionDelta + */ + constructor(x, y, zoom, rotate, about, number) { this.x = x; this.y = y; this.zoom = zoom; this.rotate = rotate; this.about = about; + this.number = number; } toString() { @@ -4930,16 +4941,13 @@ let p1 = this.previous.get(c1.key); let p2 = this.previous.get(c2.key); - //let p1 = previous[0] - //let p2 = previous[1] - let d1 = Points.subtract(c1, p1); let d2 = Points.subtract(c2, p2); let cm = Points.mean(c1, c2); - //let pm = Points.mean(p1, p2) - // UO: Using the mean lead to jumps between time slices with 3 and 2 fingers + + // Using the mean leads to jumps between time slices with 3 and 2 fingers // We use the mean of deltas instead - let delta = Points.mean(d1, d2); //Points.subtract(cm, pm) + let delta = Points.mean(d1, d2); let zoom = 1.0; let distance1 = Points.distance(p1, p2); let distance2 = Points.distance(c1, c2); @@ -4949,13 +4957,14 @@ let currentAngle = Points.angle(c1, c2); let previousAngle = Points.angle(p1, p2); let alpha = this.diffAngle(currentAngle, previousAngle); - return new InteractionDelta(delta.x, delta.y, zoom, alpha, cm) + return new InteractionDelta(delta.x, delta.y, zoom, alpha, cm, csize) } else if (csize == 1 && psize == 1 && this.current.firstKey() == this.previous.firstKey()) { - // We need to ensure that the keys are the same + // We need to ensure that the keys are the same, since single points with different keys + // can jump let current = this.current.first(); let previous = this.previous.first(); let delta = Points.subtract(current, previous); - return new InteractionDelta(delta.x, delta.y, 1.0, 0.0, current) + return new InteractionDelta(delta.x, delta.y, 1.0, 0.0, current, csize) } return null } @@ -6104,7 +6113,9 @@ this.lastframe = t; if (dt > 0) { // Avoid division by zero errors later on - let velocity = { t: t, dt: dt, dx: delta.x, dy: delta.y }; + // and consider the number of involved pointers sind addVelocity will be called by the + // onMove events + let velocity = { t: t, dt: dt, dx: delta.x / delta.number, dy: delta.y / delta.number}; this.velocities.push(velocity); while (this.velocities.length > buffer) { this.velocities.shift(); @@ -6113,7 +6124,7 @@ } meanVelocity(milliseconds = 30) { - this.addVelocity({ x: 0, y: 0 }); + this.addVelocity({ x: 0, y: 0, number: 1 }); let sum = { x: 0, y: 0 }; let count = 0; let t = 0; diff --git a/lib/scatter.js b/lib/scatter.js index c575217..168a6e2 100644 --- a/lib/scatter.js +++ b/lib/scatter.js @@ -138,7 +138,7 @@ class Throwable { } meanVelocity(milliseconds = 30) { - this.addVelocity({ x: 0, y: 0 }) + this.addVelocity({ x: 0, y: 0, number: 1 }) let sum = { x: 0, y: 0 } let count = 0 let t = 0