X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fanimation.h;h=92c177b685fead92aa15ee34c8721af1e16e4924;hp=e3fb79ee3aff2bdcf019e79c03628066aed605c2;hb=ff85f90d33023d908c534b0bf5d9a65e9fc2cce2;hpb=332352298ef41b8ac3a4c57b467dd146c0b05e0b diff --git a/source/animation.h b/source/animation.h index e3fb79ee..92c177b6 100644 --- a/source/animation.h +++ b/source/animation.h @@ -3,6 +3,7 @@ #include #include +#include #include #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,59 @@ public: }; private: - struct AxisInterpolation + enum CurveTarget { - float slope; - float scale; + POSITION, + EULER, + SCALE, + UNIFORM + }; + + class Curve + { + protected: + CurveTarget target; + + Curve(CurveTarget); + public: + virtual ~Curve() { } + + virtual void apply(float, Matrix &) const = 0; + virtual void apply(float, KeyFrame::AnimatedUniform &) const = 0; + }; + + template + class ValueCurve: public Curve + { + public: + typedef typename Interpolate::SplineKnot Knot; + + private: + Interpolate::Spline spline; - AxisInterpolation(); - AxisInterpolation(const float *, const float *); + public: + ValueCurve(CurveTarget, const std::vector &); + + virtual void apply(float, Matrix &) const; + virtual void apply(float, KeyFrame::AnimatedUniform &) const; }; - struct MatrixInterpolation + template + struct ExtractUniform { - const Matrix *matrix1; - const Matrix *matrix2; - AxisInterpolation axes[3]; + const std::string &name; - MatrixInterpolation(); - MatrixInterpolation(const Matrix &, const Matrix &); + ExtractUniform(const std::string &n): name(n) { } - Matrix get(float) const; + 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 &); }; struct Event @@ -104,10 +124,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 +146,7 @@ private: std::vector events; bool looping; std::vector uniforms; + std::vector curves; public: Animation(); @@ -146,9 +165,17 @@ public: private: void add_keyframe(const Time::TimeDelta &, const RefPtr &, float, float); 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); };