#include <Magnum/Animation/Easing.h>
template<class T>
BasicEasing struct new in Git master
Easing functions.
A collection of predefined easing / tweening functions for adding life to animation interpolation. Meant to be used through the Easing and Easingd typedefs.
This library is built as part of Magnum by default. To use this library with CMake, find the Magnum
package and link to the Magnum::Magnum
target:
find_package(Magnum REQUIRED) # ... target_link_libraries(your-app PRIVATE Magnum::Magnum)
See Downloading and building, Usage with CMake and Keyframe-based animation for more information.
The easing function is meant to be used to modify the interpolation factor, such as:
Vector3 result = Math::lerp(a, b, Animation::Easing::quadraticInOut(t));
The Animation library also provides the ease() utility that combines the interpolator together with the easing function:
auto lerpQuadraticInOut = Animation::ease<Vector3, Math::lerp, Animation::Easing::quadraticInOut>(); Vector3 result = lerpQuadraticInOut(a, b, t);
Equations
Every function documentation shows a plot of its behavior, together with a direction in which it extrapolates. Green color means the extrapolation goes in a reasonable monotonic direction outside of the range (also denoted by E in the above list), red color means the extrapolation is defined, but behaves in a probably unwanted or non-monotonic way (denoted by E in the above list). If neither is present, it means the function is not defined outside of the range and produces a NaN. You may want to ensure the factor stays in bounds, using either Math::
auto lerpCircularOutClamped = Animation::easeClamped< Vector3, Math::lerp, Animation::Easing::quadraticInOut>(); Vector3 result1 = Math::lerp(a, b, Math::clamp(0.0f, 1.0f, Animation::Easing::circularOut(t))); Vector3 result2 = lerpCircularOutClamped(a, b, t);
Out-function for a corresponding in-function is defined as the following, the equations in the docs usually just show the final derived form. Similarly goes for combined in-/out-function :
Easing functions defined by simple polynomials can have an exact (denoted by B in the above list) or approximate (denoted by B in the above list) cubic Math::
Matrix3 transformation; CubicBezier2D easing; CubicBezier2D transformed{ transformation.transformPoint(easing[0]), transformation.transformPoint(easing[1]), transformation.transformPoint(easing[2]), transformation.transformPoint(easing[3])};
References
Functions follow the common naming from Robert Penner's Easing functions, http:/
Public static functions
- static auto linear(T t) -> T
- Linear.
- static auto step(T t) -> T
- Step.
- static auto smoothstep(T t) -> T
- Smoothstep.
- static auto smootherstep(T t) -> T
- Smootherstep.
- static auto quadraticIn(T t) -> T
- Quadratic in.
- static auto quadraticOut(T t) -> T
- Quadratic out.
- static auto quadraticInOut(T t) -> T
- Quadratic in and out.
- static auto cubicIn(T t) -> T
- Cubic in.
- static auto cubicOut(T t) -> T
- Cubic out.
- static auto cubicInOut(T t) -> T
- Cubic in and out.
- static auto quarticIn(T t) -> T
- Quartic in.
- static auto quarticOut(T t) -> T
- Quartic out.
- static auto quarticInOut(T t) -> T
- Quartic in and out.
- static auto quinticIn(T t) -> T
- Quintic in.
- static auto quinticOut(T t) -> T
- Quintic out.
- static auto quinticInOut(T t) -> T
- Quintic in and out.
- static auto sineIn(T t) -> T
- Sine in.
- static auto sineOut(T t) -> T
- Sine out.
- static auto sineInOut(T t) -> T
- Sine in and out.
- static auto circularIn(T t) -> T
- Circular in.
- static auto circularOut(T t) -> T
- Circular out.
- static auto circularInOut(T t) -> T
- Circular in and out.
- static auto exponentialIn(T t) -> T
- Exponential in.
- static auto exponentialOut(T t) -> T
- Exponential out.
- static auto exponentialInOut(T t) -> T
- Exponential in and out.
- static auto elasticIn(T t) -> T
- Elastic in.
- static auto elasticOut(T t) -> T
- Elastic out.
- static auto elasticInOut(T t) -> T
- Elastic in and out.
- static auto backIn(T t) -> T
- Back in.
- static auto backOut(T t) -> T
- Back out.
- static auto backInOut(T t) -> T
- Back in and out.
- static auto bounceIn(T t) -> T
- Bounce in.
- static auto bounceOut(T t) -> T
- Bounce out.
- static auto bounceInOut(T t) -> T
- Bounce in and out.
Function documentation
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: linear(T t)
Linear.
One possible exact Bézier representation:
CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f}, Vector2{2.0f/3.0f}, Vector2{1.0f}}
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: step(T t)
Step.
Similar to Math::step()
function with edge = T(0.5)
.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: smoothstep(T t)
Implementation matching the GLSL smoothstep()
function. Combine with Math::
Math::lerp(a, b, Animation::Easing::smoothstep(t));
Exact Bézier representation:
CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f, 0.0f}, Vector2{2.0f/3.0f, 1.0f}, Vector2{1.0f}}
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: smootherstep(T t)
Improved version of smoothstep() by Ken Perlin.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: quadraticIn(T t)
Quadratic in.
Exact Bézier representation:
CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f, 0.0f}, Vector2{2.0f/3.0f, 1.0f/3.0f}, Vector2{1.0f}}
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: quadraticOut(T t)
Quadratic out.
Exact Bézier representation:
CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f, 2.0f/3.0f}, Vector2{2.0f/3.0f, 1.0f}, Vector2{1.0f}}
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: quadraticInOut(T t)
Quadratic in and out.
Combination of quadraticIn() and quadraticOut().
Approximate Bézier representation:
CubicBezier2D{Vector2{0.0f}, Vector2{0.455f, 0.0f}, Vector2{0.545f, 1.0f}, Vector2{1.0f}}
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: cubicIn(T t)
Cubic in.
Exact Bézier representation:
CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f, 0.0f}, Vector2{2.0f/3.0f, 0.0f}, Vector2{1.0f}}
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: cubicOut(T t)
Cubic out.
Exact Bézier representation:
CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f, 1.0f}, Vector2{2.0f/3.0f, 1.0f}, Vector2{1.0f}}
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: cubicInOut(T t)
Cubic in and out.
Combination of cubicIn() and cubicOut().
Approximate Bézier representation:
CubicBezier2D{Vector2{0.0f}, Vector2{0.645f, 0.0f}, Vector2{0.355f, 1.0f}, Vector2{1.0f}}
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: quarticIn(T t)
Quartic in.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: quarticOut(T t)
Quartic out.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: quarticInOut(T t)
Quartic in and out.
Combination of quarticIn() and quarticOut().
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: quinticIn(T t)
Quintic in.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: quinticOut(T t)
Quintic out.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: quinticInOut(T t)
Quintic in and out.
Combination of quinticIn() and quinticOut().
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: sineIn(T t)
Sine in.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: sineOut(T t)
Sine out.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: circularIn(T t)
Circular in.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: circularOut(T t)
Circular out.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: circularInOut(T t)
Circular in and out.
Combination of circularIn() and circularOut().
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: exponentialIn(T t)
Exponential in.
Contrary to Robert Penner's book but consistently with other implementations has a special case for , because otherwise.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: exponentialOut(T t)
Exponential out.
Contrary to Robert Penner's book but consistently with other implementations has a special case for , because otherwise.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: exponentialInOut(T t)
Exponential in and out.
Combination of exponentialIn() and exponentialOut(). Contrary to Robert Penner's book but consistently with other implementations has a special case for , because otherwise.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: elasticIn(T t)
Elastic in.
Combines sineIn() and exponentialIn().
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: elasticOut(T t)
Elastic out.
Combines sineOut() and exponentialOut().
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: elasticInOut(T t)
Elastic in and out.
Combination of elasticIn() and elasticOut() (or sineInOut() and exponentialInOut()).
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: backIn(T t)
Back in.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: backOut(T t)
Back out.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: bounceIn(T t)
Bounce in.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: bounceOut(T t)
Bounce out.
template<class T>
static T Magnum:: Animation:: BasicEasing<T>:: bounceInOut(T t)
Bounce in and out.
Combination of bounceIn() and bounceOut().