PointScreenToWorldHitTest added to Global Input Manager

This commit is contained in:
Felipe Alfonso 2017-07-07 15:59:17 -04:00
parent 423326c71b
commit ebea116809
4 changed files with 69 additions and 14 deletions

View file

@ -70,6 +70,10 @@ var Camera = new Class({
for (var index = 0; index < length; ++index)
{
var object = renderableObjects[index];
/* Not every renderable object has a dimension */
if (typeof object.width === 'number')
{
var objectW = object.width;
var objectH = object.height;
var objectX = (object.x - (scrollX * object.scrollFactorX)) - (objectW * object.originX);
@ -83,6 +87,11 @@ var Camera = new Class({
culledObjects.push(object);
}
}
else
{
culledObjects.push(object);
}
}
return culledObjects;
},

View file

@ -1,6 +0,0 @@
var IntersectGameObject = function (point, gameObjectArray, camera)
{
return false;
};
module.exports = IntersectGameObject;

View file

@ -8,6 +8,7 @@ var Mouse = require('./mouse/MouseManager');
var MouseEvent = require('./mouse/events/');
var PointWithinGameObject = require('./components/PointWithinGameObject');
var TransformMatrix = require('../gameobjects/components/TransformMatrix');
var PointScreenToWorldHitTest = require('./components/PointScreenToWorldHitTest');
var GlobalInputManager = new Class({
@ -32,6 +33,7 @@ var GlobalInputManager = new Class({
this._tempMatrix = new TransformMatrix();
this._tempPoint = { x: 0, y: 0 };
this._tempHitTest = [];
},
/**
@ -92,6 +94,11 @@ var GlobalInputManager = new Class({
pointWithinGameObject: function (gameObject, x, y)
{
return PointWithinGameObject(gameObject, x, y);
},
pointScreenToWorldHitTest: function (gameObjects, x, y, camera)
{
return PointScreenToWorldHitTest(this._tempMatrix, x, y, gameObjects, camera, this._tempHitTest);
}
});

View file

@ -0,0 +1,45 @@
var GetTransformedPoint = require('./GetTransformedPoint');
var PointWithinGameObject = require('./PointWithinGameObject');
var PointScreenToWorldHitTest = function (tempMatrix, x, y, gameObjectArray, camera, output)
{
var length = gameObjectArray.length;
var scrollX = camera.scrollX;
var scrollY = camera.scrollY;
var cameraW = camera.width;
var cameraH = camera.height;
output.length = 0;
if (gameObjectArray instanceof Array)
{
var culled = camera.cull(gameObjectArray);
var culledLength = culled.length;
for (var index = 0; index < culledLength; ++index)
{
var object = culled[index];
var tpoint = GetTransformedPoint(tempMatrix, object, x + scrollX * object.scrollFactorX, y + scrollY * object.scrollFactorY);
if (PointWithinGameObject(object, tpoint.x, tpoint.y))
{
output.push(object);
}
}
return output;
}
else
{
var tpoint = GetTransformedPoint(tempMatrix, object, x + scrollX * object.scrollFactorX, y + scrollY * object.scrollFactorY);
if (PointWithinGameObject(object, tpoint.x, tpoint.y))
{
return object;
}
}
return null;
};
module.exports = PointScreenToWorldHitTest;