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/time/timedelta.h>
12 class AnimationEventObserver;
18 An Animation is a sequence of KeyFrames combined with timing information. The
19 state at any point in the animation can be interpolated from the keyframes.
24 class Loader: public DataFile::CollectionObjectLoader<Animation>
27 Time::TimeDelta current_time;
33 Loader(Animation &, Collection &);
37 void event(const std::string &);
38 void event1i(const std::string &, int);
39 void event1f(const std::string &, float);
40 void event2f(const std::string &, float, float);
41 void event3f(const std::string &, float, float, float);
42 void event4f(const std::string &, float, float, float, float);
44 void keyframe(const std::string &);
45 void keyframe_inline();
46 void slopes(float, float);
50 struct AxisInterpolation
56 AxisInterpolation(const float *, const float *);
59 struct MatrixInterpolation
61 const Matrix *matrix1;
62 const Matrix *matrix2;
63 AxisInterpolation axes[3];
65 MatrixInterpolation();
66 MatrixInterpolation(const Matrix &, const Matrix &);
68 Matrix get(float) const;
73 const TimedKeyFrame *prev;
75 Time::TimeDelta delta_t;
78 RefPtr<const KeyFrame> keyframe;
79 MatrixInterpolation matrix;
80 std::vector<KeyFrame::AnimatedUniform> uniforms;
81 std::vector<MatrixInterpolation> pose_matrices;
84 void prepare(const Animation &);
99 UniformInfo(const std::string &, unsigned);
106 const Animation *animation;
107 std::vector<TimedKeyFrame>::const_iterator iter;
108 std::vector<Event>::const_iterator event_iter;
109 Time::TimeDelta time_since_keyframe;
114 Iterator(const Animation &);
116 Iterator &operator+=(const Time::TimeDelta &);
117 void dispatch_events(AnimationEventObserver &);
119 bool is_end() const { return end; }
120 Matrix get_matrix() const;
121 KeyFrame::AnimatedUniform get_uniform(unsigned) const;
122 Matrix get_pose_matrix(unsigned) const;
126 const Armature *armature;
127 std::vector<TimedKeyFrame> keyframes;
128 std::vector<Event> events;
130 std::vector<UniformInfo> uniforms;
136 void set_armature(const Armature &);
137 const Armature *get_armature() const { return armature; }
139 unsigned get_n_uniforms() const { return uniforms.size(); }
140 unsigned get_slot_for_uniform(const std::string &) const;
141 const std::string &get_uniform_name(unsigned) const;
143 void add_keyframe(const Time::TimeDelta &, const KeyFrame &);
144 void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float);
145 void add_keyframe(const Time::TimeDelta &, const KeyFrame &, float, float);
147 void add_keyframe(const Time::TimeDelta &, const RefPtr<const KeyFrame> &, float, float);
148 void prepare_keyframe(TimedKeyFrame &);
150 void add_event(const Time::TimeDelta &, const std::string &, const Variant & = Variant());
152 const Msp::Time::TimeDelta &get_duration() const;
154 void set_looping(bool);