2017-09-20 22:10:37 +00:00
|
|
|
// Based on the three.js Curve classes created by [zz85](http://www.lab4games.net/zz85/blog)
|
|
|
|
|
|
|
|
var Curve = require('../Curve');
|
|
|
|
var Class = require('../../../utils/Class');
|
|
|
|
|
|
|
|
// Phaser.Paths.Curves.Ellipse
|
|
|
|
|
|
|
|
var EllipseCurve = new Class({
|
|
|
|
|
|
|
|
Extends: Curve,
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function EllipseCurve (aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation)
|
|
|
|
{
|
2017-09-21 00:19:27 +00:00
|
|
|
Curve.call(this);
|
|
|
|
|
2017-09-20 22:10:37 +00:00
|
|
|
this.aX = aX;
|
|
|
|
this.aY = aY;
|
|
|
|
|
|
|
|
this.xRadius = xRadius;
|
|
|
|
this.yRadius = yRadius;
|
|
|
|
|
|
|
|
this.aStartAngle = aStartAngle;
|
|
|
|
this.aEndAngle = aEndAngle;
|
|
|
|
|
|
|
|
this.aClockwise = aClockwise;
|
|
|
|
|
|
|
|
this.aRotation = aRotation || 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
getPoint: function (t)
|
|
|
|
{
|
|
|
|
var twoPi = Math.PI * 2;
|
|
|
|
var deltaAngle = this.aEndAngle - this.aStartAngle;
|
|
|
|
var samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
|
|
|
|
|
|
|
|
// ensures that deltaAngle is 0 .. 2 PI
|
|
|
|
while (deltaAngle < 0)
|
|
|
|
{
|
|
|
|
deltaAngle += twoPi;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (deltaAngle > twoPi)
|
|
|
|
{
|
|
|
|
deltaAngle -= twoPi;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deltaAngle < Number.EPSILON)
|
|
|
|
{
|
|
|
|
if (samePoints)
|
|
|
|
{
|
|
|
|
deltaAngle = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
deltaAngle = twoPi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.aClockwise === true && ! samePoints)
|
|
|
|
{
|
|
|
|
if (deltaAngle === twoPi)
|
|
|
|
{
|
|
|
|
deltaAngle = - twoPi;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
deltaAngle = deltaAngle - twoPi;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var angle = this.aStartAngle + t * deltaAngle;
|
|
|
|
var x = this.aX + this.xRadius * Math.cos(angle);
|
|
|
|
var y = this.aY + this.yRadius * Math.sin(angle);
|
|
|
|
|
|
|
|
if (this.aRotation !== 0)
|
|
|
|
{
|
|
|
|
var cos = Math.cos(this.aRotation);
|
|
|
|
var sin = Math.sin(this.aRotation);
|
|
|
|
|
|
|
|
var tx = x - this.aX;
|
|
|
|
var ty = y - this.aY;
|
|
|
|
|
|
|
|
// Rotate the point about the center of the ellipse.
|
|
|
|
x = tx * cos - ty * sin + this.aX;
|
|
|
|
y = tx * sin + ty * cos + this.aY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Vector2(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = EllipseCurve;
|