This documents an old version of bs::framework. Click here to see the latest release.
TAnimationCurve< T > Class Template Reference

Description

template<class T>
class bs::TAnimationCurve< T >

Animation spline represented by a set of keyframes, each representing an endpoint of a cubic hermite curve.

The spline can be evaluated at any time, and uses caching to speed up multiple sequential evaluations.

Methods

 TAnimationCurve (const Vector< KeyFrame > &keyframes)
 Creates a new animation curve. More...
 
evaluate (float time, const TCurveCache< T > &cache, bool loop=true) const
 Evaluate the animation curve using caching. More...
 
evaluate (float time, bool loop=true) const
 Evaluate the animation curve at the specified time. More...
 
evaluateIntegrated (float time, const TCurveIntegrationCache< T > &integrationCache) const
 Evaluates the integrated animation curve. More...
 
evaluateIntegratedDouble (float time, const TCurveIntegrationCache< T > &integrationCache) const
 Evaluates the double integrated animation curve. More...
 
KeyFrame evaluateKey (float time, bool loop=true) const
 Evaluate the animation curve at the specified time and returns a new keyframe containing the evaluated value and tangents. More...
 
TAnimationCurve< T > split (float start, float end)
 Splits a piece of the animation curve into a separate animation curve. More...
 
void makeAdditive ()
 Converts a normal curve into an additive curve. More...
 
std::pair< float, float > getTimeRange () const
 Returns the time of the first and last keyframe in the curve. More...
 
std::pair< T, T > calculateRange () const
 Calculates the minimal and maximal value of the curve. More...
 
std::pair< T, T > calculateRangeIntegrated (const TCurveIntegrationCache< T > &cache) const
 Calculates the minimal and maximal value of the integrated curve. More...
 
std::pair< T, T > calculateRangeIntegratedDouble (const TCurveIntegrationCache< T > &cache) const
 Calculates the minimal and maximal value of the doubly integrated curve. More...
 
float getLength () const
 Returns the length of the animation curve, from time zero to last keyframe. More...
 
UINT32 getNumKeyFrames () const
 Returns the total number of key-frames in the curve. More...
 
const TKeyframe< T > & getKeyFrame (UINT32 idx) const
 Returns a keyframe at the specified index. More...
 
const Vector< TKeyframe< T > > & getKeyFrames () const
 Returns a list of all keyframes in the curve. More...
 

Public Types

typedef TKeyframe< T > KeyFrame
 

Method documentation

◆ calculateRange()

std::pair<T, T> calculateRange ( ) const

Calculates the minimal and maximal value of the curve.

◆ calculateRangeIntegrated()

std::pair<T, T> calculateRangeIntegrated ( const TCurveIntegrationCache< T > &  cache) const

Calculates the minimal and maximal value of the integrated curve.

◆ calculateRangeIntegratedDouble()

std::pair<T, T> calculateRangeIntegratedDouble ( const TCurveIntegrationCache< T > &  cache) const

Calculates the minimal and maximal value of the doubly integrated curve.

◆ evaluate() [1/2]

T evaluate ( float  time,
const TCurveCache< T > &  cache,
bool  loop = true 
) const

Evaluate the animation curve using caching.

Caching can significantly speed of evaluation if the evaluation happens sequential order (which should be true for most curves). If evaluation is not happening in sequential order using the non-caching version of evaluate() might yield better performance.

Parameters
[in]timeTime to evaluate the curve at.
[in]cacheCached data from previous requests that can be used for speeding up sequential calls to this method. Caller should ensure to maintain a persistent instance of this data for every animation using this curve in order to ensure cache is maintained.
[in]loopIf true the curve will loop when it goes past the end or beggining. Otherwise the curve value will be clamped.
Returns
Interpolated value from the curve at provided time.

◆ evaluate() [2/2]

T evaluate ( float  time,
bool  loop = true 
) const

Evaluate the animation curve at the specified time.

If evaluating multiple values in a sequential order consider using the cached version of evaluate() for better performance.

Parameters
[in]timeTime to evaluate the curve at.
[in]loopIf true the curve will loop when it goes past the end or beggining. Otherwise the curve value will be clamped.
Returns
Interpolated value from the curve at provided time.

◆ evaluateIntegrated()

T evaluateIntegrated ( float  time,
const TCurveIntegrationCache< T > &  integrationCache 
) const

Evaluates the integrated animation curve.

(e.g. evaluating a curve containing velocity values will return a position).

Parameters
[in]timeTime to evaluate the curve at.
[in]integrationCacheCache storing the values required for integration. Generated the first time this method is called and re-used on subsequent calls. Caller must ensure to use the cache only with the curve it was originally used on. Separate caches need to be used for single and double integration evaluation.
Returns
Interpolated value from the curve at provided time.

◆ evaluateIntegratedDouble()

T evaluateIntegratedDouble ( float  time,
const TCurveIntegrationCache< T > &  integrationCache 
) const

Evaluates the double integrated animation curve.

(e.g. evaluating a curve containing acceleration values will return a position).

Parameters
[in]timeTime to evaluate the curve at.
[in]integrationCacheCache storing the values required for integration. Generated the first time this method is called and re-used on subsequent calls. Caller must ensure to use the cache only with the curve it was originally used on. Separate caches need to be used for single and double integration evaluation.
Returns
Interpolated value from the curve at provided time.

◆ evaluateKey()

KeyFrame evaluateKey ( float  time,
bool  loop = true 
) const

Evaluate the animation curve at the specified time and returns a new keyframe containing the evaluated value and tangents.

Parameters
[in]timeTime to evaluate the curve at.
[in]loopIf true the curve will loop when it goes past the end or beggining. Otherwise the curve value will be clamped.
Returns
Keyframe containing the interpolated value and tangents at provided time.

◆ getKeyFrame()

const TKeyframe<T>& getKeyFrame ( UINT32  idx) const

Returns a keyframe at the specified index.

◆ getKeyFrames()

const Vector<TKeyframe<T> >& getKeyFrames ( ) const

Returns a list of all keyframes in the curve.

◆ getLength()

float getLength ( ) const

Returns the length of the animation curve, from time zero to last keyframe.

◆ getNumKeyFrames()

UINT32 getNumKeyFrames ( ) const

Returns the total number of key-frames in the curve.

◆ getTimeRange()

std::pair<float, float> getTimeRange ( ) const

Returns the time of the first and last keyframe in the curve.

◆ makeAdditive()

void makeAdditive ( )

Converts a normal curve into an additive curve.

It is assumed the first keyframe in the curve is the reference key from which to generate the additive curve. Such curves can then be added on top of a curve containing reference keys.

◆ split()

TAnimationCurve<T> split ( float  start,
float  end 
)

Splits a piece of the animation curve into a separate animation curve.

Parameters
[in]startBeginning time of the split curve.
[in]endEnd time of the split curve.
Returns
New curve with data corresponding to the provided split times.

Constructor & Destructor Documentation

◆ TAnimationCurve()

TAnimationCurve ( const Vector< KeyFrame > &  keyframes)

Creates a new animation curve.

Parameters
[in]keyframesKeyframes to initialize the curve with. They must be sorted by time.