X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fanimationplayer.cpp;h=ac16321874a7abd612ad6cf39fdb69cf1fdb8cf4;hp=0c00105276309f711569a0ae65a29347c0879b2a;hb=HEAD;hpb=d093b45975eb03b07680711ce982ad634a50fba3 diff --git a/source/animationplayer.cpp b/source/animationplayer.cpp deleted file mode 100644 index 0c001052..00000000 --- a/source/animationplayer.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include "animatedobject.h" -#include "animationplayer.h" -#include "armature.h" -#include "programdata.h" - -using namespace std; - -namespace Msp { -namespace GL { - -AnimationPlayer::ObjectSlot &AnimationPlayer::get_slot(AnimatedObject &obj) -{ - ObjectMap::iterator i = objects.find(&obj); - if(i!=objects.end()) - return i->second; - - return objects.insert(ObjectMap::value_type(&obj, ObjectSlot(obj))).first->second; -} - -void AnimationPlayer::play(AnimatedObject &obj, const Animation &anim) -{ - ObjectSlot &obj_slot = get_slot(obj); - obj_slot.animations.clear(); - obj_slot.base_matrix = Matrix(); - obj_slot.stacked = false; - obj_slot.armature = anim.get_armature(); - obj_slot.animations.push_back(AnimationSlot(anim)); -} - -void AnimationPlayer::play_stacked(AnimatedObject &obj, const Animation &anim) -{ - ObjectSlot &obj_slot = get_slot(obj); - if(obj_slot.animations.empty()) - obj_slot.base_matrix = *obj.get_matrix(); - // TODO check for incompatible armature - obj_slot.stacked = true; - obj_slot.armature = anim.get_armature(); - obj_slot.animations.push_back(AnimationSlot(anim)); -} - -unsigned AnimationPlayer::get_n_active_animations(const AnimatedObject &obj) const -{ - ObjectMap::const_iterator i = objects.find(&obj); - return (i!=objects.end() ? i->second.animations.size() : 0); -} - -void AnimationPlayer::stop(AnimatedObject &obj) -{ - objects.erase(&obj); -} - -void AnimationPlayer::stop(AnimatedObject &obj, const Animation &anim) -{ - ObjectMap::iterator i = objects.find(&obj); - if(i==objects.end()) - return; - - for(AnimationList::iterator j=i->second.animations.begin(); j!=i->second.animations.end(); ++j) - if(&j->animation==&anim) - { - i->second.animations.erase(j); - break; - } - - if(i->second.animations.empty()) - objects.erase(i); -} - -void AnimationPlayer::tick(const Time::TimeDelta &dt) -{ - for(ObjectMap::iterator i=objects.begin(); i!=objects.end(); ) - { - bool keep = false; - if(i->second.stacked) - keep = tick_stacked(i->second, dt); - else - keep = tick_single(i->second, dt); - - if(!keep) - objects.erase(i++); - else - ++i; - } -} - -bool AnimationPlayer::tick_single(ObjectSlot &slot, const Time::TimeDelta &dt) -{ - AnimatedObject &obj = slot.object; - AnimationSlot &anim = slot.animations.front(); - anim.iterator += dt; - obj.set_matrix(anim.iterator.get_matrix()); - - unsigned n_uniforms = anim.animation.get_n_uniforms(); - for(unsigned i=0; iget_max_link_index(); - for(unsigned i=0; i<=max_index; ++i) - obj.set_pose_matrix(i, anim.iterator.get_pose_matrix(i)); - } - - return !anim.iterator.is_end(); -} - -bool AnimationPlayer::tick_stacked(ObjectSlot &slot, const Time::TimeDelta &dt) -{ - Matrix matrix = slot.base_matrix; - for(AnimationList::iterator i=slot.animations.begin(); i!=slot.animations.end(); ++i) - { - i->iterator += dt; - matrix *= i->iterator.get_matrix(); - - unsigned n_uniforms = i->animation.get_n_uniforms(); - for(unsigned j=0; janimation.get_uniform_name(j), i->iterator.get_uniform(j)); - } - slot.object.set_matrix(matrix); - - if(slot.armature) - { - unsigned max_index = slot.armature->get_max_link_index(); - for(unsigned i=0; i<=max_index; ++i) - { - matrix = Matrix(); - /* XXX This is in all likelihood incorrect. The stacking should be - performed on local matrices. */ - for(AnimationList::iterator j=slot.animations.begin(); j!=slot.animations.end(); ++j) - if(j->animation.get_armature()) - matrix *= j->iterator.get_pose_matrix(i); - slot.object.set_pose_matrix(i, matrix); - } - } - - for(AnimationList::iterator i=slot.animations.begin(); i!=slot.animations.end(); ) - { - if(i->iterator.is_end()) - slot.animations.erase(i++); - else - ++i; - } - - return !slot.animations.empty(); -} - -void AnimationPlayer::set_object_uniform(AnimatedObject &obj, const string &name, const KeyFrame::AnimatedUniform &uni) -{ - ProgramData &shdata = obj.get_shader_data(); - - if(uni.size==1) - shdata.uniform(name, uni.values[0]); - else if(uni.size==2) - shdata.uniform2(name, uni.values); - else if(uni.size==2) - shdata.uniform3(name, uni.values); - else if(uni.size==4) - shdata.uniform4(name, uni.values); -} - - -AnimationPlayer::ObjectSlot::ObjectSlot(AnimatedObject &o): - object(o), - armature(0), - stacked(false) -{ } - - -AnimationPlayer::AnimationSlot::AnimationSlot(const Animation &a): - animation(a), - iterator(animation) -{ } - -} // namespace GL -} // namespace Msp