]> git.tdb.fi Git - libs/gl.git/blob - source/keyframe.h
Add a class to unify loading coordinate transforms
[libs/gl.git] / source / 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
8 namespace Msp {
9 namespace GL {
10
11 class Pose;
12
13 /**
14 Keyframes are used to encapsulate object state for animation.
15 */
16 class KeyFrame
17 {
18 public:
19         class Loader: public DataFile::CollectionObjectLoader<KeyFrame>
20         {
21         public:
22                 Loader(KeyFrame &);
23                 Loader(KeyFrame &, Collection &);
24         private:
25                 void init();
26
27                 void pose(const std::string &);
28                 void pose_inline();
29                 void position(float, float, float);
30                 void rotation(float, float, float, float);
31                 void scaling_uniform(float);
32                 void scaling(float, float, float);
33                 void transform();
34                 void uniforms();
35         };
36
37         class UniformsLoader: public DataFile::ObjectLoader<KeyFrame>
38         {
39         public:
40                 UniformsLoader(KeyFrame &);
41
42         private:
43                 void uniform1f(const std::string &, float);
44                 void uniform2f(const std::string &, float, float);
45                 void uniform3f(const std::string &, float, float, float);
46                 void uniform4f(const std::string &, float, float, float, float);
47         };
48
49         struct AnimatedUniform
50         {
51                 unsigned size;
52                 float values[4];
53
54                 AnimatedUniform(unsigned, float, float = 0.0f, float = 0.0f, float = 0.0f);
55         };
56
57         typedef std::map<std::string, AnimatedUniform> UniformMap;
58
59 private:
60         Matrix matrix;
61         UniformMap uniforms;
62         RefPtr<const Pose> pose;
63
64 public:
65         KeyFrame();
66         ~KeyFrame();
67
68         void set_matrix(const Matrix &);
69         void set_pose(const Pose &);
70         const Matrix &get_matrix() const { return matrix; }
71         const UniformMap &get_uniforms() const { return uniforms; }
72         const Pose *get_pose() const { return pose.get(); }
73 };
74
75 } // namespace GL
76 } // namespace Msp
77
78 #endif