Skip to content

Commit e459729

Browse files
committed
Function now takes x and y values directly instead of via a point. Returns vector2 if not defined.
1 parent 2405027 commit e459729

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

v3/src/camera/2d/inc/GetWorldPoint.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
var Vector2 = require('../../../math/Vector2');
22

3-
var GetWorldPoint = function (screenPoint, output)
3+
var GetWorldPoint = function (x, y, output)
44
{
5+
if (output === undefined) { output = new Vector2(); }
6+
57
var cameraMatrix = this.matrix.matrix;
8+
69
var mva = cameraMatrix[0];
710
var mvb = cameraMatrix[1];
811
var mvc = cameraMatrix[2];
@@ -15,7 +18,10 @@ var GetWorldPoint = function (screenPoint, output)
1518

1619
if (!determinant)
1720
{
18-
return screenPoint;
21+
output.x = x;
22+
output.y = y;
23+
24+
return output;
1925
}
2026

2127
determinant = 1 / determinant;
@@ -26,22 +32,21 @@ var GetWorldPoint = function (screenPoint, output)
2632
var imd = mva * determinant;
2733
var ime = (mvc * mvf - mvd * mve) * determinant;
2834
var imf = (mvb * mve - mva * mvf) * determinant;
35+
2936
var c = Math.cos(this.rotation);
3037
var s = Math.sin(this.rotation);
38+
3139
var zoom = this.zoom;
40+
3241
var scrollX = this.scrollX;
3342
var scrollY = this.scrollY;
34-
var x = screenPoint.x + ((scrollX * c - scrollY * s) * zoom);
35-
var y = screenPoint.y + ((scrollX * s + scrollY * c) * zoom);
3643

37-
if (!output)
38-
{
39-
output = new Vector2();
40-
}
44+
var sx = x + ((scrollX * c - scrollY * s) * zoom);
45+
var sy = y + ((scrollX * s + scrollY * c) * zoom);
4146

4247
/* Apply transform to point */
43-
output.x = (x * ima + y * imc + ime);
44-
output.y = (x * imb + y * imd + imf);
48+
output.x = (sx * ima + sy * imc + ime);
49+
output.y = (sx * imb + sy * imd + imf);
4550

4651
return output;
4752
};

v3/src/input/Pointer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var Pointer = new Class({
8181

8282
positionToCamera: function (camera, output)
8383
{
84-
return camera.getWorldPoint(this.position, output);
84+
return camera.getWorldPoint(this.x, this.y, output);
8585
},
8686

8787
x: {

v3/src/physics/matter-js/PointerConstraint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ var PointerConstraint = new Class({
129129
{
130130
var pos = this.position;
131131

132-
this.camera.getWorldPoint(pointer.position, pos);
132+
this.camera.getWorldPoint(pointer.x, pointer.y, pos);
133133

134134
if (constraint.bodyB)
135135
{

0 commit comments

Comments
 (0)