]> git.tdb.fi Git - libs/gl.git/blob - source/animation/keyframe.h
Add inline data items to the collection
[libs/gl.git] / source / animation / keyframe.h
1 #ifndef MSP_GL_KEYFRAME_H_
2 #define MSP_GL_KEYFRAME_H_
3
4 #include <msp/core/refptr.h>
5 #include <msp/datafile/objectloader.h>
6 #include "matrix.h"
7 #include "transform.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Pose;
13
14 /**
15 Keyframes are used to encapsulate object state for animation.
16 */
17 class KeyFrame
18 {
19 public:
20         class Loader: public DataFile::CollectionObjectLoader<KeyFrame>
21         {
22         private:
23                 std::string inline_base_name;
24
25         public:
26                 Loader(KeyFrame &);
27                 Loader(KeyFrame &, Collection &);
28         private:
29                 void init();
30
31         public:
32                 void set_inline_base_name(const std::string &);
33
34         private:
35                 void pose(const std::string &);
36                 void pose_inline();
37                 void position(float, float, float);
38                 void rotation(float, float, float, float);
39                 void scaling_uniform(float);
40                 void scaling(float, float, float);
41                 void transform();
42                 void uniforms();
43         };
44
45         class UniformsLoader: public DataFile::ObjectLoader<KeyFrame>
46         {
47         public:
48                 UniformsLoader(KeyFrame &);
49
50         private:
51                 void uniform1f(const std::string &, float);
52                 void uniform2f(const std::string &, float, float);
53                 void uniform3f(const std::string &, float, float, float);
54                 void uniform4f(const std::string &, float, float, float, float);
55         };
56
57         struct AnimatedUniform
58         {
59                 unsigned size;
60                 float values[4];
61
62                 AnimatedUniform(unsigned, float, float = 0.0f, float = 0.0f, float = 0.0f);
63         };
64
65         typedef std::map<std::string, AnimatedUniform> UniformMap;
66
67 private:
68         Transform transform;
69         UniformMap uniforms;
70         const Pose *pose;
71
72 public:
73         KeyFrame();
74         ~KeyFrame();
75
76         void set_transform(const Transform &);
77         void set_matrix(const Matrix &);
78         void set_uniform(const std::string &, const AnimatedUniform &);
79         void set_pose(const Pose &);
80         const Transform &get_transform() const { return transform; }
81         Matrix get_matrix() const { return transform.to_matrix(); }
82         const UniformMap &get_uniforms() const { return uniforms; }
83         const Pose *get_pose() const { return pose; }
84 };
85
86 } // namespace GL
87 } // namespace Msp
88
89 #endif