]> git.tdb.fi Git - libs/gl.git/blobdiff - source/animation.h
Reimplement Animation using splines
[libs/gl.git] / source / animation.h
index b9e9fe1f3d1bd25e7a10efd3c0d7648eadd75000..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"
 
@@ -33,6 +34,7 @@ public:
                Loader(Animation &, Collection &);
        private:
                void init();
+               virtual void finish();
 
                void event(const std::string &);
                void event1i(const std::string &, int);
@@ -47,41 +49,49 @@ public:
        };
 
 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;
 
-               MatrixInterpolation();
-               MatrixInterpolation(const Matrix &, const Matrix &);
+       private:
+               Interpolate::Spline<float, 1, N> spline;
 
-               Matrix get(float) const;
+       public:
+               ValueCurve(CurveTarget, const std::vector<Knot> &);
+
+               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
@@ -104,10 +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;
-               float x;
                bool end;
 
        public:
@@ -128,6 +136,7 @@ private:
        std::vector<Event> events;
        bool looping;
        std::vector<UniformInfo> uniforms;
+       std::vector<Curve *> curves;
 
 public:
        Animation();
@@ -146,6 +155,9 @@ public:
 private:
        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());