Loading anim/include/anim/interpolator.hpp +15 −3 Original line number Diff line number Diff line Loading @@ -102,13 +102,18 @@ struct LinearInterpolator : public ValueInterpolator<T> { } }; enum BezierMethod { CARDANO, NEWTON_RAPHSON }; struct BezierHandles { vec2 leftHandle{0.2f, 0.0f}; // Relative position of the handle on the left side of the *SEGMENT* going out from the starting keyframe vec2 rightHandle{-0.2f, 0.0f}; // Relative position of the handle on the right side of the *SEGMENT* going into the ending keyframe }; // Concrete interpolator for bezier curves template <typename T> template <typename T, BezierMethod Method = NEWTON_RAPHSON> struct BezierInterpolator : public Interpolator<T> { BezierInterpolator(const BezierHandles& handles = BezierHandles{}) : m_handles(handles) {} InterpolationType getType() const override { return InterpolationType::BEZIER; } Loading @@ -122,8 +127,15 @@ struct BezierInterpolator : public Interpolator<T> { scalar t = p0.x + normalizedTime * (p3.x - p0.x); if constexpr (Method == NEWTON_RAPHSON) { return helpers::solveBezierNewtonRaphson(p0, p1, p2, p3, t); // return helpers::solveBezierCardano(p0, p1, p2, p3, t); } else if constexpr (Method == CARDANO) { return helpers::solveBezierCardano(p0, p1, p2, p3, t); } else { throw std::runtime_error("Unknown Bezier method!"); } } T interpolate(const Keyframe<T>& start, const Keyframe<T>& end, scalar normalizedTime) const override Loading Loading
anim/include/anim/interpolator.hpp +15 −3 Original line number Diff line number Diff line Loading @@ -102,13 +102,18 @@ struct LinearInterpolator : public ValueInterpolator<T> { } }; enum BezierMethod { CARDANO, NEWTON_RAPHSON }; struct BezierHandles { vec2 leftHandle{0.2f, 0.0f}; // Relative position of the handle on the left side of the *SEGMENT* going out from the starting keyframe vec2 rightHandle{-0.2f, 0.0f}; // Relative position of the handle on the right side of the *SEGMENT* going into the ending keyframe }; // Concrete interpolator for bezier curves template <typename T> template <typename T, BezierMethod Method = NEWTON_RAPHSON> struct BezierInterpolator : public Interpolator<T> { BezierInterpolator(const BezierHandles& handles = BezierHandles{}) : m_handles(handles) {} InterpolationType getType() const override { return InterpolationType::BEZIER; } Loading @@ -122,8 +127,15 @@ struct BezierInterpolator : public Interpolator<T> { scalar t = p0.x + normalizedTime * (p3.x - p0.x); if constexpr (Method == NEWTON_RAPHSON) { return helpers::solveBezierNewtonRaphson(p0, p1, p2, p3, t); // return helpers::solveBezierCardano(p0, p1, p2, p3, t); } else if constexpr (Method == CARDANO) { return helpers::solveBezierCardano(p0, p1, p2, p3, t); } else { throw std::runtime_error("Unknown Bezier method!"); } } T interpolate(const Keyframe<T>& start, const Keyframe<T>& end, scalar normalizedTime) const override Loading