]> git.tdb.fi Git - libs/demoscene.git/blobdiff - source/action.cpp
Move the Action class out of Sequencer
[libs/demoscene.git] / source / action.cpp
diff --git a/source/action.cpp b/source/action.cpp
new file mode 100644 (file)
index 0000000..b7cf082
--- /dev/null
@@ -0,0 +1,37 @@
+#include "action.h"
+
+InterpolationAction::InterpolationAction(bool h):
+       hermite(h),
+       start_beat(0),
+       duration(0)
+{ }
+
+void InterpolationAction::start(float b, float d)
+{
+       start_beat = b;
+       duration = d;
+       interpolate(0.0f, 0.0f);
+}
+
+void InterpolationAction::tick(float b, float d)
+{
+       if(duration)
+       {
+               float t = (b-start_beat)/duration;
+               float dt = d/duration;
+               if(hermite)
+               {
+                       dt = t-dt;
+                       t = (3-2*t)*t*t;
+                       dt = t-(3-2*dt)*dt*dt;
+               }
+               interpolate(t, dt);
+       }
+       else
+               interpolate(1.0f, 1.0f);
+}
+
+void InterpolationAction::end(float)
+{
+       interpolate(1.0f, 0.0f);
+}