Last active
May 1, 2021 06:17
-
-
Save aalin/3c1c7e34c8293f546b71a0317acba630 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
#pragma once | |
#include <glm/glm.hpp> | |
template<typename T> | |
class Tween { | |
public: | |
Tween(float speed = 1.0) | |
: _value(T()), | |
_target(T()), | |
_speed(speed) { | |
} | |
const T & getValue() const { | |
return _value; | |
} | |
float getDistance() const { | |
return glm::distance(_value, _target); | |
} | |
void reset(T value) { | |
_value = value; | |
_target = value; | |
} | |
void setTarget(T target) { | |
_target = target; | |
} | |
void update(float delta) { | |
const float amount = glm::clamp(delta * _speed, 0.0f, 0.5f); | |
_value = glm::mix(_value, _target, amount); | |
} | |
private: | |
T _value; | |
T _target; | |
float _speed; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment