]> git.tdb.fi Git - libs/gl.git/blobdiff - source/animation.h
Reimplement Animation using splines
[libs/gl.git] / source / animation.h
index c190bdbfd1cb11048020ad7ba06a44fff81d1a24..83b369bfca1f1e975df889de113d9655ca77db80 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <msp/core/refptr.h>
 #include <msp/datafile/objectloader.h>
+#include <msp/interpolate/spline.h>
 #include <msp/time/timedelta.h>
 #include "keyframe.h"
 
@@ -25,12 +26,15 @@ public:
        {
        private:
                Time::TimeDelta current_time;
+               float start_slope;
+               float end_slope;
 
        public:
                Loader(Animation &);
                Loader(Animation &, Collection &);
        private:
                void init();
+               virtual void finish();
 
                void event(const std::string &);
                void event1i(const std::string &, int);
@@ -38,45 +42,56 @@ public:
                void event2f(const std::string &, float, float);
                void event3f(const std::string &, float, float, float);
                void event4f(const std::string &, float, float, float, float);
+               void interval(float);
                void keyframe(const std::string &);
                void keyframe_inline();
-               void interval(float);
+               void slopes(float, float);
        };
 
 private:
-       struct AxisInterpolation
+       enum CurveTarget
        {
-               float slope;
-               float scale;
+               POSITION,
+               EULER,
+               SCALE,
+               UNIFORM
+       };
+
+       class Curve
+       {
+       protected:
+               CurveTarget target;
+
+               Curve(CurveTarget);
+       public:
+               virtual ~Curve() { }
 
-               AxisInterpolation();
-               AxisInterpolation(const float *, const float *);
+               virtual void apply(float, Matrix &) const = 0;
+               virtual void apply(float, KeyFrame::AnimatedUniform &) const = 0;
        };
 
-       struct MatrixInterpolation
+       template<unsigned N>
+       class ValueCurve: public Curve
        {
-               const Matrix *matrix1;
-               const Matrix *matrix2;
-               AxisInterpolation axes[3];
+       public:
+               typedef typename Interpolate::SplineKnot<float, N> Knot;
+
+       private:
+               Interpolate::Spline<float, 1, N> spline;
 
-               MatrixInterpolation();
-               MatrixInterpolation(const Matrix &, const Matrix &);
+       public:
+               ValueCurve(CurveTarget, const std::vector<Knot> &);
 
-               Matrix get(float) const;
+               virtual void apply(float, Matrix &) const;
+               virtual void apply(float, KeyFrame::AnimatedUniform &) const;
        };
 
        struct TimedKeyFrame
        {
-               const TimedKeyFrame *prev;
                Time::TimeDelta time;
-               Time::TimeDelta delta_t;
+               float start_slope;
+               float end_slope;
                RefPtr<const KeyFrame> keyframe;
-               MatrixInterpolation matrix;
-               std::vector<KeyFrame::AnimatedUniform> uniforms;
-               std::vector<MatrixInterpolation> pose_matrices;
-
-               TimedKeyFrame();
-               void prepare(const Animation &);
        };
 
        struct Event
@@ -99,9 +114,8 @@ public:
        {
        private:
                const Animation *animation;
-               std::vector<TimedKeyFrame>::const_iterator iter;
+               Time::TimeDelta elapsed;
                std::vector<Event>::const_iterator event_iter;
-               Time::TimeDelta time_since_keyframe;
                bool end;
 
        public:
@@ -122,6 +136,7 @@ private:
        std::vector<Event> events;
        bool looping;
        std::vector<UniformInfo> uniforms;
+       std::vector<Curve *> curves;
 
 public:
        Animation();
@@ -135,12 +150,19 @@ public:
        const std::string &get_uniform_name(unsigned) const;
 
        void add_keyframe(const Time::TimeDelta &, const KeyFrame &);
+       void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float);
+       void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float, float);
 private:
-       void add_keyframe(const Time::TimeDelta &, const RefPtr<const KeyFrame> &);
+       void add_keyframe(const Time::TimeDelta &, const RefPtr<const KeyFrame> &, float, float);
        void prepare_keyframe(TimedKeyFrame &);
+       void create_curves();
+       template<unsigned N>
+       void create_uniform_curve(const std::string &);
 public:
        void add_event(const Time::TimeDelta &, const std::string &, const Variant & = Variant());
 
+       const Msp::Time::TimeDelta &get_duration() const;
+
        void set_looping(bool);
 };