X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fanimation.h;h=7c277f430876e71a1738d039dda2852033639e68;hp=e3fb79ee3aff2bdcf019e79c03628066aed605c2;hb=22ed49c0b233566fc5d72b7c9769fd3ba543ab40;hpb=332352298ef41b8ac3a4c57b467dd146c0b05e0b diff --git a/source/animation.h b/source/animation.h index e3fb79ee..7c277f43 100644 --- a/source/animation.h +++ b/source/animation.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "keyframe.h" @@ -27,13 +28,22 @@ public: Time::TimeDelta current_time; float start_slope; float end_slope; + int slopes_set; public: Loader(Animation &); Loader(Animation &, Collection &); private: 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); @@ -47,41 +57,58 @@ 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 + 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; + + public: + ValueCurve(CurveTarget, const std::vector &); - Matrix get(float) const; + virtual void apply(float, Matrix &) const; + virtual void apply(float, KeyFrame::AnimatedUniform &) const; + }; + + template + struct ExtractUniform + { + const std::string &name; + + ExtractUniform(const std::string &n): name(n) { } + + bool operator()(const KeyFrame &, typename Interpolate::SplineValue::Type &) 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 &); + bool control; }; struct Event @@ -104,10 +131,8 @@ public: { private: const Animation *animation; - std::vector::const_iterator iter; + Time::TimeDelta elapsed; std::vector::const_iterator event_iter; - Time::TimeDelta time_since_keyframe; - float x; bool end; public: @@ -128,6 +153,7 @@ private: std::vector events; bool looping; std::vector uniforms; + std::vector curves; public: Animation(); @@ -141,14 +167,24 @@ 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); + 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 &); private: - void add_keyframe(const Time::TimeDelta &, const RefPtr &, 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 + void create_curve(CurveTarget target, 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); };