Fixed throwing problems with 2+ pointers

This commit is contained in:
Uwe Oestermeier 2019-05-31 09:51:01 +02:00
parent d114edc1e2
commit d0d3a7f134
2 changed files with 17 additions and 4 deletions

View File

@ -122,12 +122,23 @@ export class PointMap extends MapProxy {
} }
export class InteractionDelta { export 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.x = x
this.y = y this.y = y
this.zoom = zoom this.zoom = zoom
this.rotate = rotate this.rotate = rotate
this.about = about this.about = about
this.number = number
} }
toString() { toString() {
@ -217,14 +228,14 @@ export class InteractionPoints {
let currentAngle = Points.angle(c1, c2) let currentAngle = Points.angle(c1, c2)
let previousAngle = Points.angle(p1, p2) let previousAngle = Points.angle(p1, p2)
let alpha = this.diffAngle(currentAngle, previousAngle) 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()) { } else if (csize == 1 && psize == 1 && this.current.firstKey() == this.previous.firstKey()) {
// We need to ensure that the keys are the same, since single points with different keys // We need to ensure that the keys are the same, since single points with different keys
// can jump // can jump
let current = this.current.first() let current = this.current.first()
let previous = this.previous.first() let previous = this.previous.first()
let delta = Points.subtract(current, previous) 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 return null
} }

View File

@ -127,7 +127,9 @@ class Throwable {
this.lastframe = t this.lastframe = t
if (dt > 0) { if (dt > 0) {
// Avoid division by zero errors later on // 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) this.velocities.push(velocity)
while (this.velocities.length > buffer) { while (this.velocities.length > buffer) {
this.velocities.shift() this.velocities.shift()