Skip to content

Commit d596fbd

Browse files
committed
Added distance property.
1 parent f6efccb commit d596fbd

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

src/input/Pointer.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ var Pointer = new Class({
158158
*/
159159
this.angle = new Vector2();
160160

161+
this.distance = 0;
162+
163+
164+
161165
/**
162166
* The smoothing factor to apply to the Pointer position.
163167
*
@@ -477,15 +481,12 @@ var Pointer = new Class({
477481
*/
478482
updateMotion: function ()
479483
{
480-
var px = this.midPoint.x;
481-
var py = this.midPoint.y;
482-
483484
var cx = this.position.x;
484485
var cy = this.position.y;
485486

486487
// Moving towards our goal ...
487-
var vx = SmoothStepInterpolation(this.motionFactor, px, cx);
488-
var vy = SmoothStepInterpolation(this.motionFactor, py, cy);
488+
var vx = SmoothStepInterpolation(this.motionFactor, this.midPoint.x, cx);
489+
var vy = SmoothStepInterpolation(this.motionFactor, this.midPoint.y, cy);
489490

490491
if (FuzzyEqual(vx, cx, 0.1))
491492
{
@@ -499,9 +500,14 @@ var Pointer = new Class({
499500

500501
this.midPoint.set(vx, vy);
501502

502-
this.velocity.set(cx - vx, cy - vy);
503+
var dx = cx - vx;
504+
var dy = cy - vy;
505+
506+
this.velocity.set(dx, dy);
507+
508+
this.angle = Math.atan2(dy, dx);
503509

504-
this.angle = Math.atan2(cy - vy, cx - vx);
510+
this.distance = Math.sqrt(dx * dx + dy * dy);
505511
},
506512

507513
/**

0 commit comments

Comments
 (0)