]> git.tdb.fi Git - libs/gl.git/blobdiff - source/animation/keyframe.h
Rearrange soucre files into subdirectories
[libs/gl.git] / source / animation / keyframe.h
diff --git a/source/animation/keyframe.h b/source/animation/keyframe.h
new file mode 100644 (file)
index 0000000..5b748ad
--- /dev/null
@@ -0,0 +1,82 @@
+#ifndef MSP_GL_KEYFRAME_H_
+#define MSP_GL_KEYFRAME_H_
+
+#include <msp/core/refptr.h>
+#include <msp/datafile/objectloader.h>
+#include "matrix.h"
+#include "transform.h"
+
+namespace Msp {
+namespace GL {
+
+class Pose;
+
+/**
+Keyframes are used to encapsulate object state for animation.
+*/
+class KeyFrame
+{
+public:
+       class Loader: public DataFile::CollectionObjectLoader<KeyFrame>
+       {
+       public:
+               Loader(KeyFrame &);
+               Loader(KeyFrame &, Collection &);
+       private:
+               void init();
+
+               void pose(const std::string &);
+               void pose_inline();
+               void position(float, float, float);
+               void rotation(float, float, float, float);
+               void scaling_uniform(float);
+               void scaling(float, float, float);
+               void transform();
+               void uniforms();
+       };
+
+       class UniformsLoader: public DataFile::ObjectLoader<KeyFrame>
+       {
+       public:
+               UniformsLoader(KeyFrame &);
+
+       private:
+               void uniform1f(const std::string &, float);
+               void uniform2f(const std::string &, float, float);
+               void uniform3f(const std::string &, float, float, float);
+               void uniform4f(const std::string &, float, float, float, float);
+       };
+
+       struct AnimatedUniform
+       {
+               unsigned size;
+               float values[4];
+
+               AnimatedUniform(unsigned, float, float = 0.0f, float = 0.0f, float = 0.0f);
+       };
+
+       typedef std::map<std::string, AnimatedUniform> UniformMap;
+
+private:
+       Transform transform;
+       UniformMap uniforms;
+       RefPtr<const Pose> pose;
+
+public:
+       KeyFrame();
+       ~KeyFrame();
+
+       void set_transform(const Transform &);
+       void set_matrix(const Matrix &);
+       void set_uniform(const std::string &, const AnimatedUniform &);
+       void set_pose(const Pose &);
+       const Transform &get_transform() const { return transform; }
+       Matrix get_matrix() const { return transform.to_matrix(); }
+       const UniformMap &get_uniforms() const { return uniforms; }
+       const Pose *get_pose() const { return pose.get(); }
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif