X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fpose.cpp;h=99fa6bb3dfe812265a8e2372ddd9c1daad5f887a;hb=HEAD;hp=b5c5781b630be2365c5dcb06841acd3060291180;hpb=9abfb801dbceb59272f6561731d066ed516340e5;p=libs%2Fgl.git diff --git a/source/pose.cpp b/source/pose.cpp deleted file mode 100644 index b5c5781b..00000000 --- a/source/pose.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include "armature.h" -#include "error.h" -#include "pose.h" - -using namespace std; - -namespace Msp { -namespace GL { - -Pose::Pose(): - armature(0) -{ } - -Pose::Pose(const Armature &a): - armature(0) -{ - set_armature(a); -} - -void Pose::set_armature(const Armature &a) -{ - if(armature) - throw invalid_operation("Pose::set_armature"); - armature = &a; - links.resize(armature->get_max_link_index()+1); -} - -void Pose::rotate_link(unsigned i, float angle, const Vector3 &axis) -{ - if(i>=links.size()) - throw out_of_range("Pose::rotate_link"); - - const Armature::Link &arm_link = armature->get_link(i); - links[i].local_matrix.rotate(angle, axis); - - // Keep the base point stationary - Vector3 base = arm_link.get_base(); - Vector3 new_base = links[i].local_matrix*base; - links[i].local_matrix.translate(base.x-new_base.x, base.y-new_base.y, base.z-new_base.z); - - if(const Armature::Link *parent = arm_link.get_parent()) - links[i].matrix = links[parent->get_index()].matrix*links[i].local_matrix; - - // XXX apply matrix to descendants of the link -} - -const Matrix &Pose::get_link_matrix(unsigned i) const -{ - if(i>=links.size()) - throw out_of_range("Pose::get_link_matrix"); - return links[i].matrix; -} - - -Pose::Loader::Loader(Pose &p, Collection &c): - DataFile::CollectionObjectLoader(p, &c) -{ - add("armature", &Pose::armature); - add("link", &Loader::link); -} - -void Pose::Loader::link(const string &n) -{ - if(!obj.armature) - error("Armature must be specified first"); - LinkLoader ldr(obj, obj.armature->get_link(n).get_index()); - load_sub_with(ldr); -} - - -Pose::LinkLoader::LinkLoader(Pose &p, unsigned l): - DataFile::ObjectLoader(p), - link_index(l) -{ - add("rotation", &LinkLoader::rotation); -} - -void Pose::LinkLoader::rotation(float a, float x, float y, float z) -{ - obj.rotate_link(link_index, a, Vector3(x, y, z)); -} - -} // namespace GL -} // namespace Msp