]> git.tdb.fi Git - libs/gl.git/blobdiff - source/animation.h
Add public functions for adding owned keyframes to Animation
[libs/gl.git] / source / animation.h
index 83b369bfca1f1e975df889de113d9655ca77db80..d053ee9004835154acd8f22f3a91ab5655148c67 100644 (file)
@@ -28,6 +28,7 @@ public:
                Time::TimeDelta current_time;
                float start_slope;
                float end_slope;
+               int slopes_set;
 
        public:
                Loader(Animation &);
@@ -36,6 +37,13 @@ public:
                void init();
                virtual void finish();
 
+               void check_slopes_and_control(bool, bool);
+               void add_kf(const KeyFrame *, bool, bool);
+               void load_kf(const std::string &, bool);
+               void load_kf_inline(bool);
+
+               void control_keyframe(const std::string &);
+               void control_keyframe_inline();
                void event(const std::string &);
                void event1i(const std::string &, int);
                void event1f(const std::string &, float);
@@ -61,8 +69,9 @@ private:
        {
        protected:
                CurveTarget target;
+               int component;
 
-               Curve(CurveTarget);
+               Curve(CurveTarget, int);
        public:
                virtual ~Curve() { }
 
@@ -77,21 +86,43 @@ private:
                typedef typename Interpolate::SplineKnot<float, N> Knot;
 
        private:
-               Interpolate::Spline<float, 1, N> spline;
+               Interpolate::Spline<float, 3, N> spline;
 
        public:
-               ValueCurve(CurveTarget, const std::vector<Knot> &);
+               ValueCurve(CurveTarget, int, const std::vector<Knot> &);
 
                virtual void apply(float, Matrix &) const;
                virtual void apply(float, KeyFrame::AnimatedUniform &) const;
        };
 
+       struct ExtractComponent
+       {
+               typedef bool (*Extract)(const KeyFrame &, Vector3 &);
+
+               Extract extract;
+               unsigned index;
+               Transform::ComponentMask mask;
+
+               ExtractComponent(Extract e, unsigned i, Transform::ComponentMask m): extract(e), index(i), mask(m) { }
+
+               bool operator()(const KeyFrame &, float &) const;
+       };
+
+       template<unsigned N>
+       struct ExtractUniform
+       {
+               const std::string &name;
+
+               ExtractUniform(const std::string &n): name(n) { }
+
+               bool operator()(const KeyFrame &, typename Interpolate::SplineValue<float, N>::Type &) const;
+       };
+
        struct TimedKeyFrame
        {
                Time::TimeDelta time;
-               float start_slope;
-               float end_slope;
                RefPtr<const KeyFrame> keyframe;
+               bool control;
        };
 
        struct Event
@@ -137,6 +168,7 @@ private:
        bool looping;
        std::vector<UniformInfo> uniforms;
        std::vector<Curve *> curves;
+       unsigned uniform_curve_offset;
 
 public:
        Animation();
@@ -150,20 +182,29 @@ 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);
+       void add_keyframe_owned(const Time::TimeDelta &, const KeyFrame *);
+       DEPRECATED void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float);
+       DEPRECATED void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float, float);
+       void add_control_keyframe(const KeyFrame &);
+       void add_control_keyframe_owned(const KeyFrame *);
 private:
-       void add_keyframe(const Time::TimeDelta &, const RefPtr<const KeyFrame> &, float, float);
+       void add_keyframe(const Time::TimeDelta &, const KeyFrame *, float, float, bool);
+       void add_keyframe(const Time::TimeDelta &, const KeyFrame *, bool, bool);
        void prepare_keyframe(TimedKeyFrame &);
        void create_curves();
-       template<unsigned N>
-       void create_uniform_curve(const std::string &);
+       void create_curve(CurveTarget, Transform::ComponentMask, ExtractComponent::Extract);
+       template<unsigned N, typename T>
+       void create_curve(CurveTarget target, int, const T &);
+       static bool extract_position(const KeyFrame &, Vector3 &);
+       static bool extract_euler(const KeyFrame &, Vector3 &);
+       static bool extract_scale(const KeyFrame &, Vector3 &);
 public:
        void add_event(const Time::TimeDelta &, const std::string &, const Variant & = Variant());
 
        const Msp::Time::TimeDelta &get_duration() const;
 
        void set_looping(bool);
+       bool is_looping() const { return looping; }
 };
 
 } // namespace GL