1 #include <msp/datafile/collection.h>
11 Pose::Pose(const Armature &a)
16 void Pose::set_armature(const Armature &a)
19 throw invalid_operation("Pose::set_armature");
21 links.resize(armature->get_max_link_index()+1);
24 void Pose::rotate_link(unsigned i, float angle, const Vector3 &axis)
27 throw out_of_range("Pose::rotate_link");
29 const Armature::Link &arm_link = armature->get_link(i);
30 links[i].local_matrix.rotate(angle, axis);
32 // Keep the base point stationary
33 Vector3 base = arm_link.get_base();
34 Vector3 new_base = links[i].local_matrix*base;
35 links[i].local_matrix = Matrix::translation(base-new_base)*links[i].local_matrix;
37 if(const Armature::Link *parent = arm_link.get_parent())
38 links[i].matrix = links[parent->get_index()].matrix*links[i].local_matrix;
40 // XXX apply matrix to descendants of the link
43 const Matrix &Pose::get_link_matrix(unsigned i) const
46 throw out_of_range("Pose::get_link_matrix");
47 return links[i].matrix;
51 Pose::Loader::Loader(Pose &p, Collection &c):
52 DataFile::CollectionObjectLoader<Pose>(p, &c)
54 add("armature", &Loader::armature);
55 add("link", &Loader::link);
58 void Pose::Loader::armature(const string &n)
60 obj.set_armature(get_collection().get<Armature>(n));
63 void Pose::Loader::link(const string &n)
66 throw logic_error("Armature must be specified first");
67 LinkLoader ldr(obj, obj.armature->get_link(n).get_index());
72 Pose::LinkLoader::LinkLoader(Pose &p, unsigned l):
73 DataFile::ObjectLoader<Pose>(p),
76 add("rotation", &LinkLoader::rotation);
79 void Pose::LinkLoader::rotation(float a, float x, float y, float z)
81 obj.rotate_link(link_index, a, Vector3(x, y, z));