From b0dfcfb5cdd73e7515170c0598d6b061d33446a7 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 23 Jun 2019 22:38:23 +0300 Subject: [PATCH] Use double for animation curves Since the t value is raised to the third power, floats with their 24-bit mantissa started to run out of precision around 30 seconds. Doubles should be good for several hours. If that somehow turns out to not be enough I'll invent some way to chain animations. --- source/animation.cpp | 13 +++++++------ source/animation.h | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/source/animation.cpp b/source/animation.cpp index 0e4bd3e6..37f583d5 100644 --- a/source/animation.cpp +++ b/source/animation.cpp @@ -234,6 +234,7 @@ void Animation::create_curve(CurveTarget target, int component, const T &extract typename Interpolate::SplineValue::Type value; if(extract(*i->keyframe, value)) { + typename Knot::Value dvalue = value; float x = i->time/Time::sec; if(i->control) { @@ -246,14 +247,14 @@ void Animation::create_curve(CurveTarget target, int component, const T &extract if(n_control==1) { typename Knot::Value cv = knots.back().y; - knots.back().y = (knots[knots.size()-2].y+cv*2.0f)/3.0f; - knots.push_back(Knot(x, (value+cv*2.0f)/3.0f)); + knots.back().y = (knots[knots.size()-2].y+cv*2.0)/3.0; + knots.push_back(Knot(x, (dvalue+cv*2.0)/3.0)); } else if(n_control==0 && !knots.empty()) { typename Knot::Value prev = knots.back().y; - knots.push_back(Knot(knots.back().x, (prev*2.0f+value)/3.0f)); - knots.push_back(Knot(x, (prev+value*2.0f)/3.0f)); + knots.push_back(Knot(knots.back().x, (prev*2.0+dvalue)/3.0)); + knots.push_back(Knot(x, (prev+dvalue*2.0)/3.0)); } n_control = 0; } @@ -318,7 +319,7 @@ Animation::Curve::Curve(CurveTarget t, int c): template Animation::ValueCurve::ValueCurve(CurveTarget t, int c, const vector &k): Curve(t, c), - spline(Interpolate::BezierSpline(k)) + spline(Interpolate::BezierSpline(k)) { } template @@ -372,7 +373,7 @@ template void Animation::ValueCurve::apply(float x, KeyFrame::AnimatedUniform &uni) const { uni.size = N; - typename Interpolate::Spline::Value value = spline(x); + typename Interpolate::Spline::Value value = spline(x); for(unsigned i=0; i::get(value, i); } diff --git a/source/animation.h b/source/animation.h index d053ee90..6845d23e 100644 --- a/source/animation.h +++ b/source/animation.h @@ -83,10 +83,10 @@ private: class ValueCurve: public Curve { public: - typedef typename Interpolate::SplineKnot Knot; + typedef typename Interpolate::SplineKnot Knot; private: - Interpolate::Spline spline; + Interpolate::Spline spline; public: ValueCurve(CurveTarget, int, const std::vector &); -- 2.45.2