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

angle_interpolation.cpp « anim - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bdc13ce620872a0c9e0f4666132328f7364d20b7 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "anim/angle_interpolation.hpp"
#include "anim/controller.hpp"

#include "geometry/angles.hpp"

#include "base/logging.hpp"


namespace anim
{
  AngleInterpolation::AngleInterpolation(double start,
                                         double end,
                                         double speed,
                                         double & out)
    : m_outAngle(out)
  {
    CalcParams(start, end, speed);
  }

  void AngleInterpolation::Reset(double start, double end, double speed)
  {
    CalcParams(start, end, speed);
    m_startTime = GetController()->GetCurrentTime();
    m_outAngle = m_startAngle;
    SetState(EReady);
  }

  void AngleInterpolation::OnStart(double ts)
  {
    m_startTime = ts;
    m_outAngle = m_startAngle;
    Task::OnStart(ts);
  }

  void AngleInterpolation::OnStep(double ts)
  {
    if (!IsRunning())
      return;

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

    m_curAngle = m_outAngle = m_startAngle + elapsed * m_speed;

    Task::OnStep(ts);
  }

  void AngleInterpolation::OnEnd(double ts)
  {
    // ensuring that the final value was reached
    m_outAngle = m_endAngle;
    Task::OnEnd(ts);
  }

  void AngleInterpolation::SetEndAngle(double val)
  {
    CalcParams(m_curAngle, val, fabs(m_speed));
    m_startTime = GetController()->GetCurrentTime();
  }

  void AngleInterpolation::CalcParams(double start, double end, double speed)
  {
    ASSERT_GREATER(speed, 0.0, ());

    m_startAngle = start;
    m_speed = speed;
    m_startTime = 0.0;

    double const dist = ang::GetShortestDistance(start, end);
    if (dist < 0.0)
      m_speed = -m_speed;

    m_curAngle = m_startAngle;
    m_endAngle = m_startAngle + dist;
    m_interval = dist / m_speed;
  }

  SafeAngleInterpolation::SafeAngleInterpolation(double start, double end, double speed)
    : TBase(start, end, speed, m_angle)
  {
    m_angle = start;
  }

  void SafeAngleInterpolation::ResetDestParams(double dstAngle, double speed)
  {
    Reset(GetCurrentValue(), dstAngle, speed);
  }

  double SafeAngleInterpolation::GetCurrentValue() const
  {
    return m_angle;
  }
}