2 #include <msp/strings/format.h>
3 #include "animatedobject.h"
6 #include "programdata.h"
15 AnimatedObject::AnimatedObject(const Object &o):
19 void AnimatedObject::set_pose_matrix(unsigned link, const Matrix &m)
21 if(link*16>=pose_data.size())
22 pose_data.resize((link+1)*16);
23 copy(m.data(), m.data()+16, &pose_data[link*16]);
24 shdata.uniform_matrix4_array("pose", pose_data.size()/16, &pose_data[0]);
27 void AnimatedObject::set_uniform(const string &name, const KeyFrame::AnimatedUniform &uni)
30 shdata.uniform(name, uni.values[0]);
32 shdata.uniform2(name, uni.values);
34 shdata.uniform3(name, uni.values);
36 shdata.uniform4(name, uni.values);
38 throw invalid_argument("AnimatedObject::set_uniform");
41 void AnimatedObject::setup_render(Renderer &renderer, Tag) const
43 renderer.set_matrix(matrix);
44 renderer.add_shader_data(shdata);
48 AnimatedObject::Loader::Loader(AnimatedObject &o):
49 DataFile::DerivedObjectLoader<AnimatedObject, ObjectInstance::Loader>(o)
51 // Deprecated; Use the transform statement defined in ObjectInstance instead
52 add("position", &Loader::position);
53 add("rotation", &Loader::rotation);
54 add("scale", &Loader::scale);
55 add("scale", &Loader::scale_uniform);
58 void AnimatedObject::Loader::position(float x, float y, float z)
60 obj.matrix.translate(x, y, z);
63 void AnimatedObject::Loader::rotation(float a, float x, float y, float z)
65 obj.matrix.rotate_deg(a, x, y, z);
68 void AnimatedObject::Loader::scale(float x, float y, float z)
70 obj.matrix.scale(x, y, z);
73 void AnimatedObject::Loader::scale_uniform(float s)