Skip to content

Commit 730c6b5

Browse files
committed
Input updates
1 parent fb33be2 commit 730c6b5

4 files changed

Lines changed: 78 additions & 15 deletions

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: '51369a60-5161-11e7-bea9-fdb861265841'
2+
build: '531e9860-521e-11e7-914d-2dba089add27'
33
};
44
module.exports = CHECKSUM;

v3/src/components/TransformMatrix.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,47 @@ TransformMatrix.prototype.transform = function (a, b, c, d, tx, ty)
113113
return this;
114114
};
115115

116+
TransformMatrix.prototype.transformPoint = function (x, y, point)
117+
{
118+
if (point === undefined) { point = { x: 0, y: 0 }; }
119+
120+
var matrix = this.matrix;
121+
122+
var a = matrix[0];
123+
var b = matrix[1];
124+
var c = matrix[2];
125+
var d = matrix[3];
126+
var tx = matrix[4];
127+
var ty = matrix[5];
128+
129+
point.x = x * a + y * c + tx;
130+
point.y = x * b + y * d + ty;
131+
132+
return point;
133+
};
134+
135+
TransformMatrix.prototype.invert = function ()
136+
{
137+
var matrix = this.matrix;
138+
139+
var a1 = matrix[0];
140+
var b1 = matrix[1];
141+
var c1 = matrix[2];
142+
var d1 = matrix[3];
143+
var tx1 = matrix[4];
144+
var ty1 = matrix[5];
145+
var n = a1 * d1 - b1 * c1;
146+
147+
matrix[0] = d1 / n;
148+
matrix[1] = -b1 / n;
149+
matrix[2] = -c1 / n;
150+
matrix[3] = a1 / n;
151+
matrix[4] = (c1 * ty1 - d1 * tx1) / n;
152+
matrix[5] = -(a1 * ty1 - b1 * tx1) / n;
153+
154+
return this;
155+
};
156+
116157
TransformMatrix.prototype.setTransform = function (a, b, c, d, tx, ty)
117158
{
118159
var matrix = this.matrix;

v3/src/input/components/GetTransformedPoint.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,28 @@ var GetTransformedPoint = function (matrix, gameObject, x, y, output)
1111
if (output === undefined) { output = { x: 0, y: 0 }; }
1212

1313
matrix.applyITRS(gameObject.x, gameObject.y, gameObject.rotation, gameObject.scaleX, gameObject.scaleY);
14+
matrix.invert();
15+
matrix.transformPoint(x, y, output);
1416

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];
17+
// var a = matrix.matrix[0];
18+
// var b = matrix.matrix[1];
19+
// var c = matrix.matrix[2];
20+
// var d = matrix.matrix[3];
21+
// var tx = matrix.matrix[4];
22+
// var ty = matrix.matrix[5];
2123

22-
var id = 1 / (a * d + c * -b);
24+
// Apply inverse of the matrix
2325

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+
// var id = 1 / ((a * d) + (c * -b));
27+
28+
// output.x = (d * id * x) + (-c * id * y) + (((ty * c) - (tx * d)) * id);
29+
// output.y = (a * id * y) + (-b * id * x) + (((-ty * a) + (tx * b)) * id);
30+
31+
// x -= tx;
32+
// y -= ty;
33+
34+
// output.x = (a * x) + (c * y) + tx;
35+
// output.y = (b * x) + (d * y) + ty;
2636

2737
return output;
2838
};

v3/src/input/components/PointWithinGameObject.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@
33

44
var PointWithinGameObject = function (gameObject, x, y)
55
{
6-
var width = gameObject.width;
7-
var height = gameObject.height;
8-
var x1 = -width * gameObject.originX;
9-
var y1 = -height * gameObject.originY;
6+
// var width = gameObject.width;
7+
// var height = gameObject.height;
8+
// var x1 = -width * gameObject.originX;
9+
10+
// if (x >= x1 && x < x1 + width)
11+
// {
12+
// var y1 = -height * gameObject.originY;
13+
14+
// if (y >= y1 && y < y1 + height)
15+
// {
16+
// return true;
17+
// }
18+
// }
19+
20+
// return false;
21+
22+
return (x >= gameObject.x && x <= gameObject.x+gameObject.width && y >= gameObject.y && y <= gameObject.y+gameObject.height);
1023

11-
return (x >= x1 && x < x1 + width && y >= y1 && y < y1 + height);
1224
};
1325

1426
module.exports = PointWithinGameObject;

0 commit comments

Comments
 (0)