If it were done, when 'tis done, then 'twer well, it were done properly.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@327 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -23,32 +23,46 @@ package com.threerings.flash.path {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Interpolates cubically between two values, with beginning and end derivates set
|
* Interpolates cubically between two values, with beginning and end derivates set
|
||||||
* to zero. TODO: Add support for specifying derivate values as well.
|
* to zero. See http://en.wikipedia.org/wiki/Cubic_Hermite_spline for details.
|
||||||
*/
|
*/
|
||||||
public class HermiteFunc extends InterpFunc
|
public class HermiteFunc extends InterpFunc
|
||||||
{
|
{
|
||||||
public function HermiteFunc (start :int, end :int)
|
public function HermiteFunc (start :int, end :int, startSlope :Number = 0, endSlope :Number = 0)
|
||||||
{
|
{
|
||||||
_start = start;
|
_p0 = start;
|
||||||
_end = end;
|
_p1 = end;
|
||||||
|
_m0 = startSlope;
|
||||||
|
_m1 = endSlope;
|
||||||
}
|
}
|
||||||
|
|
||||||
// from InterpFunc
|
// from InterpFunc
|
||||||
override public function getValue (t :Number) :int
|
override public function getValue (t :Number) :int
|
||||||
{
|
{
|
||||||
if (t >= 1) {
|
if (t >= 1) {
|
||||||
return _end;
|
return _p1;
|
||||||
} else if (t < 0) { // cope with a funny startOffset
|
} else if (t < 0) { // cope with a funny startOffset
|
||||||
return _start;
|
return _p0;
|
||||||
} else {
|
} else {
|
||||||
var h00 :Number = 2*t*t*t - 3*t*t + 1;
|
var tt :Number = t*t;
|
||||||
var h01 :Number = -2*t*t*t + 3*t*t;
|
var ttt :Number = t2 * t;
|
||||||
|
|
||||||
return int(_start * h00 + _end * h01);
|
return int(_p0 * (2*ttt - 3*tt + 1) +
|
||||||
|
_m0 * (ttt - 2*tt + t) +
|
||||||
|
_p1 * (-2*ttt + 3*tt) +
|
||||||
|
_m1 * (ttt - tt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected var _start :int;
|
/** The coefficient for the spline that interpolates the beginning point value. */
|
||||||
protected var _end :int;
|
protected var _p0 :Number;
|
||||||
|
|
||||||
|
/** The coefficient for the spline that interpolates the end point value. */
|
||||||
|
protected var _p1 :Number;
|
||||||
|
|
||||||
|
/** The coefficient for the spline that interpolates the beginning point derivate. */
|
||||||
|
protected var _m0 :Number;
|
||||||
|
|
||||||
|
/** The coefficient for the spline that interpolates the end point derivate. */
|
||||||
|
protected var _m1 :Number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user