2 #include <msp/strings/format.h>
3 #include "animatedobject.h"
6 #include "programdata.h"
15 AnimatedObject::AnimatedObject(const Object &o):
19 if(const Technique *tech = object.get_technique())
20 if(tech->has_shaders())
21 shdata = new ProgramData;
24 AnimatedObject::~AnimatedObject()
29 void AnimatedObject::set_matrix(const Matrix &m)
34 void AnimatedObject::set_pose_matrix(unsigned link, const Matrix &m)
38 if(link*16>=pose_data.size())
39 pose_data.resize((link+1)*16);
40 copy(m.data(), m.data()+16, &pose_data[link*16]);
41 shdata->uniform_matrix4_array("pose", pose_data.size()/16, &pose_data[0]);
45 void AnimatedObject::set_uniform(const string &name, const KeyFrame::AnimatedUniform &uni)
48 throw invalid_operation("AnimatedObject::set_uniform");
51 shdata->uniform(name, uni.values[0]);
53 shdata->uniform2(name, uni.values);
55 shdata->uniform3(name, uni.values);
57 shdata->uniform4(name, uni.values);
59 throw invalid_argument("AnimatedObject::set_uniform");
62 void AnimatedObject::setup_render(Renderer &renderer, const Tag &) const
64 renderer.transform(matrix);
66 renderer.add_shader_data(*shdata);
70 AnimatedObject::Loader::Loader(AnimatedObject &o):
71 DataFile::ObjectLoader<AnimatedObject>(o)
73 add("position", &Loader::position);
74 add("rotation", &Loader::rotation);
75 add("scale", &Loader::scale);
76 add("scale", &Loader::scale_uniform);
79 void AnimatedObject::Loader::position(float x, float y, float z)
81 obj.matrix.translate(x, y, z);
84 void AnimatedObject::Loader::rotation(float a, float x, float y, float z)
86 obj.matrix.rotate_deg(a, x, y, z);
89 void AnimatedObject::Loader::scale(float x, float y, float z)
91 obj.matrix.scale(x, y, z);
94 void AnimatedObject::Loader::scale_uniform(float s)