blob: 86c4218841b630113187c430acadd098040ff851 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include "anim/value_interpolation.hpp"
namespace anim
{
ValueInterpolation::ValueInterpolation(double start,
double end,
double interval,
double & out)
: m_startValue(start),
m_outValue(out),
m_endValue(end)
{
m_dist = end - start;
m_interval = interval;
}
void ValueInterpolation::OnStart(double ts)
{
m_startTime = ts;
m_outValue = m_startValue;
Task::OnStart(ts);
}
void ValueInterpolation::OnStep(double ts)
{
if (ts - m_startTime >= m_interval)
{
End();
return;
}
if (!IsRunning())
return;
double elapsedSec = ts - m_startTime;
m_outValue = m_startValue + m_dist * elapsedSec / m_interval;
Task::OnStep(ts);
}
void ValueInterpolation::OnEnd(double ts)
{
// ensuring that the final value was reached
m_outValue = m_endValue;
Task::OnEnd(ts);
}
}
|