1 #include <msp/datafile/collection.h>
15 Pose::Pose(const Armature &a):
21 void Pose::set_armature(const Armature &a)
24 throw invalid_operation("Pose::set_armature");
26 links.resize(armature->get_max_link_index()+1);
29 void Pose::rotate_link(unsigned i, float angle, const Vector3 &axis)
32 throw out_of_range("Pose::rotate_link");
34 const Armature::Link &arm_link = armature->get_link(i);
35 links[i].local_matrix.rotate(angle, axis);
37 // Keep the base point stationary
38 Vector3 base = arm_link.get_base();
39 Vector3 new_base = links[i].local_matrix*base;
40 links[i].local_matrix = Matrix::translation(base-new_base)*links[i].local_matrix;
42 if(const Armature::Link *parent = arm_link.get_parent())
43 links[i].matrix = links[parent->get_index()].matrix*links[i].local_matrix;
45 // XXX apply matrix to descendants of the link
48 const Matrix &Pose::get_link_matrix(unsigned i) const
51 throw out_of_range("Pose::get_link_matrix");
52 return links[i].matrix;
56 Pose::Loader::Loader(Pose &p, Collection &c):
57 DataFile::CollectionObjectLoader<Pose>(p, &c)
59 add("armature", &Loader::armature);
60 add("link", &Loader::link);
63 void Pose::Loader::armature(const string &n)
65 obj.set_armature(get_collection().get<Armature>(n));
68 void Pose::Loader::link(const string &n)
71 throw logic_error("Armature must be specified first");
72 LinkLoader ldr(obj, obj.armature->get_link(n).get_index());
77 Pose::LinkLoader::LinkLoader(Pose &p, unsigned l):
78 DataFile::ObjectLoader<Pose>(p),
81 add("rotation", &LinkLoader::rotation);
84 void Pose::LinkLoader::rotation(float a, float x, float y, float z)
86 obj.rotate_link(link_index, a, Vector3(x, y, z));