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:
Par Winzell
2007-11-01 14:50:22 +00:00
parent c9ee5f1c21
commit 45abd9a903
+25 -11
View File
@@ -23,32 +23,46 @@ package com.threerings.flash.path {
/**
* 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 function HermiteFunc (start :int, end :int)
public function HermiteFunc (start :int, end :int, startSlope :Number = 0, endSlope :Number = 0)
{
_start = start;
_end = end;
_p0 = start;
_p1 = end;
_m0 = startSlope;
_m1 = endSlope;
}
// from InterpFunc
override public function getValue (t :Number) :int
{
if (t >= 1) {
return _end;
return _p1;
} else if (t < 0) { // cope with a funny startOffset
return _start;
return _p0;
} else {
var h00 :Number = 2*t*t*t - 3*t*t + 1;
var h01 :Number = -2*t*t*t + 3*t*t;
var tt :Number = 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;
protected var _end :int;
/** The coefficient for the spline that interpolates the beginning point value. */
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;
}
}