]> git.tdb.fi Git - libs/gl.git/blob - source/animationplayer.cpp
Store block pointer in uniform info
[libs/gl.git] / source / animationplayer.cpp
1 #include "animatedobject.h"
2 #include "animationplayer.h"
3 #include "armature.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace GL {
9
10 void AnimationPlayer::play(AnimatedObject &obj, const Animation &anim)
11 {
12         slots.push_back(Slot(obj, anim));
13 }
14
15 void AnimationPlayer::tick(const Time::TimeDelta &dt)
16 {
17         for(list<Slot>::iterator i=slots.begin(); i!=slots.end(); )
18         {
19                 i->iterator += dt;
20                 i->object.set_matrix(i->iterator.get_matrix());
21                 if(const Armature *armature = i->animation.get_armature())
22                 {
23                         unsigned max_index = armature->get_max_link_index();
24                         for(unsigned j=0; j<=max_index; ++j)
25                                 i->object.set_pose_matrix(j, i->iterator.get_pose_matrix(j));
26                 }
27
28                 if(i->iterator.is_end())
29                         slots.erase(i++);
30                 else
31                         ++i;
32         }
33 }
34
35
36 AnimationPlayer::Slot::Slot(AnimatedObject &o, const Animation &a):
37         object(o),
38         animation(a),
39         iterator(animation)
40 { }
41
42 } // namespace GL
43 } // namespace Msp