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_pose_matrix(unsigned link, const Matrix &m)
33 if(link*16>=pose_data.size())
34 pose_data.resize((link+1)*16);
35 copy(m.data(), m.data()+16, &pose_data[link*16]);
36 shdata->uniform_matrix4_array("pose", pose_data.size()/16, &pose_data[0]);
40 ProgramData &AnimatedObject::get_shader_data()
43 throw invalid_operation("AnimatedObject::get_shader_data");
47 const ProgramData &AnimatedObject::get_shader_data() const
50 throw invalid_operation("AnimatedObject::get_shader_data");
54 void AnimatedObject::set_uniform(const string &name, const KeyFrame::AnimatedUniform &uni)
57 throw invalid_operation("AnimatedObject::set_uniform");
60 shdata->uniform(name, uni.values[0]);
62 shdata->uniform2(name, uni.values);
64 shdata->uniform3(name, uni.values);
66 shdata->uniform4(name, uni.values);
68 throw invalid_argument("AnimatedObject::set_uniform");
71 void AnimatedObject::setup_render(Renderer &renderer, Tag) const
73 renderer.transform(matrix);
75 renderer.add_shader_data(*shdata);
79 AnimatedObject::Loader::Loader(AnimatedObject &o):
80 DataFile::DerivedObjectLoader<AnimatedObject, ObjectInstance::Loader>(o)
82 // Deprecated; Use the transform statement defined in ObjectInstance instead
83 add("position", &Loader::position);
84 add("rotation", &Loader::rotation);
85 add("scale", &Loader::scale);
86 add("scale", &Loader::scale_uniform);
89 void AnimatedObject::Loader::position(float x, float y, float z)
91 obj.matrix.translate(x, y, z);
94 void AnimatedObject::Loader::rotation(float a, float x, float y, float z)
96 obj.matrix.rotate_deg(a, x, y, z);
99 void AnimatedObject::Loader::scale(float x, float y, float z)
101 obj.matrix.scale(x, y, z);
104 void AnimatedObject::Loader::scale_uniform(float s)