mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-02 18:39:20 -06:00
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:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user