2 #include <msp/strings/format.h>
3 #include "animatedobject.h"
6 #include "programdata.h"
16 AnimatedObject::AnimatedObject(const Object &o):
20 if(const Technique *tech = object.get_technique())
21 if(tech->has_shaders())
22 shdata = new ProgramData;
25 AnimatedObject::~AnimatedObject()
30 void AnimatedObject::set_pose_matrix(unsigned link, const Matrix &m)
34 if(link*16>=pose_data.size())
35 pose_data.resize((link+1)*16);
36 copy(m.data(), m.data()+16, &pose_data[link*16]);
37 shdata->uniform_matrix4_array("pose", pose_data.size()/16, &pose_data[0]);
41 ProgramData &AnimatedObject::get_shader_data()
44 throw invalid_operation("AnimatedObject::get_shader_data");
48 const ProgramData &AnimatedObject::get_shader_data() const
51 throw invalid_operation("AnimatedObject::get_shader_data");
55 void AnimatedObject::set_uniform(const string &name, const KeyFrame::AnimatedUniform &uni)
58 throw invalid_operation("AnimatedObject::set_uniform");
61 shdata->uniform(name, uni.values[0]);
63 shdata->uniform2(name, uni.values);
65 shdata->uniform3(name, uni.values);
67 shdata->uniform4(name, uni.values);
69 throw invalid_argument("AnimatedObject::set_uniform");
72 void AnimatedObject::setup_render(Renderer &renderer, const Tag &) const
74 renderer.transform(matrix);
76 renderer.add_shader_data(*shdata);
80 AnimatedObject::Loader::Loader(AnimatedObject &o):
81 DataFile::ObjectLoader<AnimatedObject>(o)
83 add("transform", &Loader::transform);
85 // Deprecated; Use the transform statement instead
86 add("position", &Loader::position);
87 add("rotation", &Loader::rotation);
88 add("scale", &Loader::scale);
89 add("scale", &Loader::scale_uniform);
92 void AnimatedObject::Loader::position(float x, float y, float z)
94 obj.matrix.translate(x, y, z);
97 void AnimatedObject::Loader::rotation(float a, float x, float y, float z)
99 obj.matrix.rotate_deg(a, x, y, z);
102 void AnimatedObject::Loader::scale(float x, float y, float z)
104 obj.matrix.scale(x, y, z);
107 void AnimatedObject::Loader::scale_uniform(float s)
112 void AnimatedObject::Loader::transform()
116 obj.matrix = trn.to_matrix();