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 Class = require('../../../utils/Class');
|
|
|
|
var Curve = require('../Curve');
|
|
|
|
var Vector2 = require('../../../math/Vector2');
|
|
|
|
|
|
|
|
// Phaser.Curves.Line
|
|
|
|
|
|
|
|
var tmpVec2 = new Vector2();
|
|
|
|
|
|
|
|
var LineCurve = new Class({
|
|
|
|
|
|
|
|
Extends: Curve,
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
// vec2s
|
|
|
|
function LineCurve (v1, v2)
|
|
|
|
{
|
2017-09-22 00:34:53 +00:00
|
|
|
if (Array.isArray(v1))
|
|
|
|
{
|
|
|
|
v2 = new Vector2(v1[2], v1[3]);
|
|
|
|
v1 = new Vector2(v1[0], v1[1]);
|
|
|
|
}
|
|
|
|
|
2017-09-21 00:19:27 +00:00
|
|
|
Curve.call(this);
|
|
|
|
|
2017-09-20 22:10:37 +00:00
|
|
|
this.v1 = v1;
|
|
|
|
this.v2 = v2;
|
|
|
|
},
|
|
|
|
|
2017-09-21 16:12:16 +00:00
|
|
|
getResolution: function (divisions)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
},
|
|
|
|
|
2017-09-20 22:10:37 +00:00
|
|
|
getPoint: function (t, out)
|
|
|
|
{
|
|
|
|
if (out === undefined) { out = new Vector2(); }
|
|
|
|
|
|
|
|
if (t === 1)
|
|
|
|
{
|
|
|
|
return out.copy(this.v2);
|
|
|
|
}
|
|
|
|
|
|
|
|
out.copy(this.v2).sub(this.v1).scale(t).add(this.v1);
|
|
|
|
|
|
|
|
return out;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Line curve is linear, so we can overwrite default getPointAt
|
|
|
|
getPointAt: function (u, out)
|
|
|
|
{
|
|
|
|
return this.getPoint(u, out);
|
|
|
|
},
|
|
|
|
|
|
|
|
getTangent: function ()
|
|
|
|
{
|
|
|
|
var tangent = tmpVec2.copy(this.v2).sub(this.v1);
|
|
|
|
|
|
|
|
return tangent.normalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = LineCurve;
|