]> git.tdb.fi Git - libs/demoscene.git/blobdiff - source/animate.cpp
Merge CameraControl functionality into other classes
[libs/demoscene.git] / source / animate.cpp
diff --git a/source/animate.cpp b/source/animate.cpp
new file mode 100644 (file)
index 0000000..d74c239
--- /dev/null
@@ -0,0 +1,52 @@
+#include "animate.h"
+#include "demo.h"
+
+using namespace std;
+using namespace Msp;
+
+Animate::Animate():
+       target(0),
+       anim(0),
+       player(0)
+{ }
+
+Animate::Animate(GL::Placeable &t, const GL::Animation &a, GL::AnimationPlayer &p):
+       target(&t),
+       anim(&a),
+       player(&p)
+{ }
+
+void Animate::validate() const
+{
+       if(!target)
+               throw logic_error("null target");
+       if(!anim)
+               throw logic_error("null animation");
+       if(!player)
+               throw logic_error("null player");
+}
+
+void Animate::start(float, float d)
+{
+       float speed = (d ? (anim->get_duration()/Time::sec)/d : 1.0f);
+       player->play(*target, *anim, speed);
+}
+
+
+Animate::Loader::Loader(Animate &a, Demo &d):
+       DataFile::DerivedObjectLoader<Animate, Action::Loader>(a, d)
+{
+       a.player = &demo.get_animation_player();
+       add("animation", &Loader::animation);
+       add("target", &Loader::target);
+}
+
+void Animate::Loader::animation(const string &n)
+{
+       obj.anim = &demo.get_resources().get<GL::Animation>(n);
+}
+
+void Animate::Loader::target(const string &n)
+{
+       obj.target = &demo.get_thing<GL::Placeable>(n);
+}