X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fanimation.h;h=83b369bfca1f1e975df889de113d9655ca77db80;hp=dd3cc688c41290316450858a7d540a79e93dcfb8;hb=025016d7628be9c43b20999325dcbaae5cb3c3b8;hpb=89a1ada18430079896cfb28862e61bb32d66b8a0 diff --git a/source/animation.h b/source/animation.h index dd3cc688..83b369bf 100644 --- a/source/animation.h +++ b/source/animation.h @@ -3,12 +3,14 @@ #include #include +#include #include #include "keyframe.h" namespace Msp { namespace GL { +class AnimationEventObserver; class Armature; class Matrix; class Pose; @@ -24,52 +26,79 @@ 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); + void event1f(const std::string &, float); + 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 + { + POSITION, + EULER, + SCALE, + UNIFORM + }; + + class Curve { - float slope; - float scale; + 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 + class ValueCurve: public Curve { - const Matrix *matrix1; - const Matrix *matrix2; - AxisInterpolation axes[3]; + public: + typedef typename Interpolate::SplineKnot Knot; - MatrixInterpolation(); - MatrixInterpolation(const Matrix &, const Matrix &); + private: + Interpolate::Spline spline; - Matrix get(float) const; + public: + ValueCurve(CurveTarget, const std::vector &); + + 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 keyframe; - MatrixInterpolation matrix; - std::vector uniforms; - std::vector pose_matrices; + }; - TimedKeyFrame(); - void prepare(const Animation &); + struct Event + { + Time::TimeDelta time; + std::string name; + Variant value; }; struct UniformInfo @@ -85,14 +114,15 @@ public: { private: const Animation *animation; - std::vector::const_iterator iter; - Time::TimeDelta time_since_keyframe; + Time::TimeDelta elapsed; + std::vector::const_iterator event_iter; bool end; public: Iterator(const Animation &); Iterator &operator+=(const Time::TimeDelta &); + void dispatch_events(AnimationEventObserver &); bool is_end() const { return end; } Matrix get_matrix() const; @@ -103,8 +133,10 @@ public: private: const Armature *armature; std::vector keyframes; + std::vector events; bool looping; std::vector uniforms; + std::vector curves; public: Animation(); @@ -118,11 +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 &); + void add_keyframe(const Time::TimeDelta &, const RefPtr &, float, float); void prepare_keyframe(TimedKeyFrame &); - + void create_curves(); + template + 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); };