CUGL 2.3
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
cugl::EasingBezier Class Reference

#include <CUEasingBezier.h>

Inheritance diagram for cugl::EasingBezier:

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< EasingBezieralloc ()
 
static std::shared_ptr< EasingBezieralloc (EasingFunction::Type type)
 
static std::shared_ptr< EasingBezieralloc (float x1, float y1, float x2, float y2)
 
static std::shared_ptr< EasingBezieralloc (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ EasingBezier()

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.

◆ ~EasingBezier()

cugl::EasingBezier::~EasingBezier ( )
inline

Deletes this easing function, disposing all resources

Member Function Documentation

◆ alloc() [1/4]

static std::shared_ptr< EasingBezier > cugl::EasingBezier::alloc ( )
inlinestatic

Returns a newly allocated linear easing function

Returns
a newly allocated linear easing function

◆ alloc() [2/4]

static std::shared_ptr< EasingBezier > cugl::EasingBezier::alloc ( const Vec2  p1,
const Vec2  p2 
)
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.

Parameters
p1The first handle.
p2The second handle.
Returns
a newly allocated easing function eith the given control points.

◆ alloc() [3/4]

static std::shared_ptr< EasingBezier > cugl::EasingBezier::alloc ( EasingFunction::Type  type)
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.

Parameters
typeThe easing function type
Returns
a newly allocated easing function of the given type.

◆ alloc() [4/4]

static std::shared_ptr< EasingBezier > cugl::EasingBezier::alloc ( float  x1,
float  y1,
float  x2,
float  y2 
)
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.

Parameters
x1The x-coordinate of the first handle.
y1The y-coordinate of the first handle.
x2The x-coordinate of the second handle.
y2The y-coordinate of the second handle.
Returns
a newly allocated easing function eith the given control points.

◆ dispose()

void cugl::EasingBezier::dispose ( )

Disposes all of the resources used by this easing function.

A disposed function can be safely reinitialized.

◆ evaluate()

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.

Returns
the value of the easing function at t.

◆ getEvaluator()

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.

Returns
a pointer to the function represented by this object.

◆ init() [1/4]

bool cugl::EasingBezier::init ( )
inline

Initializes a linear easing function

Returns
true if initialization was successful.

◆ init() [2/4]

bool cugl::EasingBezier::init ( const Vec2  p1,
const Vec2  p2 
)
inline

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.

Parameters
p1The first handle.
p2The second handle.
Returns
true if initialization was successful.

◆ init() [3/4]

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.

Parameters
typeThe easing function type
Returns
true if initialization was successful.

◆ init() [4/4]

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.

Parameters
x1The x-coordinate of the first handle.
y1The y-coordinate of the first handle.
x2The x-coordinate of the second handle.
y2The y-coordinate of the second handle.
Returns
true if initialization was successful.

◆ solveCubicEquation()

void cugl::EasingBezier::solveCubicEquation ( float  a,
float  b,
float  c,
float  d 
)
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.

Parameters
aThe 3rd degree coefficient
bThe 2nd degree coefficient
cThe linear coefficient
dThe constant factor

◆ solveQuadraticEquation()

void cugl::EasingBezier::solveQuadraticEquation ( float  a,
float  b,
float  c 
)
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.

Parameters
aThe 2nd degree coefficient
bThe linear coefficient
cThe constant factor

Member Data Documentation

◆ _c1

Vec2 cugl::EasingBezier::_c1
protected

The C1 coefficient

◆ _c2

Vec2 cugl::EasingBezier::_c2
protected

The C2 coefficient

◆ _c3

Vec2 cugl::EasingBezier::_c3
protected

The C3 coefficient

◆ _rootset

std::vector<float> cugl::EasingBezier::_rootset
protected

The rootset of the polynomial x-component (cached for efficiency).


The documentation for this class was generated from the following file: