1 #ifndef MSP_GL_ANIMATION_H_
2 #define MSP_GL_ANIMATION_H_
4 #include <msp/core/refptr.h>
5 #include <msp/datafile/objectloader.h>
6 #include <msp/interpolate/spline.h>
7 #include <msp/time/timedelta.h>
13 class AnimationEventObserver;
19 An Animation is a sequence of KeyFrames combined with timing information. The
20 state at any point in the animation can be interpolated from the keyframes.
25 class Loader: public DataFile::CollectionObjectLoader<Animation>
28 Time::TimeDelta current_time;
34 Loader(Animation &, Collection &);
37 virtual void finish();
39 void event(const std::string &);
40 void event1i(const std::string &, int);
41 void event1f(const std::string &, float);
42 void event2f(const std::string &, float, float);
43 void event3f(const std::string &, float, float, float);
44 void event4f(const std::string &, float, float, float, float);
46 void keyframe(const std::string &);
47 void keyframe_inline();
48 void slopes(float, float);
69 virtual void apply(float, Matrix &) const = 0;
70 virtual void apply(float, KeyFrame::AnimatedUniform &) const = 0;
74 class ValueCurve: public Curve
77 typedef typename Interpolate::SplineKnot<float, N> Knot;
80 Interpolate::Spline<float, 1, N> spline;
83 ValueCurve(CurveTarget, const std::vector<Knot> &);
85 virtual void apply(float, Matrix &) const;
86 virtual void apply(float, KeyFrame::AnimatedUniform &) const;
94 RefPtr<const KeyFrame> keyframe;
109 UniformInfo(const std::string &, unsigned);
116 const Animation *animation;
117 Time::TimeDelta elapsed;
118 std::vector<Event>::const_iterator event_iter;
122 Iterator(const Animation &);
124 Iterator &operator+=(const Time::TimeDelta &);
125 void dispatch_events(AnimationEventObserver &);
127 bool is_end() const { return end; }
128 Matrix get_matrix() const;
129 KeyFrame::AnimatedUniform get_uniform(unsigned) const;
130 Matrix get_pose_matrix(unsigned) const;
134 const Armature *armature;
135 std::vector<TimedKeyFrame> keyframes;
136 std::vector<Event> events;
138 std::vector<UniformInfo> uniforms;
139 std::vector<Curve *> curves;
145 void set_armature(const Armature &);
146 const Armature *get_armature() const { return armature; }
148 unsigned get_n_uniforms() const { return uniforms.size(); }
149 unsigned get_slot_for_uniform(const std::string &) const;
150 const std::string &get_uniform_name(unsigned) const;
152 void add_keyframe(const Time::TimeDelta &, const KeyFrame &);
153 void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float);
154 void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float, float);
156 void add_keyframe(const Time::TimeDelta &, const RefPtr<const KeyFrame> &, float, float);
157 void prepare_keyframe(TimedKeyFrame &);
158 void create_curves();
160 void create_uniform_curve(const std::string &);
162 void add_event(const Time::TimeDelta &, const std::string &, const Variant & = Variant());
164 const Msp::Time::TimeDelta &get_duration() const;
166 void set_looping(bool);