]> git.tdb.fi Git - libs/demoscene.git/blob - source/action.cpp
Framework for loading sequences from files
[libs/demoscene.git] / source / action.cpp
1 #include "action.h"
2
3 using namespace Msp;
4
5 InterpolationAction::InterpolationAction(Mode m):
6         mode(m),
7         start_beat(0),
8         duration(0)
9 { }
10
11 void InterpolationAction::start(float b, float d)
12 {
13         start_beat = b;
14         duration = d;
15         interpolate(0.0f, 0.0f);
16 }
17
18 void InterpolationAction::tick(float b, float d)
19 {
20         if(duration)
21         {
22                 float t = (b-start_beat)/duration;
23                 float dt = d/duration;
24                 if(mode==HERMITE)
25                 {
26                         dt = t-dt;
27                         t = (3-2*t)*t*t;
28                         dt = t-(3-2*dt)*dt*dt;
29                 }
30                 interpolate(t, dt);
31         }
32         else
33                 interpolate(1.0f, 1.0f);
34 }
35
36 void InterpolationAction::end(float)
37 {
38         interpolate(1.0f, 0.0f);
39 }
40
41
42 Action::Loader::Loader(Action &a, Demo &d):
43         DataFile::ObjectLoader<Action>(a),
44         demo(d)
45 { }