Quick port of Robert Penner's easing equations*
*Excluding bounce, since that's not really a equation.
Code: Select all
// Sine
float easeInSine(float T)
{
return sin((T-1)*PI*0.5)+1;
}
float easeOutSine(float T)
{
return sin(T*PI*0.5);
}
float easeInOutSine(float T)
{
return 0.5*(1-cos(T*PI));
}
// Quadratic
float easeInQuad(float T)
{
return T*T;
}
float easeOutQuad(float T)
{
return 0-T*(T-2);
}
float easeInOutQuad(float T)
{
if(T < 0.5)
{
return 2*T*T;
}
else
{
return -2*T*T+4*T-1;
}
}
// Cubic
float easeInCubic(float T)
{
return T*T*T;
}
float easeOutCubic(float T)
{
float F = T-1;
return F*F*F+1;
}
float easeInOutCubic(float T)
{
if(T < 0.5)
{
return 4*T*T*T;
}
else
{
float F = 2*T-2;
return 0.5*F*F*F+1;
}
}
// Quartic
float easeInQuart(float T)
{
return T*T*T*T;
}
float easeOutQuart(float T)
{
float F = T-1;
return F*F*F*(1-T)+1;
}
float easeInOutQuart(float T)
{
if(T < 0.5)
{
return 8*T*T*T*T;
}
else
{
float F = T-1;
return -8*F*F*F*F+1;
}
}
// Quintic
float easeInQuint(float T)
{
return T*T*T*T*T;
}
float easeOutQuint(float T)
{
float F = T-1;
return F*F*F*F*F+1;
}
float easeInOutQuint(float T)
{
if(T < 0.5)
{
return 16*T*T*T*T*T;
}
else
{
float F = 2*T-2;
return 0.5*F*F*F*F*F+1;
}
}
// Exponential
float easeInExpo(float T)
{
return T ? pow(2,10*(T-1)) : T;
}
float easeOutExpo(float T)
{
return T == 1 ? T : 1-pow(2,-10*T);
}
float easeInOutExpo(float T)
{
if(T == 0 || T == 1)return T;
if(T < 0.5)
{
return 0.5*pow(2,(20*T)-10);
}
else
{
return -0.5*pow(2,(-20*T)+10)+1;
}
}
// Circular
float easeInCirc(float T)
{
return 1-sqrt(1-T*T);
}
float easeOutCirc(float T)
{
return sqrt((2-T)*T);
}
float easeInOutCirc(float T)
{
if(T < 0.5)
{
return 0.5*(1-sqrt(1-4*T*T));
}
else
{
return 0.5*(sqrt(0-(2*T-3)*(2*T-1))+1);
}
}
// Back
float easeInBack(float T)
{
return T*T*T-T*sin(T*PI);
}
float easeOutBack(float T)
{
float F = 1-T;
return 1-(F*F*F-F*sin(F*PI));
}
float easeInOutBack(float T)
{
float F;
if(T < 0.5)
{
F = 2*T;
return 0.5*(F*F*F-F*sin(F*PI));
}
else
{
F = 1-(2*T-1);
return 0.5*(1-(F*F*F-F*sin(F*PI)))+0.5;
}
}
// Elastic
float easeInElastic(float T)
{
return sin(13*PI*0.5*T)*pow(2,10*(T-1));
}
float easeOutElastic(float T)
{
return sin(-13*PI*0.5*(T+1))*pow(2,-10*T)+1;
}
float easeInOutElastic(float T)
{
if(T < 0.5)
{
return 0.5*sin(13*PI*T)*pow(2,10*(2*T-1));
}
else
{
return 0.5*(sin(-13*PI*T)*pow(2,-10*(2*T-1))+2);
}
}