Skip to content

Instantly share code, notes, and snippets.

@vittorioromeo
Created September 25, 2013 09:42
Show Gist options
  • Save vittorioromeo/6697349 to your computer and use it in GitHub Desktop.
Save vittorioromeo/6697349 to your computer and use it in GitHub Desktop.
template<typename T> class PingPongValue
{
private:
T value, min, max, speed, dir{1};
public:
inline PingPongValue(T mMin, T mMax, T mSpeed) : value(mMin), min(mMin), max(mMax), speed(mSpeed) { }
inline void update(float mFT)
{
value += speed * mFT * dir;
if(value > max) { value = max; dir = -1; }
else if(value < min) { value = min; dir = 1; }
}
inline operator T() const noexcept { return value; }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment