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>
17 An Animation is a sequence of KeyFrames combined with timing information. The
18 state at any point in the animation can be interpolated from the keyframes.
23 class Loader: public DataFile::CollectionObjectLoader<Animation>
26 Time::TimeDelta current_time;
30 Loader(Animation &, Collection &);
34 void keyframe(const std::string &);
35 void keyframe_inline();
40 struct AxisInterpolation
46 AxisInterpolation(const float *, const float *);
49 struct MatrixInterpolation
51 const Matrix *matrix1;
52 const Matrix *matrix2;
53 AxisInterpolation axes[3];
55 MatrixInterpolation();
56 MatrixInterpolation(const Matrix &, const Matrix &);
58 Matrix get(float) const;
63 const TimedKeyFrame *prev;
65 Time::TimeDelta delta_t;
66 RefPtr<const KeyFrame> keyframe;
67 MatrixInterpolation matrix;
68 std::vector<KeyFrame::AnimatedUniform> uniforms;
69 std::vector<MatrixInterpolation> pose_matrices;
72 void prepare(const Animation &);
80 UniformInfo(const std::string &, unsigned);
87 const Animation *animation;
88 std::vector<TimedKeyFrame>::const_iterator iter;
89 Time::TimeDelta time_since_keyframe;
93 Iterator(const Animation &);
95 Iterator &operator+=(const Time::TimeDelta &);
97 bool is_end() const { return end; }
98 Matrix get_matrix() const;
99 KeyFrame::AnimatedUniform get_uniform(unsigned) const;
100 Matrix get_pose_matrix(unsigned) const;
104 const Armature *armature;
105 std::vector<TimedKeyFrame> keyframes;
107 std::vector<UniformInfo> uniforms;
113 void set_armature(const Armature &);
114 const Armature *get_armature() const { return armature; }
116 unsigned get_n_uniforms() const { return uniforms.size(); }
117 unsigned get_slot_for_uniform(const std::string &) const;
118 const std::string &get_uniform_name(unsigned) const;
120 void add_keyframe(const Time::TimeDelta &, const KeyFrame &);
122 void add_keyframe(const Time::TimeDelta &, const RefPtr<const KeyFrame> &);
123 void prepare_keyframe(TimedKeyFrame &);
126 void set_looping(bool);