]> git.tdb.fi Git - libs/demoscene.git/blob - source/action.cpp
Move the Action class out of Sequencer
[libs/demoscene.git] / source / action.cpp
1 #include "action.h"
2
3 InterpolationAction::InterpolationAction(bool h):
4         hermite(h),
5         start_beat(0),
6         duration(0)
7 { }
8
9 void InterpolationAction::start(float b, float d)
10 {
11         start_beat = b;
12         duration = d;
13         interpolate(0.0f, 0.0f);
14 }
15
16 void InterpolationAction::tick(float b, float d)
17 {
18         if(duration)
19         {
20                 float t = (b-start_beat)/duration;
21                 float dt = d/duration;
22                 if(hermite)
23                 {
24                         dt = t-dt;
25                         t = (3-2*t)*t*t;
26                         dt = t-(3-2*dt)*dt*dt;
27                 }
28                 interpolate(t, dt);
29         }
30         else
31                 interpolate(1.0f, 1.0f);
32 }
33
34 void InterpolationAction::end(float)
35 {
36         interpolate(1.0f, 0.0f);
37 }