namespace Msp {
namespace GL {
-AnimationPlayer::Target &AnimationPlayer::get_slot(AnimatedObject &obj)
+AnimationPlayer::Target &AnimationPlayer::get_slot(Placeable &obj)
{
ObjectMap::iterator i = objects.find(&obj);
if(i!=objects.end())
return objects.insert(ObjectMap::value_type(&obj, Target(obj))).first->second;
}
-void AnimationPlayer::play(AnimatedObject &obj, const Animation &anim)
+AnimationPlayer::Target &AnimationPlayer::play_(Placeable &obj, const Animation &anim, bool stacked, float speed)
{
Target &target = get_slot(obj);
- target.animations.clear();
- target.base_matrix = Matrix();
- target.stacked = false;
+ if(!stacked)
+ {
+ target.animations.clear();
+ target.base_matrix = Matrix();
+ }
+ else if(target.animations.empty())
+ target.base_matrix = *obj.get_matrix();
+ target.stacked = stacked;
+ // TODO check for incompatible armature
target.armature = anim.get_armature();
- target.animations.push_back(PlayingAnimation(anim));
+ target.animations.push_back(PlayingAnimation(anim, speed));
+ return target;
}
-void AnimationPlayer::play_stacked(AnimatedObject &obj, const Animation &anim)
+void AnimationPlayer::play(AnimatedObject &obj, const Animation &anim, float speed)
{
- Target &target = get_slot(obj);
- if(target.animations.empty())
- target.base_matrix = *obj.get_matrix();
- // TODO check for incompatible armature
- target.stacked = true;
- target.armature = anim.get_armature();
- target.animations.push_back(PlayingAnimation(anim));
+ Target &target = play_(obj, anim, false, speed);
+ target.object = &obj;
+}
+
+void AnimationPlayer::play(Placeable &obj, const Animation &anim, float speed)
+{
+ play_(obj, anim, false, speed);
+}
+
+void AnimationPlayer::play_stacked(AnimatedObject &obj, const Animation &anim, float speed)
+{
+ Target &target = play_(obj, anim, true, speed);
+ target.object = &obj;
+}
+
+void AnimationPlayer::play_stacked(Placeable &obj, const Animation &anim, float speed)
+{
+ play_(obj, anim, true, speed);
}
unsigned AnimationPlayer::get_n_active_animations(const AnimatedObject &obj) const
}
}
-void AnimationPlayer::stop(AnimatedObject &obj)
+void AnimationPlayer::stop(Placeable &obj)
{
objects.erase(&obj);
}
-void AnimationPlayer::stop(AnimatedObject &obj, const Animation &anim)
+void AnimationPlayer::stop(Placeable &obj, const Animation &anim)
{
ObjectMap::iterator i = objects.find(&obj);
if(i==objects.end())
void AnimationPlayer::tick_single(Target &target, const Time::TimeDelta &dt)
{
PlayingAnimation &anim = target.animations.front();
- anim.iterator += dt;
- target.object.set_matrix(anim.iterator.get_matrix());
+ anim.iterator += dt*anim.speed;
+ target.placeable.set_matrix(anim.iterator.get_matrix());
- unsigned n_uniforms = anim.animation->get_n_uniforms();
- for(unsigned i=0; i<n_uniforms; ++i)
- set_object_uniform(target.object, anim.animation->get_uniform_name(i), anim.iterator.get_uniform(i));
-
- if(target.armature)
+ if(target.object)
{
- unsigned max_index = target.armature->get_max_link_index();
- for(unsigned i=0; i<=max_index; ++i)
- target.object.set_pose_matrix(i, anim.iterator.get_pose_matrix(i));
+ unsigned n_uniforms = anim.animation->get_n_uniforms();
+ for(unsigned i=0; i<n_uniforms; ++i)
+ set_object_uniform(*target.object, anim.animation->get_uniform_name(i), anim.iterator.get_uniform(i));
+
+ if(target.armature)
+ {
+ unsigned max_index = target.armature->get_max_link_index();
+ for(unsigned i=0; i<=max_index; ++i)
+ target.object->set_pose_matrix(i, anim.iterator.get_pose_matrix(i));
+ }
}
anim.iterator.dispatch_events(target);
- if(!anim.iterator.is_end())
+ if(anim.iterator.is_end())
target.animations.clear();
}
Matrix matrix = target.base_matrix;
for(vector<PlayingAnimation>::iterator i=target.animations.begin(); i!=target.animations.end(); ++i)
{
- i->iterator += dt;
+ i->iterator += dt*i->speed;
matrix *= i->iterator.get_matrix();
- unsigned n_uniforms = i->animation->get_n_uniforms();
- for(unsigned j=0; j<n_uniforms; ++j)
- set_object_uniform(target.object, i->animation->get_uniform_name(j), i->iterator.get_uniform(j));
+ if(target.object)
+ {
+ unsigned n_uniforms = i->animation->get_n_uniforms();
+ for(unsigned j=0; j<n_uniforms; ++j)
+ set_object_uniform(*target.object, i->animation->get_uniform_name(j), i->iterator.get_uniform(j));
+ }
}
- target.object.set_matrix(matrix);
+ target.placeable.set_matrix(matrix);
- if(target.armature)
+ if(target.object && target.armature)
{
unsigned max_index = target.armature->get_max_link_index();
for(unsigned i=0; i<=max_index; ++i)
for(vector<PlayingAnimation>::iterator j=target.animations.begin(); j!=target.animations.end(); ++j)
if(j->animation->get_armature())
matrix *= j->iterator.get_pose_matrix(i);
- target.object.set_pose_matrix(i, matrix);
+ target.object->set_pose_matrix(i, matrix);
}
}
shdata.uniform(name, uni.values[0]);
else if(uni.size==2)
shdata.uniform2(name, uni.values);
- else if(uni.size==2)
+ else if(uni.size==3)
shdata.uniform3(name, uni.values);
else if(uni.size==4)
shdata.uniform4(name, uni.values);
}
-AnimationPlayer::Target::Target(AnimatedObject &o):
- object(o),
+AnimationPlayer::PlayingAnimation::PlayingAnimation(const Animation &a, float s):
+ animation(&a),
+ speed(s),
+ iterator(*animation)
+{ }
+
+
+AnimationPlayer::Target::Target(Placeable &p):
+ placeable(p),
+ object(0),
armature(0),
stacked(false)
{ }
-void AnimationPlayer::Target::animation_event(AnimatedObject *, const string &name, const Variant &value)
+void AnimationPlayer::Target::animation_event(Placeable *, const string &name, const Variant &value)
{
for(vector<AnimationEventObserver *>::const_iterator i=event_observers.begin(); i!=event_observers.end(); ++i)
- (*i)->animation_event(&object, name, value);
+ (*i)->animation_event(&placeable, name, value);
}
-
-AnimationPlayer::PlayingAnimation::PlayingAnimation(const Animation &a):
- animation(&a),
- iterator(*animation)
-{ }
-
} // namespace GL
} // namespace Msp