diff options
author | rachytski <siarhei.rachytski@gmail.com> | 2012-09-28 21:37:21 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:44:24 +0300 |
commit | 4f04b39a7aec4a09eb697c0227dfa4a558972dcc (patch) | |
tree | 803b5eddc48e21a0ecd96d6320be93e81581092e /anim | |
parent | 766d07bb9407e981c2a5bc720f19c486bb0cf0a2 (diff) |
added anim::SegmentInterpolation and MoveScreen animation tasks.
Diffstat (limited to 'anim')
-rw-r--r-- | anim/angle_interpolation.hpp | 5 | ||||
-rw-r--r-- | anim/anim.pro | 2 | ||||
-rw-r--r-- | anim/segment_interpolation.cpp | 48 | ||||
-rw-r--r-- | anim/segment_interpolation.hpp | 31 |
4 files changed, 81 insertions, 5 deletions
diff --git a/anim/angle_interpolation.hpp b/anim/angle_interpolation.hpp index 55a2102557..063fee2266 100644 --- a/anim/angle_interpolation.hpp +++ b/anim/angle_interpolation.hpp @@ -1,16 +1,11 @@ #pragma once #include "task.hpp" -#include "../std/function.hpp" namespace anim { class AngleInterpolation : public Task { - public: - - typedef function<void()> TCallback; - private: double m_startAngle; diff --git a/anim/anim.pro b/anim/anim.pro index 477a63413a..512015ab9d 100644 --- a/anim/anim.pro +++ b/anim/anim.pro @@ -13,8 +13,10 @@ HEADERS += \ controller.hpp \ task.hpp \ angle_interpolation.hpp \ + segment_interpolation.hpp \ SOURCES += \ controller.cpp \ task.cpp \ angle_interpolation.cpp \ + segment_interpolation.cpp \ diff --git a/anim/segment_interpolation.cpp b/anim/segment_interpolation.cpp new file mode 100644 index 0000000000..ae7fbcb974 --- /dev/null +++ b/anim/segment_interpolation.cpp @@ -0,0 +1,48 @@ +#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_interval(interval), + m_outPt(outPt) + { + m_deltaPt = m_endPt - m_startPt; + } + + 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; + + m_outPt = m_startPt + m_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); + } +} diff --git a/anim/segment_interpolation.hpp b/anim/segment_interpolation.hpp new file mode 100644 index 0000000000..26f22f4934 --- /dev/null +++ b/anim/segment_interpolation.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "task.hpp" +#include "../geometry/point2d.hpp" + +namespace anim +{ + class SegmentInterpolation : public Task + { + private: + + m2::PointD m_startPt; + m2::PointD m_endPt; + m2::PointD m_deltaPt; + m2::PointD & m_outPt; + double m_startTime; + double m_interval; + + public: + + SegmentInterpolation(m2::PointD const & startPt, + m2::PointD const & endPt, + double interval, + m2::PointD & outPt); + + void OnStart(double ts); + void OnStep(double ts); + void OnEnd(double ts); + }; +} + |