Converted HermiteFunc into a standard easing function. Untested.
git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@542 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
package com.threerings.flash {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Some easing functions.
|
||||||
|
*/
|
||||||
|
public class Easing
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Interpolates cubically between two values, with beginning and end derivates set
|
||||||
|
* to zero. See http://en.wikipedia.org/wiki/Cubic_Hermite_spline for details.
|
||||||
|
*/
|
||||||
|
public static function cubicHermiteSpline (
|
||||||
|
t :Number, b :Number, c :Number, d :Number, p_params :Object = null) :Number
|
||||||
|
{
|
||||||
|
// convert t to 0-1
|
||||||
|
t = (t / d);
|
||||||
|
if (t <= 0) {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
const end :Number = b + c;
|
||||||
|
if (t >= 1) {
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
const startSlope :Number = (p_params == null) ? 0 : Number(p_params["startSlope"]);
|
||||||
|
const endSlope :Number = (p_params == null) ? 0 : Number(p_params["endSlope"]);
|
||||||
|
const tt :Number = t * t;
|
||||||
|
const ttt :Number = tt * t;
|
||||||
|
return b * (2*ttt - 3*tt + 1) +
|
||||||
|
startSlope * (ttt - 2*tt + t) +
|
||||||
|
end * (-2*ttt + 3*tt) +
|
||||||
|
endSlope * (ttt -tt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user