Skip to content

Commit e7465bb

Browse files
committed
Added start of the transformed point functions
1 parent 3daafa7 commit e7465bb

4 files changed

Lines changed: 61 additions & 1 deletion

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '214dcc80-5097-11e7-9900-0395e9b33639'
2+
build: '927d4eb0-509e-11e7-8474-0fbd363270fe'
33
};
44
module.exports = CHECKSUM;

v3/src/input/GlobalInputManager.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ var Keyboard = require('./keyboard/KeyboardManager');
44
var Mouse = require('./mouse/MouseManager');
55
var MouseEvent = require('./mouse/events/');
66
var EventDispatcher = require('../events/EventDispatcher');
7+
var GetTransformedPoint = require('./components/GetTransformedPoint');
8+
var PointWithinGameObject = require('./components/PointWithinGameObject');
9+
var TransformMatrix = require('../components/TransformMatrix');
710

811
var GlobalInputManager = function (game, gameConfig)
912
{
@@ -21,6 +24,9 @@ var GlobalInputManager = function (game, gameConfig)
2124
// Listeners
2225
this.keyboard = new Keyboard(this);
2326
this.mouse = new Mouse(this);
27+
28+
this._tempMatrix = new TransformMatrix();
29+
this._tempPoint = { x: 0, y: 0 };
2430
};
2531

2632
GlobalInputManager.prototype.constructor = GlobalInputManager;
@@ -75,6 +81,16 @@ GlobalInputManager.prototype = {
7581
break;
7682
}
7783
}
84+
},
85+
86+
getTransformedPoint: function (gameObject, x, y)
87+
{
88+
return GetTransformedPoint(this._tempMatrix, gameObject, x, y, this._tempPoint);
89+
},
90+
91+
pointWithinGameObject: function (gameObject, x, y)
92+
{
93+
return PointWithinGameObject(gameObject, x, y);
7894
}
7995

8096
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* This will return the local coordinates of the specified displayObject based on the given Pointer.
3+
*
4+
* @method Phaser.Input#getLocalPosition
5+
* @param {Phaser.Sprite|Phaser.Image} gameObject - The DisplayObject to get the local coordinates for.
6+
* @param {Phaser.Pointer} pointer - The Pointer to use in the check against the gameObject.
7+
* @return {Phaser.Point} A point containing the coordinates of the Pointer position relative to the DisplayObject.
8+
*/
9+
var GetTransformedPoint = function (matrix, gameObject, x, y, output)
10+
{
11+
if (output === undefined) { output = { x: 0, y: 0 }; }
12+
13+
matrix.applyITRS(gameObject.x, gameObject.y, gameObject.rotation, gameObject.scaleX, gameObject.scaleY);
14+
15+
var a = matrix.matrix[0];
16+
var b = matrix.matrix[1];
17+
var c = matrix.matrix[2];
18+
var d = matrix.matrix[3];
19+
var tx = matrix.matrix[4];
20+
var ty = matrix.matrix[5];
21+
22+
var id = 1 / (a * d + c * -b);
23+
24+
output.x = d * id * x + -c * id * y + (ty * c - tx * d) * id;
25+
output.y = a * id * y + -b * id * x + (-ty * a + tx * b) * id;
26+
27+
return output;
28+
};
29+
30+
module.exports = GetTransformedPoint;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// x/y MUST be translated before being passed to this function, unless the gameObject is guarnateed to
2+
// be not rotated or scaled in any way
3+
4+
var PointWithinGameObject = function (gameObject, x, y)
5+
{
6+
var width = gameObject.width;
7+
var height = gameObject.height;
8+
var x1 = -width * gameObject.originX;
9+
var y1 = -height * gameObject.originY;
10+
11+
return (x >= x1 && x < x1 + width && y >= y1 && y < y1 + height);
12+
};
13+
14+
module.exports = PointWithinGameObject;

0 commit comments

Comments
 (0)