vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::AnimationTrack< T > Class Template Reference

Keyframes of type T sorted by time, sampled through an easing curve. More...

#include <animation_track.h>

Public Member Functions

 AnimationTrack (Easing easing)
 Construct a track that interpolates with easing.
size_t addKeyframe (float time, const T &value)
 Add a keyframe at time.
void setKeyframe (float time, const T &value)
 Set the value at time, replacing any keyframe already there.
void removeKeyframe (size_t index)
 Remove the keyframe at index; out of range is a no-op.
void setKeyframeValue (size_t index, const T &value)
 Replace the value of the keyframe at index; out of range is a no-op.
size_t setKeyframeTime (size_t index, float time)
 Move the keyframe at index to time.
void setEasing (Easing easing)
 Choose the curve this track eases its interpolation with.
T getValue (float time) const
 Sample the track at time.
float getDuration () const
 The track's length.
Easing getEasing () const
 The curve this track eases with.
const std::vector< float > & getTimes () const
 The keyframe times, ascending.
const std::vector< T > & getValues () const
 The keyframe values, parallel to getTimes.

Static Public Attributes

static constexpr float SAME_INSTANT_SECONDS = 1e-4f
 Two keyframe times closer than this, in seconds, are one instant.

Detailed Description

template<typename T>
class Vkm::Engine::AnimationTrack< T >

Keyframes of type T sorted by time, sampled through an easing curve.

T is any type glm::mix accepts.

Template Parameters
TValue type, e.g. glm::vec3 or float.

Constructor & Destructor Documentation

◆ AnimationTrack()

template<typename T>
Vkm::Engine::AnimationTrack< T >::AnimationTrack ( Easing easing)
inlineexplicit

Construct a track that interpolates with easing.

Parameters
easingThe curve; see setEasing.

Member Function Documentation

◆ addKeyframe()

template<typename T>
size_t Vkm::Engine::AnimationTrack< T >::addKeyframe ( float time,
const T & value )
inline

Add a keyframe at time.

A keyframe at a time already held is added beside it, not replacing it; setKeyframe() re-keys.

Parameters
timeTime in the unit the track is read at, usually seconds.
valueValue at that time.
Returns
Index the sort put it at.

◆ setKeyframe()

template<typename T>
void Vkm::Engine::AnimationTrack< T >::setKeyframe ( float time,
const T & value )
inline

Set the value at time, replacing any keyframe already there.

Matches approximately, so re-keying an instant leaves no zero-length segment.

Parameters
timeTime to key at.
valueValue at that time.

◆ removeKeyframe()

template<typename T>
void Vkm::Engine::AnimationTrack< T >::removeKeyframe ( size_t index)
inline

Remove the keyframe at index; out of range is a no-op.

Parameters
indexKeyframe to remove.

◆ setKeyframeValue()

template<typename T>
void Vkm::Engine::AnimationTrack< T >::setKeyframeValue ( size_t index,
const T & value )
inline

Replace the value of the keyframe at index; out of range is a no-op.

Parameters
indexKeyframe to change.
valueNew value.

◆ setKeyframeTime()

template<typename T>
size_t Vkm::Engine::AnimationTrack< T >::setKeyframeTime ( size_t index,
float time )
inline

Move the keyframe at index to time.

The track stays sorted, so the keyframe's index may change.

Parameters
indexKeyframe to move; out of range is a no-op.
timeTime to move it to.
Returns
Its new index, or index when there was nothing to move.

◆ setEasing()

template<typename T>
void Vkm::Engine::AnimationTrack< T >::setEasing ( Easing easing)
inline

Choose the curve this track eases its interpolation with.

Parameters
easingThe curve, such as Easing::EaseInOutSine.

◆ getValue()

template<typename T>
T Vkm::Engine::AnimationTrack< T >::getValue ( float time) const
inline

Sample the track at time.

An empty track returns T{}; outside the keyframe range the nearest end value holds.

Parameters
timeTime in the track's unit.
Returns
The eased, interpolated value.

◆ getDuration()

template<typename T>
float Vkm::Engine::AnimationTrack< T >::getDuration ( ) const
inline

The track's length.

Returns
The last keyframe's time, or 0 for an empty track.

◆ getEasing()

template<typename T>
Easing Vkm::Engine::AnimationTrack< T >::getEasing ( ) const
inline

The curve this track eases with.

Returns
The curve.

◆ getTimes()

template<typename T>
const std::vector< float > & Vkm::Engine::AnimationTrack< T >::getTimes ( ) const
inline

The keyframe times, ascending.

Returns
One time per keyframe.

◆ getValues()

template<typename T>
const std::vector< T > & Vkm::Engine::AnimationTrack< T >::getValues ( ) const
inline

The keyframe values, parallel to getTimes.

Returns
One value per keyframe.

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