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;
31 Loader(Animation &, Collection &);
35 void event(const std::string &);
36 void event1i(const std::string &, int);
37 void event1f(const std::string &, float);
38 void event2f(const std::string &, float, float);
39 void event3f(const std::string &, float, float, float);
40 void event4f(const std::string &, float, float, float, float);
42 void keyframe(const std::string &);
43 void keyframe_inline();
47 struct AxisInterpolation
53 AxisInterpolation(const float *, const float *);
56 struct MatrixInterpolation
58 const Matrix *matrix1;
59 const Matrix *matrix2;
60 AxisInterpolation axes[3];
62 MatrixInterpolation();
63 MatrixInterpolation(const Matrix &, const Matrix &);
65 Matrix get(float) const;
70 const TimedKeyFrame *prev;
72 Time::TimeDelta delta_t;
73 RefPtr<const KeyFrame> keyframe;
74 MatrixInterpolation matrix;
75 std::vector<KeyFrame::AnimatedUniform> uniforms;
76 std::vector<MatrixInterpolation> pose_matrices;
79 void prepare(const Animation &);
94 UniformInfo(const std::string &, unsigned);
101 const Animation *animation;
102 std::vector<TimedKeyFrame>::const_iterator iter;
103 std::vector<Event>::const_iterator event_iter;
104 Time::TimeDelta time_since_keyframe;
108 Iterator(const Animation &);
110 Iterator &operator+=(const Time::TimeDelta &);
111 void dispatch_events(AnimationEventObserver &);
113 bool is_end() const { return end; }
114 Matrix get_matrix() const;
115 KeyFrame::AnimatedUniform get_uniform(unsigned) const;
116 Matrix get_pose_matrix(unsigned) const;
120 const Armature *armature;
121 std::vector<TimedKeyFrame> keyframes;
122 std::vector<Event> events;
124 std::vector<UniformInfo> uniforms;
130 void set_armature(const Armature &);
131 const Armature *get_armature() const { return armature; }
133 unsigned get_n_uniforms() const { return uniforms.size(); }
134 unsigned get_slot_for_uniform(const std::string &) const;
135 const std::string &get_uniform_name(unsigned) const;
137 void add_keyframe(const Time::TimeDelta &, const KeyFrame &);
139 void add_keyframe(const Time::TimeDelta &, const RefPtr<const KeyFrame> &);
140 void prepare_keyframe(TimedKeyFrame &);
142 void add_event(const Time::TimeDelta &, const std::string &, const Variant & = Variant());
144 void set_looping(bool);