C++ (Qt)double InterpolateValue( Curve * curve, double t ){ if (t >= MaxTime(curve)) ... if (t <= MinTime(curve)) ... switch (curve->splineType) { case SPLINE_LINEAR: return InterpolateLinear(curve, t); case SPLINE_RATIO: return InterpolateRatio(curve, t); ..... }}
C++ (Qt)struct Key { Key * prev, * next; ...};
C++ (Qt)typedef double CurveTime;
C++ (Qt)typedef float btReal;
C++ (Qt)class PointGenerator{ virtual double generate(Time time) = 0;}; class EditableCurve{ virtual void addKey(Time time, Key key) = 0; virtual void removeKey(Time time, Key key) = 0; virtual Key & keyAt(Time time) = 0;};
C++ (Qt)class CurveGenerator : public PointGenerator, public EditableCurve{ double generate(Time time) override; void addKey(Time time, Key key) override; void removeKey(Time time, Key key) override; Key & keyAt(Time time) override;};
C++ (Qt)class Interpolator{ virtual double interpolate(Time time) = 0; virtual Time keyTime() const = 0;};
C++ (Qt)template <class CurvePoint, class T>class RatioInterpolator : public Interpolator{ RatioInterpolator(Time keyTime, Key & key_1, Key & key_2, Key & key_3) : m_keyTime(keyTime), m_key_1(key_1), m_key_2(key_2), m_key_3(key_3) {} CurvePoint interpolate(Time time) override; Time keyTime() const override { return m_keyTime; } T inRatioVector; T outRatioVector; Time m_keyTime; Key & m_key_1; Key & m_key_2; Key & m_key_3;};
C++ (Qt)void DrawCurve( Curve * curve ){ Key * key = GetFirstKey(curve); while (key) { Key * next = GetNextKey(key); if (!next) break; DrawSegment(curve, key, next); key = next; }} void DrawSegment( Curve * curve, Key * key0, Key * key1 ){ Coordinate pos; double tStep = (GetKeyTime(key1) - GetKeyTime(key0)) / drawSteps; for (size_t i = 0; i < drawSteps; ++i) { InterpolateCurve(i * tStep, key0, key1, &pos); AddOpenGLVertex(pos); } }
C++ (Qt)void DrawCurve(PointGenerator * generator, Time from, Time to, Time step){ for (Time time = from; time <= to; time += step ) AddOpenGLVertex(generator->generate(time));}
C++ (Qt)class PointGenerator{ virtual double generate(Time time) = 0;};