return objects.insert(ObjectMap::value_type(&obj, Target(obj))).first->second;
}
-AnimationPlayer::Target &AnimationPlayer::play_(Placeable &obj, const Animation &anim, bool stacked)
+AnimationPlayer::Target &AnimationPlayer::play_(Placeable &obj, const Animation &anim, bool stacked, float speed)
{
Target &target = get_slot(obj);
if(!stacked)
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(AnimatedObject &obj, const Animation &anim)
+void AnimationPlayer::play(AnimatedObject &obj, const Animation &anim, float speed)
{
- Target &target = play_(obj, anim, false);
+ Target &target = play_(obj, anim, false, speed);
target.object = &obj;
}
-void AnimationPlayer::play(Placeable &obj, const Animation &anim)
+void AnimationPlayer::play(Placeable &obj, const Animation &anim, float speed)
{
- play_(obj, anim, false);
+ play_(obj, anim, false, speed);
}
-void AnimationPlayer::play_stacked(AnimatedObject &obj, const Animation &anim)
+void AnimationPlayer::play_stacked(AnimatedObject &obj, const Animation &anim, float speed)
{
- Target &target = play_(obj, anim, true);
+ Target &target = play_(obj, anim, true, speed);
target.object = &obj;
}
-void AnimationPlayer::play_stacked(Placeable &obj, const Animation &anim)
+void AnimationPlayer::play_stacked(Placeable &obj, const Animation &anim, float speed)
{
- play_(obj, anim, true);
+ play_(obj, anim, true, speed);
}
unsigned AnimationPlayer::get_n_active_animations(const AnimatedObject &obj) const
void AnimationPlayer::tick_single(Target &target, const Time::TimeDelta &dt)
{
PlayingAnimation &anim = target.animations.front();
- anim.iterator += dt;
+ anim.iterator += dt*anim.speed;
target.placeable.set_matrix(anim.iterator.get_matrix());
if(target.object)
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();
if(target.object)
}
-AnimationPlayer::PlayingAnimation::PlayingAnimation(const Animation &a):
+AnimationPlayer::PlayingAnimation::PlayingAnimation(const Animation &a, float s):
animation(&a),
+ speed(s),
iterator(*animation)
{ }
struct PlayingAnimation
{
const Animation *animation;
+ float speed;
Animation::Iterator iterator;
- PlayingAnimation(const Animation &);
+ PlayingAnimation(const Animation &, float);
};
struct Target: AnimationEventObserver
private:
Target &get_slot(Placeable &);
- Target &play_(Placeable &, const Animation &, bool);
+ Target &play_(Placeable &, const Animation &, bool, float);
public:
/// Plays an animation on an object. Any previous animations are replaced.
- void play(AnimatedObject &, const Animation &);
+ void play(AnimatedObject &, const Animation &, float = 1.0f);
- void play(Placeable &, const Animation &);
+ void play(Placeable &, const Animation &, float = 1.0f);
/** Plays an animation, stacked with other animations. If no animations are
playing yet, the object's current matrix is used as the base. */
- void play_stacked(AnimatedObject &, const Animation &);
+ void play_stacked(AnimatedObject &, const Animation &, float = 1.0f);
- void play_stacked(Placeable &, const Animation &);
+ void play_stacked(Placeable &, const Animation &, float = 1.0f);
/// Returns the number of animations currently affecting an object.
unsigned get_n_active_animations(const AnimatedObject &) const;