COGS
Computer Graphics Structures library
cogs::Interpolator< Type > Class Template Reference

Wrapper class for key frame animation offering effective interpolation between values in time. More...

Inheritance diagram for cogs::Interpolator< Type >:
[legend]

Public Member Functions

 Interpolator ()
 Creates an Action with no keys.
 
 Interpolator (const std::initializer_list< std::pair< float, Type >> &keys)
 Creates an Action from list of <time,value> pairs.
 
void Clear ()
 Deletes current all current key frames.
 
void ClearAndSet (const std::initializer_list< std::pair< float, Type >> &keys)
 Deletes current key array and sets up new array from list of <time,value> pairs.
 
bool IsEmpty () const
 Returns true when no key exist.
 
size_t GetKeyCount () const
 Returns number of key frames.
 
void InsertKey (const float time, Type value)
 Creates new key frame with specified value and inserts it into array.
 
Type GetValueAtTime (const float time) const
 Binary searches two keys nearest to specified time and interpolates between them. More...
 
Type GetValueAtTimeCubic (const float time) const
 
Type GetKeyValue (const size_t key_index) const
 Returns value of key on specified index (position in array ordered by time).
 
float GetTimeValue (const size_t key_index) const
 Returns time of key on specified index.
 
void SetKeyValue (const size_t key_index, const Type value)
 Returns value of key on specified index (position in array ordered by time).
 
float GetLastKeyTime () const
 Returns time of last existing key frame.
 
int32_t GetKeyBefore (const float time) const
 Returns index of key at, or immediately before specified time. More...
 
void Reserve (size_t keyframe_count)
 Reserves required memory for specified amount of key frames. Improves speed of adding new key frames.
 
void ShrinkToFit ()
 Releases allocated and not used memory for new frames.
 
void RemoveLastKey ()
 

Detailed Description

template<typename Type>
class cogs::Interpolator< Type >

Wrapper class for key frame animation offering effective interpolation between values in time.

Member Function Documentation

◆ GetKeyBefore()

template<typename Type>
int32_t cogs::Interpolator< Type >::GetKeyBefore ( const float  time) const
inline

Returns index of key at, or immediately before specified time.

Returns
A highest key index for which key.time <= time. Returns -1 if keys are empty or specified time is lower then time of any key.
Here is the caller graph for this function:

◆ GetValueAtTime()

template<typename Type>
Type cogs::Interpolator< Type >::GetValueAtTime ( const float  time) const
inline

Binary searches two keys nearest to specified time and interpolates between them.

Returns
Zero when keys are empty. Value of first key if time is lower or equal to the time of first key. Value of last key if time is higher or equal to the time of first key. Otherwise, an interpolated value between two closest keys.