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: acb588cae62ab5c1734ef41c96cb945024635e6b (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
#include "angle_interpolation.hpp"
#include "controller.hpp"

#include "../geometry/angles.hpp"
#include "../base/logging.hpp"

namespace anim
{
  AngleInterpolation::AngleInterpolation(double start,
                                         double end,
                                         double speed,
                                         double & out)
    : m_startAngle(start),
      m_outAngle(out)
  {
    m_speed = speed;
    m_startTime = 0;
    m_dist = ang::GetShortestDistance(start, end);
    m_curAngle = m_startAngle;
    m_endAngle = m_startAngle + m_dist;
    m_interval = fabs(m_dist) / (2 * math::pi) * m_speed;
  }

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

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

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

    double elapsedSec = ts - m_startTime;
    m_curAngle = m_outAngle = m_startAngle + m_dist * elapsedSec / m_interval;

    Task::OnStep(ts);
  }

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

  double AngleInterpolation::EndAngle() const
  {
    return m_endAngle;
  }

  void AngleInterpolation::SetEndAngle(double val)
  {
    m_startTime = GetController()->GetCurrentTime();
    m_startAngle = m_curAngle;
    m_dist = ang::GetShortestDistance(m_startAngle, val);
    m_endAngle = m_startAngle + m_dist;
    m_interval = fabs(m_dist) / (2 * math::pi) * m_speed;
  }
}