CUGL 2.1
Cornell University Game Library
|
#include <CUEasingBezier.h>
Public Member Functions | |
EasingBezier () | |
~EasingBezier () | |
void | dispose () |
bool | init () |
bool | init (EasingFunction::Type type) |
bool | init (float x1, float y1, float x2, float y2) |
bool | init (const Vec2 p1, const Vec2 p2) |
float | evaluate (float t) |
std::function< float(float)> | getEvaluator () |
Static Public Member Functions | |
static std::shared_ptr< EasingBezier > | alloc () |
static std::shared_ptr< EasingBezier > | alloc (EasingFunction::Type type) |
static std::shared_ptr< EasingBezier > | alloc (float x1, float y1, float x2, float y2) |
static std::shared_ptr< EasingBezier > | alloc (const Vec2 p1, const Vec2 p2) |
Protected Member Functions | |
void | solveQuadraticEquation (float a, float b, float c) |
void | solveCubicEquation (float a, float b, float c, float d) |
Protected Attributes | |
Vec2 | _c1 |
Vec2 | _c2 |
Vec2 | _c3 |
std::vector< float > | _rootset |
This class represents a bexier curve that implements an easing function.
The object itself stores the bezier curve, which cannot be manipulated after creation (for thread safety). The bezier curve is defined as a cubic polynomial that maps a paramter t onto the xy plane.
The method getEvaluator() returns a function pointer that can be used to interpolate the function over time (e.g. for tweening support). The function retains a shared pointer to the object, so the object reference can be safely discarded after getting the function pointer.
cugl::EasingBezier::EasingBezier | ( | ) |
Creates an uninitialized easing function.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.
|
inline |
Deletes this easing function, disposing all resources
|
inlinestatic |
Returns a newly allocated linear easing function
|
inlinestatic |
Returns a newly allocated easing function eith the given control points.
Any cubic bezier can be defined by a two control points in the plane, which define the tanget lines of the two endpoints. These are often manifested as handles in programs like Adobe Illustrator.
p1 | The first handle. |
p2 | The second handle. |
|
inlinestatic |
Returns a newly allocated easing function of the given type.
Bezier easing functions can duplicate every easing function in EasingFunction except for the bounce and elastic functions.
type | The easing function type |
|
inlinestatic |
Returns a newly allocated easing function eith the given control points.
Any cubic bezier can be defined by a two control points in the plane, which define the tanget lines of the two endpoints. These are often manifested as handles in programs like Adobe Illustrator.
x1 | The x-coordinate of the first handle. |
y1 | The y-coordinate of the first handle. |
x2 | The x-coordinate of the second handle. |
y2 | The y-coordinate of the second handle. |
void cugl::EasingBezier::dispose | ( | ) |
Disposes all of the resources used by this easing function.
A disposed function can be safely reinitialized.
float cugl::EasingBezier::evaluate | ( | float | t | ) |
Returns the value of the easing function at t.
The easing function is only well-defined when 0 <= t <= 1.
std::function<float(float)> cugl::EasingBezier::getEvaluator | ( | ) |
Returns a pointer to the function represented by this object.
The function retains a shared pointer to the object, so the object reference can be safely discarded after getting the function pointer.
|
inline |
Initializes a linear easing function
Initializes an easing function eith the given control points.
Any cubic bezier can be defined by a two control points in the plane, which define the tanget lines of the two endpoints. These are often manifested as handles in programs like Adobe Illustrator.
p1 | The first handle. |
p2 | The second handle. |
bool cugl::EasingBezier::init | ( | EasingFunction::Type | type | ) |
Initializes an easing function of the given type.
Bezier easing functions can duplicate every easing function in EasingFunction except for the bounce and elastic functions.
type | The easing function type |
bool cugl::EasingBezier::init | ( | float | x1, |
float | y1, | ||
float | x2, | ||
float | y2 | ||
) |
Initializes an easing function eith the given control points.
Any cubic bezier can be defined by a two control points in the plane, which define the tanget lines of the two endpoints. These are often manifested as handles in programs like Adobe Illustrator.
x1 | The x-coordinate of the first handle. |
y1 | The y-coordinate of the first handle. |
x2 | The x-coordinate of the second handle. |
y2 | The y-coordinate of the second handle. |
|
protected |
Stores the roots of a x^3 + b x^2 + c x + d into the rootset.
This is a helper function for computing the root set from the bezier polynomial.
a | The 3rd degree coefficient |
b | The 2nd degree coefficient |
c | The linear coefficient |
d | The constant factor |
|
protected |
Stores the roots of a x^2 + b x + c into the rootset.
This is a helper function for computing the root set from the bezier polynomial.
a | The 2nd degree coefficient |
b | The linear coefficient |
c | The constant factor |
|
protected |
The C1 coefficient
|
protected |
The C2 coefficient
|
protected |
The C3 coefficient
|
protected |
The rootset of the polynomial x-component (cached for efficiency).