mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
Camera input transform update
This commit is contained in:
parent
e9a71beba7
commit
3b296162cf
7 changed files with 94 additions and 36 deletions
|
@ -65,7 +65,7 @@ var Camera = new Class({
|
|||
this._id = 0;
|
||||
},
|
||||
|
||||
cameraToScreen: require('./inc/CameraToScreen'),
|
||||
cameraToWorld: require('./inc/CameraToWorld'),
|
||||
centerToBounds: require('./inc/CenterToBounds'),
|
||||
centerToSize: require('./inc/CenterToSize'),
|
||||
cull: require('./inc/Cull'),
|
||||
|
@ -77,7 +77,6 @@ var Camera = new Class({
|
|||
ignore: require('./inc/Ignore'),
|
||||
preRender: require('./inc/PreRender'),
|
||||
removeBounds: require('./inc/RemoveBounds'),
|
||||
screenToCamera: require('./inc/ScreenToCamera'),
|
||||
setAngle: require('./inc/SetAngle'),
|
||||
setBackgroundColor: require('./inc/SetBackgroundColor'),
|
||||
setBounds: require('./inc/SetBounds'),
|
||||
|
@ -94,7 +93,8 @@ var Camera = new Class({
|
|||
startFollow: require('./inc/StartFollow'),
|
||||
stopFollow: require('./inc/StopFollow'),
|
||||
toJSON: require('./inc/ToJSON'),
|
||||
update: require('./inc/Update')
|
||||
update: require('./inc/Update'),
|
||||
worldToCamera: require('./inc/WorldToCamera')
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var CameraToScreen = function (pointIn, pointOut)
|
||||
var CameraToWorld = function (pointIn, pointOut)
|
||||
{
|
||||
var cameraMatrix = this.matrix.matrix;
|
||||
var mva = cameraMatrix[0];
|
||||
|
@ -24,9 +24,13 @@ var CameraToScreen = function (pointIn, pointOut)
|
|||
var imd = mva * determinant;
|
||||
var ime = (mvc * mvf - mvd * mve) * determinant;
|
||||
var imf = (mvb * mve - mva * mvf) * determinant;
|
||||
|
||||
var x = pointIn.x;
|
||||
var y = pointIn.y;
|
||||
var c = Math.cos(this.rotation);
|
||||
var s = Math.sin(this.rotation);
|
||||
var zoom = this.zoom;
|
||||
var scrollX = this.scrollX;
|
||||
var scrollY = this.scrollY;
|
||||
var x = pointIn.x + ((scrollX * c - scrollY * s) * zoom);
|
||||
var y = pointIn.y + ((scrollX * s + scrollY * c) * zoom);
|
||||
|
||||
if (!pointOut)
|
||||
{
|
||||
|
@ -40,4 +44,4 @@ var CameraToScreen = function (pointIn, pointOut)
|
|||
return pointOut;
|
||||
};
|
||||
|
||||
module.exports = CameraToScreen;
|
||||
module.exports = CameraToWorld;
|
|
@ -1,12 +0,0 @@
|
|||
var ScreenToCamera = function (x, y, pointOut)
|
||||
{
|
||||
this.matrix.transformPoint(x, y, pointOut);
|
||||
|
||||
// Add in the scroll offset
|
||||
pointOut.x += this.scrollX;
|
||||
pointOut.y += this.scrollY;
|
||||
|
||||
return pointOut;
|
||||
};
|
||||
|
||||
module.exports = ScreenToCamera;
|
65
v3/src/camera/2d/inc/WorldToCamera.js
Normal file
65
v3/src/camera/2d/inc/WorldToCamera.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
var TransformMatrix = require('../../../gameobjects/components/TransformMatrix');
|
||||
var matrix0 = new TransformMatrix(1, 0, 0, 1, 0, 0);
|
||||
var matrix1 = new TransformMatrix(1, 0, 0, 1, 0, 0);
|
||||
var WorldToCamera = function (pointIn, pointOut)
|
||||
{
|
||||
if (!pointOut)
|
||||
{
|
||||
pointOut = { x: pointIn.x, y: pointIn.y };
|
||||
}
|
||||
|
||||
var cameraMatrix = this.matrix.matrix;
|
||||
var mva = cameraMatrix[0];
|
||||
var mvb = cameraMatrix[1];
|
||||
var mvc = cameraMatrix[2];
|
||||
var mvd = cameraMatrix[3];
|
||||
var mve = cameraMatrix[4];
|
||||
var mvf = cameraMatrix[5];
|
||||
|
||||
/* First Invert Matrix */
|
||||
var determinant = (mva * mvd) - (mvb * mvc);
|
||||
|
||||
if (!determinant)
|
||||
{
|
||||
return pointIn;
|
||||
}
|
||||
|
||||
determinant = 1 / determinant;
|
||||
|
||||
var ima = mvd * determinant;
|
||||
var imb = -mvb * determinant;
|
||||
var imc = -mvc * determinant;
|
||||
var imd = mva * determinant;
|
||||
var ime = (mvc * mvf - mvd * mve) * determinant;
|
||||
var imf = (mvb * mve - mva * mvf) * determinant;
|
||||
|
||||
matrix0.matrix[0] = ima;
|
||||
matrix0.matrix[1] = imb;
|
||||
matrix0.matrix[2] = imc;
|
||||
matrix0.matrix[3] = imd;
|
||||
matrix0.matrix[4] = ime;
|
||||
matrix0.matrix[5] = imf;
|
||||
|
||||
//var c = Math.cos(this.rotation);
|
||||
//var s = Math.sin(this.rotation);
|
||||
var zoom = this.zoom;
|
||||
var scrollX = this.scrollX;
|
||||
var scrollY = this.scrollY;
|
||||
var x = pointIn.x;// + scrollX * zoom;
|
||||
var y = pointIn.y;// + scrollY * zoom;
|
||||
|
||||
//var x = pointIn.x - ((scrollX * c - scrollY * s) * zoom);
|
||||
//var y = pointIn.y - ((scrollX * s + scrollY * c) * zoom);
|
||||
|
||||
matrix1.applyITRS(scrollX, scrollY, 0.0, zoom, zoom);
|
||||
//matrix1.invert();
|
||||
//matrix0.invert();
|
||||
|
||||
matrix0.multiply(matrix1);
|
||||
|
||||
pointOut = matrix0.transformPoint(x, y, pointOut);
|
||||
|
||||
return pointOut;
|
||||
};
|
||||
|
||||
module.exports = WorldToCamera;
|
|
@ -68,9 +68,10 @@ var TransformMatrix = new Class({
|
|||
return this.transform(radianCos, radianSin, -radianSin, radianCos, 0, 0);
|
||||
},
|
||||
|
||||
multiply: function (otherMatrix)
|
||||
multiply: function (lhs)
|
||||
{
|
||||
var matrix = this.matrix;
|
||||
var otherMatrix = lhs.matrix;
|
||||
|
||||
var a0 = matrix[0];
|
||||
var b0 = matrix[1];
|
||||
|
|
|
@ -221,8 +221,8 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
|
|||
/* Graphics Game Object Properties */
|
||||
srcX, srcY, srcScaleX, srcScaleY, srcRotation,
|
||||
/* Rectangle properties */
|
||||
commandBuffer[cmdIndex + 1] - cameraScrollX,
|
||||
commandBuffer[cmdIndex + 2] - cameraScrollY,
|
||||
commandBuffer[cmdIndex + 1],
|
||||
commandBuffer[cmdIndex + 2],
|
||||
commandBuffer[cmdIndex + 3],
|
||||
commandBuffer[cmdIndex + 4],
|
||||
fillColor,
|
||||
|
@ -241,12 +241,12 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
|
|||
/* Graphics Game Object Properties */
|
||||
srcX, srcY, srcScaleX, srcScaleY, srcRotation,
|
||||
/* Triangle properties */
|
||||
commandBuffer[cmdIndex + 1] - cameraScrollX,
|
||||
commandBuffer[cmdIndex + 2] - cameraScrollY,
|
||||
commandBuffer[cmdIndex + 3] - cameraScrollX,
|
||||
commandBuffer[cmdIndex + 4] - cameraScrollY,
|
||||
commandBuffer[cmdIndex + 5] - cameraScrollX,
|
||||
commandBuffer[cmdIndex + 6] - cameraScrollY,
|
||||
commandBuffer[cmdIndex + 1],
|
||||
commandBuffer[cmdIndex + 2],
|
||||
commandBuffer[cmdIndex + 3],
|
||||
commandBuffer[cmdIndex + 4],
|
||||
commandBuffer[cmdIndex + 5],
|
||||
commandBuffer[cmdIndex + 6],
|
||||
fillColor,
|
||||
fillAlpha,
|
||||
/* Transform */
|
||||
|
@ -263,12 +263,12 @@ var GraphicsWebGLRenderer = function (renderer, gameObject, interpolationPercent
|
|||
/* Graphics Game Object Properties */
|
||||
srcX, srcY, srcScaleX, srcScaleY, srcRotation,
|
||||
/* Triangle properties */
|
||||
commandBuffer[cmdIndex + 1] - cameraScrollX,
|
||||
commandBuffer[cmdIndex + 2] - cameraScrollY,
|
||||
commandBuffer[cmdIndex + 3] - cameraScrollX,
|
||||
commandBuffer[cmdIndex + 4] - cameraScrollY,
|
||||
commandBuffer[cmdIndex + 5] - cameraScrollX,
|
||||
commandBuffer[cmdIndex + 6] - cameraScrollY,
|
||||
commandBuffer[cmdIndex + 1],
|
||||
commandBuffer[cmdIndex + 2],
|
||||
commandBuffer[cmdIndex + 3],
|
||||
commandBuffer[cmdIndex + 4],
|
||||
commandBuffer[cmdIndex + 5],
|
||||
commandBuffer[cmdIndex + 6],
|
||||
lineWidth,
|
||||
lineColor,
|
||||
lineAlpha,
|
||||
|
|
|
@ -17,7 +17,7 @@ var HitTest = function (tempMatrix, x, y, gameObjects, camera, output)
|
|||
return output;
|
||||
}
|
||||
|
||||
var screenPoint = camera.cameraToScreen({ x: x, y: y });
|
||||
var screenPoint = camera.cameraToWorld({ x: x, y: y });
|
||||
var culledGameObjects = camera.cull(gameObjects);
|
||||
|
||||
for (var i = 0; i < culledGameObjects.length; i++)
|
||||
|
|
Loading…
Add table
Reference in a new issue