mirror of
https://github.com/photonstorm/phaser
synced 2024-11-28 15:41:37 +00:00
Added missing Curve constructor calls (opps!) and fixed tmpVec assignment in getLengths
This commit is contained in:
parent
bbfb8e4f12
commit
1439144fae
4 changed files with 20 additions and 7 deletions
|
@ -20,6 +20,10 @@ var Curve = new Class({
|
||||||
function Curve ()
|
function Curve ()
|
||||||
{
|
{
|
||||||
this.arcLengthDivisions = 200;
|
this.arcLengthDivisions = 200;
|
||||||
|
|
||||||
|
this.cacheArcLengths = [];
|
||||||
|
|
||||||
|
this.needsUpdate = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get point at relative position in curve according to arc length
|
// Get point at relative position in curve according to arc length
|
||||||
|
@ -58,7 +62,9 @@ var Curve = new Class({
|
||||||
|
|
||||||
for (var d = 0; d <= divisions; d++)
|
for (var d = 0; d <= divisions; d++)
|
||||||
{
|
{
|
||||||
points.push(this.getPointAt(d / divisions));
|
var t = this.getUtoTmapping(d / divisions, null, divisions);
|
||||||
|
|
||||||
|
points.push(this.getPoint(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
return points;
|
return points;
|
||||||
|
@ -79,9 +85,7 @@ var Curve = new Class({
|
||||||
{
|
{
|
||||||
if (divisions === undefined) { divisions = this.arcLengthDivisions; }
|
if (divisions === undefined) { divisions = this.arcLengthDivisions; }
|
||||||
|
|
||||||
if (this.cacheArcLengths &&
|
if ((this.cacheArcLengths.length === divisions + 1) && !this.needsUpdate)
|
||||||
(this.cacheArcLengths.length === divisions + 1) &&
|
|
||||||
!this.needsUpdate)
|
|
||||||
{
|
{
|
||||||
return this.cacheArcLengths;
|
return this.cacheArcLengths;
|
||||||
}
|
}
|
||||||
|
@ -98,9 +102,12 @@ var Curve = new Class({
|
||||||
for (var p = 1; p <= divisions; p++)
|
for (var p = 1; p <= divisions; p++)
|
||||||
{
|
{
|
||||||
current = this.getPoint(p / divisions, tmpVec2B);
|
current = this.getPoint(p / divisions, tmpVec2B);
|
||||||
|
|
||||||
sum += current.distance(last);
|
sum += current.distance(last);
|
||||||
|
|
||||||
cache.push(sum);
|
cache.push(sum);
|
||||||
last = current;
|
|
||||||
|
last.copy(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cacheArcLengths = cache;
|
this.cacheArcLengths = cache;
|
||||||
|
@ -117,9 +124,9 @@ var Curve = new Class({
|
||||||
|
|
||||||
// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
|
// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
|
||||||
|
|
||||||
getUtoTmapping: function (u, distance)
|
getUtoTmapping: function (u, distance, divisions)
|
||||||
{
|
{
|
||||||
var arcLengths = this.getLengths();
|
var arcLengths = this.getLengths(divisions);
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
var il = arcLengths.length;
|
var il = arcLengths.length;
|
||||||
|
|
|
@ -15,6 +15,8 @@ var CubicBezierCurve = new Class({
|
||||||
|
|
||||||
function CubicBezierCurve (v0, v1, v2, v3)
|
function CubicBezierCurve (v0, v1, v2, v3)
|
||||||
{
|
{
|
||||||
|
Curve.call(this);
|
||||||
|
|
||||||
this.v0 = v0;
|
this.v0 = v0;
|
||||||
this.v1 = v1;
|
this.v1 = v1;
|
||||||
this.v2 = v2;
|
this.v2 = v2;
|
||||||
|
|
|
@ -13,6 +13,8 @@ var EllipseCurve = new Class({
|
||||||
|
|
||||||
function EllipseCurve (aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation)
|
function EllipseCurve (aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation)
|
||||||
{
|
{
|
||||||
|
Curve.call(this);
|
||||||
|
|
||||||
this.aX = aX;
|
this.aX = aX;
|
||||||
this.aY = aY;
|
this.aY = aY;
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ var LineCurve = new Class({
|
||||||
// vec2s
|
// vec2s
|
||||||
function LineCurve (v1, v2)
|
function LineCurve (v1, v2)
|
||||||
{
|
{
|
||||||
|
Curve.call(this);
|
||||||
|
|
||||||
this.v1 = v1;
|
this.v1 = v1;
|
||||||
this.v2 = v2;
|
this.v2 = v2;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue