Moved the addVelocity method after the transform to allow a modification of the delta within the transform method. To make this destructive side effect more explicit transform could return a modified value. But that could effect several projects.
This commit is contained in:
parent
266a770c8e
commit
eff934e8b5
@ -44,8 +44,7 @@ const END = 'onEnd'
|
|||||||
*/
|
*/
|
||||||
export class ScatterEvent extends BaseEvent {
|
export class ScatterEvent extends BaseEvent {
|
||||||
constructor(
|
constructor(
|
||||||
target,
|
target, { translate = { x: 0, y: 0 }, scale = null, rotate = 0, about = null, fast = false, type = null } = {}
|
||||||
{ translate = { x: 0, y: 0 }, scale = null, rotate = 0, about = null, fast = false, type = null } = {}
|
|
||||||
) {
|
) {
|
||||||
super('scatterTransformed', { target: target })
|
super('scatterTransformed', { target: target })
|
||||||
this.translate = translate
|
this.translate = translate
|
||||||
@ -106,7 +105,7 @@ class Throwable {
|
|||||||
this.velocity = null
|
this.velocity = null
|
||||||
this.timestamp = null
|
this.timestamp = null
|
||||||
this.onThrowFinished = onThrowFinished
|
this.onThrowFinished = onThrowFinished
|
||||||
//console.log("onThrowFinished", onThrowFinished)
|
//console.log("onThrowFinished", onThrowFinished)
|
||||||
}
|
}
|
||||||
|
|
||||||
observeVelocity() {
|
observeVelocity() {
|
||||||
@ -184,7 +183,7 @@ class Throwable {
|
|||||||
animateThrow(time) {
|
animateThrow(time) {
|
||||||
if (this.velocity != null) {
|
if (this.velocity != null) {
|
||||||
let dt = this._throwDeltaTime()
|
let dt = this._throwDeltaTime()
|
||||||
// console.log("animateThrow", dt)
|
// console.log("animateThrow", dt)
|
||||||
let next = this.nextVelocity(this.velocity)
|
let next = this.nextVelocity(this.velocity)
|
||||||
let prevLength = Points.length(this.velocity)
|
let prevLength = Points.length(this.velocity)
|
||||||
let nextLength = Points.length(next)
|
let nextLength = Points.length(next)
|
||||||
@ -382,7 +381,7 @@ export class AbstractScatter extends Throwable {
|
|||||||
let delta = interaction.delta()
|
let delta = interaction.delta()
|
||||||
|
|
||||||
if (delta != null) {
|
if (delta != null) {
|
||||||
this.addVelocity(delta) // uo: reverted commit fa0256d782dd498c6d3e51321260ca375ca9f855
|
|
||||||
let rotate = delta.rotate
|
let rotate = delta.rotate
|
||||||
let zoom = delta.zoom
|
let zoom = delta.zoom
|
||||||
if (this.maxRotation != null) {
|
if (this.maxRotation != null) {
|
||||||
@ -403,6 +402,8 @@ export class AbstractScatter extends Throwable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.transform(delta, zoom, rotate, delta.about)
|
this.transform(delta, zoom, rotate, delta.about)
|
||||||
|
this.addVelocity(delta) // uo: reverted commit fa0256d782dd498c6d3e51321260ca375ca9f855
|
||||||
|
|
||||||
if (zoom != 1) this.interactionAnchor = delta.about
|
if (zoom != 1) this.interactionAnchor = delta.about
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -467,8 +468,8 @@ export class AbstractScatter extends Throwable {
|
|||||||
|
|
||||||
keepOnStage(velocity, collision = 0.5) {
|
keepOnStage(velocity, collision = 0.5) {
|
||||||
let stagePolygon = this.containerPolygon
|
let stagePolygon = this.containerPolygon
|
||||||
// UO: since keepOnStage is called in nextVelocity we need to
|
// UO: since keepOnStage is called in nextVelocity we need to
|
||||||
// ensure a return value
|
// ensure a return value
|
||||||
if (!stagePolygon) return { x: 0, y: 0 }
|
if (!stagePolygon) return { x: 0, y: 0 }
|
||||||
let polygon = this.polygon
|
let polygon = this.polygon
|
||||||
let bounced = this.bouncing()
|
let bounced = this.bouncing()
|
||||||
@ -479,7 +480,7 @@ export class AbstractScatter extends Throwable {
|
|||||||
let dx = this.movableX ? velocity.x : 0
|
let dx = this.movableX ? velocity.x : 0
|
||||||
let dy = this.movableY ? velocity.y : 0
|
let dy = this.movableY ? velocity.y : 0
|
||||||
let factor = this.throwDamping
|
let factor = this.throwDamping
|
||||||
// if (recentered) {
|
// if (recentered) {
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
dx = -dx
|
dx = -dx
|
||||||
factor = collision
|
factor = collision
|
||||||
@ -515,10 +516,10 @@ export class AbstractScatter extends Throwable {
|
|||||||
onComplete: this.close.bind(this)
|
onComplete: this.close.bind(this)
|
||||||
})
|
})
|
||||||
} else if (this.scale < this.minScale + this.scaleCloseThreshold) {
|
} else if (this.scale < this.minScale + this.scaleCloseThreshold) {
|
||||||
this.zoom(this.minScale + this.scaleCloseThreshold, {
|
this.zoom(this.minScale + this.scaleCloseThreshold, {
|
||||||
animate: 0.4
|
animate: 0.4
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rotateDegrees(degrees, anchor) {
|
rotateDegrees(degrees, anchor) {
|
||||||
@ -621,7 +622,7 @@ export class AbstractScatter extends Throwable {
|
|||||||
let newOrigin = Points.arc(anchor, beta + rotate, distance * thresholdedZoom)
|
let newOrigin = Points.arc(anchor, beta + rotate, distance * thresholdedZoom)
|
||||||
let extra = Points.subtract(newOrigin, origin)
|
let extra = Points.subtract(newOrigin, origin)
|
||||||
const anchorOffset = Points.subtract(anchor, origin)
|
const anchorOffset = Points.subtract(anchor, origin)
|
||||||
// this._move(offset)
|
// this._move(offset)
|
||||||
this.scale = newScale
|
this.scale = newScale
|
||||||
this.rotation += rotate
|
this.rotation += rotate
|
||||||
let offset = Points.negate(anchorOffset)
|
let offset = Points.negate(anchorOffset)
|
||||||
@ -911,8 +912,7 @@ export class DOMScatterContainer {
|
|||||||
* @param {DOM node} debugCanvas - Shows debug infos about touches if not null
|
* @param {DOM node} debugCanvas - Shows debug infos about touches if not null
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
element,
|
element, {
|
||||||
{
|
|
||||||
stopEvents = 'auto',
|
stopEvents = 'auto',
|
||||||
claimEvents = true,
|
claimEvents = true,
|
||||||
useCapture = true,
|
useCapture = true,
|
||||||
@ -1076,8 +1076,7 @@ export class DOMScatterContainer {
|
|||||||
export class DOMScatter extends AbstractScatter {
|
export class DOMScatter extends AbstractScatter {
|
||||||
constructor(
|
constructor(
|
||||||
element,
|
element,
|
||||||
container,
|
container, {
|
||||||
{
|
|
||||||
startScale = 1.0,
|
startScale = 1.0,
|
||||||
minScale = 0.1,
|
minScale = 0.1,
|
||||||
maxScale = 1.0,
|
maxScale = 1.0,
|
||||||
@ -1274,10 +1273,10 @@ export class DOMScatter extends AbstractScatter {
|
|||||||
let r = this.bounds
|
let r = this.bounds
|
||||||
let w2 = r.width / 2
|
let w2 = r.width / 2
|
||||||
let h2 = r.height / 2
|
let h2 = r.height / 2
|
||||||
// if (this.resizable) {
|
// if (this.resizable) {
|
||||||
// w2 *= this.scale
|
// w2 *= this.scale
|
||||||
// h2 *= this.scale
|
// h2 *= this.scale
|
||||||
// }
|
// }
|
||||||
var x = r.left + w2
|
var x = r.left + w2
|
||||||
var y = r.top + h2
|
var y = r.top + h2
|
||||||
return { x, y }
|
return { x, y }
|
||||||
@ -1397,7 +1396,7 @@ export class DOMScatter extends AbstractScatter {
|
|||||||
}
|
}
|
||||||
this._x = x
|
this._x = x
|
||||||
this._y = y
|
this._y = y
|
||||||
// this.addVelocity({ x: delta.x, y: delta.y }) uo: reverted commit fa0256d782dd498c6d3e51321260ca375ca9f855
|
// this.addVelocity({ x: delta.x, y: delta.y }) uo: reverted commit fa0256d782dd498c6d3e51321260ca375ca9f855
|
||||||
TweenLite.set(this.element, { x, y })
|
TweenLite.set(this.element, { x, y })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user