2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2018-01-04 15:20:28 +00:00
|
|
|
var Vector2 = require('./Vector2');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes the `x` and `y` coordinates and transforms them into the same space as
|
|
|
|
* defined by the position, rotation and scale values.
|
|
|
|
*
|
|
|
|
* @function Phaser.Math.TransformXY
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param {number} x - The x coordinate to be transformed.
|
|
|
|
* @param {number} y - The y coordinate to be transformed.
|
|
|
|
* @param {number} positionX - Horizontal position of the transform point.
|
|
|
|
* @param {number} positionY - Vertical position of the transform point.
|
|
|
|
* @param {number} rotation - Rotation of the transform point, in radians.
|
|
|
|
* @param {number} scaleX - Horizontal scale of the transform point.
|
|
|
|
* @param {number} scaleY - Vertical scale of the transform point.
|
2018-05-23 09:46:16 +00:00
|
|
|
* @param {(Phaser.Math.Vector2|Phaser.Geom.Point|object)} [output] - The output vector, point or object for the translated coordinates.
|
2018-01-04 15:20:28 +00:00
|
|
|
*
|
2018-03-21 14:41:16 +00:00
|
|
|
* @return {(Phaser.Math.Vector2|Phaser.Geom.Point|object)} The translated point.
|
2018-01-04 15:20:28 +00:00
|
|
|
*/
|
|
|
|
var TransformXY = function (x, y, positionX, positionY, rotation, scaleX, scaleY, output)
|
|
|
|
{
|
|
|
|
if (output === undefined) { output = new Vector2(); }
|
|
|
|
|
2018-08-29 15:10:48 +00:00
|
|
|
var radianSin = Math.sin(rotation);
|
|
|
|
var radianCos = Math.cos(rotation);
|
2018-01-04 15:20:28 +00:00
|
|
|
|
2018-08-29 15:10:48 +00:00
|
|
|
// Rotate and Scale
|
|
|
|
var a = radianCos * scaleX;
|
|
|
|
var b = radianSin * scaleX;
|
|
|
|
var c = -radianSin * scaleY;
|
|
|
|
var d = radianCos * scaleY;
|
2018-01-04 15:20:28 +00:00
|
|
|
|
|
|
|
// Invert
|
2018-08-29 15:10:48 +00:00
|
|
|
var id = 1 / ((a * d) + (c * -b));
|
2018-01-04 15:20:28 +00:00
|
|
|
|
2018-08-29 15:10:48 +00:00
|
|
|
output.x = (d * id * x) + (-c * id * y) + (((positionY * c) - (positionX * d)) * id);
|
|
|
|
output.y = (a * id * y) + (-b * id * x) + (((-positionY * a) + (positionX * b)) * id);
|
2018-01-04 15:20:28 +00:00
|
|
|
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = TransformXY;
|