Better handle interpolation when setting interpolation time to 0

Prevent NaNs from appearing when selecting a linear flight distance of 0 (closes #1329)
This commit is contained in:
Alexander Bock
2020-10-21 00:53:12 +02:00
parent a93b5fdf10
commit 8cf5f96392
3 changed files with 22 additions and 4 deletions

View File

@@ -51,6 +51,7 @@ public:
private:
std::function<T(float)> _transferFunction;
bool _isInterpolating = false;
float _t = 1.f;
float _interpolationTime = 1.f;
float _scaledDeltaTime = 0.f;

View File

@@ -34,16 +34,28 @@ Interpolator<T>::Interpolator()
template <typename T>
void Interpolator<T>::start() {
_t = 0.f;
_isInterpolating = true;
}
template <typename T>
void Interpolator<T>::end() {
_t = 1.f;
_isInterpolating = false;
}
template <typename T>
void Interpolator<T>::setDeltaTime(float deltaTime) {
_scaledDeltaTime = deltaTime / _interpolationTime;
if (_interpolationTime > 0.f) {
_scaledDeltaTime = deltaTime / _interpolationTime;
}
else {
if (deltaTime > 0.f) {
_scaledDeltaTime = 1.f;
}
else {
_scaledDeltaTime = -1.f;
}
}
}
template <typename T>
@@ -59,7 +71,7 @@ void Interpolator<T>::setInterpolationTime(float interpolationTime) {
template <typename T>
void Interpolator<T>::step() {
_t += _scaledDeltaTime;
_t = glm::clamp(_t, 0.0f, 1.0f);
_t = glm::clamp(_t, 0.f, 1.f);
}
template <typename T>
@@ -74,7 +86,7 @@ T Interpolator<T>::value() const {
template <typename T>
bool Interpolator<T>::isInterpolating() const {
return (_t < 1.f) && (_t >= 0.f);
return _isInterpolating;
}
} // namespace openspace::interaction