Game Development Reference
In-Depth Information
7.1.3 Interpolator
Theinterpolator istheobjectresponsibleforperformingtheinterpolation ofanyrunningan-
imations. It's reasonably straightforward, it maintains a list of user added animations and
updates them each frame.
class interpolator
{
public:
void Add(animation& anim)
{
m_activeAnimations.push_back(std::move(anim));
}
void Update(float deltaTime)
{
auto anim = m_activeAnimations.begin();
while ( anim != m_activeAnimations.end() )
{
anim->Update(deltaTime);
if ( anim->IsFinished() )
{
anim = m_activeAnimations.erase(anim);
}
else
{
++anim;
}
}
}
private:
std::list<animation> m_activeAnimations;
};
When an animation is added to the interpolator, it takes ownership of it by way of std::move
there is no need for animations to exist outside of the interpolator.
Updating each animation is trivial, the only thing to notice is that if after an animation's up-
date we determine that it has finished, we will erase it from the list.
7.1.4 Animations
Animations will hold the parameters that describe how an interpolation will behave. The
mainpropertieswillbethestartingvalue,theendingvalueandthedurationoftheanimation.
Search WWH ::




Custom Search