Created
September 25, 2013 09:42
-
-
Save vittorioromeo/6697349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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