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: df4b328be46511536dae2787e26e64f63439693b (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "anim/segment_interpolation.hpp"
#include "anim/controller.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)
  {
    m_speed = (m_endPt - m_startPt) / m_interval;
  }

  void SegmentInterpolation::Reset(m2::PointD const & start, m2::PointD const & end, double interval)
  {
    ASSERT_GREATER(interval, 0.0, ());

    m_startPt = start;
    m_endPt = end;
    m_outPt = m_startPt;
    m_interval = interval;

    m_speed = (m_endPt - m_startPt) / m_interval;
    m_startTime = GetController()->GetCurrentTime();
    SetState(EReady);
  }

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

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

    if (!IsRunning())
      return;

    m_outPt = m_startPt + m_speed * elapsed;

    Task::OnStep(ts);
  }

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

  SafeSegmentInterpolation::SafeSegmentInterpolation(m2::PointD const & startPt, m2::PointD const & endPt,
                                                     double interval)
    : TBase(startPt, endPt, interval, m_pt)
  {
    m_pt = startPt;
  }

  void SafeSegmentInterpolation::ResetDestParams(m2::PointD const & dstPt, double interval)
  {
    Reset(GetCurrentValue(), dstPt, interval);
  }

  m2::PointD const & SafeSegmentInterpolation::GetCurrentValue() const
  {
    return m_pt;
  }
}