Welcome to mirror list, hosted at ThFree Co, Russian Federation.

segment_interpolation.cpp « anim - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ab1d3a9bd25c7e35247bfb67f3cc48bce76595c (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
#include "segment_interpolation.hpp"

namespace anim
{
  SegmentInterpolation::SegmentInterpolation(m2::PointD const & startPt,
                                             m2::PointD const & endPt,
                                             double interval,
                                             m2::PointD & outPt)
    : m_startPt(startPt),
      m_endPt(endPt),
      m_outPt(outPt),
      m_interval(interval)
  {}

  void SegmentInterpolation::OnStart(double ts)
  {
    m_startTime = ts;
    m_outPt = m_startPt;
    Task::OnStart(ts);
  }

  void SegmentInterpolation::OnStep(double ts)
  {
    if (ts - m_startTime >= m_interval)
    {
      End();
      return;
    }

    if (!IsRunning())
      return;

    double elapsedSec = ts - m_startTime;
    m2::PointD deltaPt = m_endPt - m_startPt;

    m_outPt = m_startPt + deltaPt * (elapsedSec / m_interval);

    Task::OnStep(ts);
  }

  void SegmentInterpolation::OnEnd(double ts)
  {
    // ensuring that the final value was reached
    m_outPt = m_endPt;
    Task::OnEnd(ts);
  }
}