X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fanimation%2Fkeyframe.cpp;fp=source%2Fanimation%2Fkeyframe.cpp;h=f610de2d42afbd08dd118cf97e7f54afa75da7de;hb=7aaec9a70b8d7733429bec043f8e33e02956f266;hp=0000000000000000000000000000000000000000;hpb=bec07999d95b76f4b47cffcc564d0cd0afc0435e;p=libs%2Fgl.git diff --git a/source/animation/keyframe.cpp b/source/animation/keyframe.cpp new file mode 100644 index 00000000..f610de2d --- /dev/null +++ b/source/animation/keyframe.cpp @@ -0,0 +1,157 @@ +#include +#include "keyframe.h" +#include "pose.h" + +using namespace std; + +namespace Msp { +namespace GL { + +// Avoid synthesizing RefPtr c'tor and d'tor in files including keyframe.h +KeyFrame::KeyFrame() +{ } + +KeyFrame::~KeyFrame() +{ } + +void KeyFrame::set_transform(const Transform &t) +{ + transform = t; +} + +void KeyFrame::set_matrix(const Matrix &m) +{ + transform = Transform::from_matrix(m); +} + +void KeyFrame::set_uniform(const string &n, const AnimatedUniform &u) +{ + uniforms.erase(n); + uniforms.insert(UniformMap::value_type(n, u)); +} + +void KeyFrame::set_pose(const Pose &p) +{ + pose = &p; + pose.keep(); +} + + +KeyFrame::AnimatedUniform::AnimatedUniform(unsigned s, float v0, float v1, float v2, float v3): + size(s) +{ + values[0] = v0; + values[1] = v1; + values[2] = v2; + values[3] = v3; +} + + +KeyFrame::Loader::Loader(KeyFrame &k): + DataFile::CollectionObjectLoader(k, 0) +{ + init(); +} + +KeyFrame::Loader::Loader(KeyFrame &k, Collection &c): + DataFile::CollectionObjectLoader(k, &c) +{ + init(); +} + +void KeyFrame::Loader::init() +{ + add("pose", &Loader::pose); + add("pose", &Loader::pose_inline); + add("transform", &Loader::transform); + add("uniforms", &Loader::uniforms); + + // Deprecated; use the transform statement instead + add("position", &Loader::position); + add("rotation", &Loader::rotation); + add("scaling", &Loader::scaling_uniform); + add("scaling", &Loader::scaling); +} + +void KeyFrame::Loader::pose(const string &n) +{ + obj.pose = &get_collection().get(n); + obj.pose.keep(); +} + +void KeyFrame::Loader::pose_inline() +{ + RefPtr p = new Pose; + load_sub(*p, get_collection()); + obj.pose = p; +} + +void KeyFrame::Loader::position(float x, float y, float z) +{ + obj.transform.set_position(Vector3(x, y, z)); +} + +void KeyFrame::Loader::rotation(float a, float x, float y, float z) +{ + obj.transform.set_rotation(Transform::Angle::from_degrees(a), Vector3(x, y, z)); +} + +void KeyFrame::Loader::scaling_uniform(float s) +{ + obj.transform.set_scale(s); +} + +void KeyFrame::Loader::scaling(float x, float y, float z) +{ + obj.transform.set_scale(Vector3(x, y, z)); +} + +void KeyFrame::Loader::transform() +{ + load_sub(obj.transform); +} + +void KeyFrame::Loader::uniforms() +{ + UniformsLoader ldr(obj); + load_sub_with(ldr); +} + + +KeyFrame::UniformsLoader::UniformsLoader(KeyFrame &k): + DataFile::ObjectLoader(k) +{ + add("uniform", &UniformsLoader::uniform1f); + add("uniform", &UniformsLoader::uniform2f); + add("uniform", &UniformsLoader::uniform3f); + add("uniform", &UniformsLoader::uniform4f); + + // Deprecated + add("uniform1f", &UniformsLoader::uniform1f); + add("uniform2f", &UniformsLoader::uniform2f); + add("uniform3f", &UniformsLoader::uniform3f); + add("uniform4f", &UniformsLoader::uniform4f); +} + +void KeyFrame::UniformsLoader::uniform1f(const string &n, float v) +{ + obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(1, v))); +} + +void KeyFrame::UniformsLoader::uniform2f(const string &n, float v0, float v1) +{ + obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(2, v0, v1))); +} + +void KeyFrame::UniformsLoader::uniform3f(const string &n, float v0, float v1, float v2) +{ + obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(3, v0, v1, v2))); +} + +void KeyFrame::UniformsLoader::uniform4f(const string &n, float v0, float v1, float v2, float v3) +{ + obj.uniforms.insert(UniformMap::value_type(n, AnimatedUniform(4, v0, v1, v2, v3))); +} + +} // namespace GL +} // namespace Msp