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

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/anim
diff options
context:
space:
mode:
authorrachytski <siarhei.rachytski@gmail.com>2012-09-30 22:24:28 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:44:26 +0300
commitd45e301d248cb1b52dd28c2e49c1288af0873488 (patch)
tree210cebadcc3fc1e885ed7f689ef14da39babab4e /anim
parent499af27e6a799bcf007f3179b8467aa78402cd35 (diff)
added base animation classes for single values and AnyRect's interpolations.
Diffstat (limited to 'anim')
-rw-r--r--anim/angle_interpolation.cpp2
-rw-r--r--anim/anim.pro4
-rw-r--r--anim/anyrect_interpolation.cpp79
-rw-r--r--anim/anyrect_interpolation.hpp45
-rw-r--r--anim/segment_interpolation.cpp6
-rw-r--r--anim/value_interpolation.cpp48
-rw-r--r--anim/value_interpolation.hpp31
7 files changed, 211 insertions, 4 deletions
diff --git a/anim/angle_interpolation.cpp b/anim/angle_interpolation.cpp
index b31a55fe82..0d8ba70dfa 100644
--- a/anim/angle_interpolation.cpp
+++ b/anim/angle_interpolation.cpp
@@ -27,7 +27,7 @@ namespace anim
void AngleInterpolation::OnStep(double ts)
{
- if (ts - m_startTime > m_interval)
+ if (ts - m_startTime >= m_interval)
{
End();
return;
diff --git a/anim/anim.pro b/anim/anim.pro
index 512015ab9d..e6cbf1d4cc 100644
--- a/anim/anim.pro
+++ b/anim/anim.pro
@@ -14,9 +14,13 @@ HEADERS += \
task.hpp \
angle_interpolation.hpp \
segment_interpolation.hpp \
+ anyrect_interpolation.hpp \
+ value_interpolation.hpp \
SOURCES += \
controller.cpp \
task.cpp \
angle_interpolation.cpp \
segment_interpolation.cpp \
+ value_interpolation.cpp \
+ anyrect_interpolation.cpp \
diff --git a/anim/anyrect_interpolation.cpp b/anim/anyrect_interpolation.cpp
new file mode 100644
index 0000000000..74ca20eace
--- /dev/null
+++ b/anim/anyrect_interpolation.cpp
@@ -0,0 +1,79 @@
+#include "anyrect_interpolation.hpp"
+
+namespace anim
+{
+ AnyRectInterpolation::AnyRectInterpolation(m2::AnyRectD const & startRect,
+ m2::AnyRectD const & endRect,
+ double rotationSpeed,
+ m2::AnyRectD & outRect)
+ : m_interval(rotationSpeed * fabs(ang::GetShortestDistance(startRect.Angle().val(),
+ endRect.Angle().val())) / (2 * math::pi)),
+ m_angleInt(startRect.Angle().val(),
+ endRect.Angle().val(),
+ rotationSpeed,
+ m_curAngle),
+ m_segmentInt(startRect.GlobalCenter(),
+ endRect.GlobalCenter(),
+ m_interval,
+ m_curCenter),
+ m_sizeXInt(startRect.GetLocalRect().SizeX(),
+ endRect.GetLocalRect().SizeX(),
+ m_interval,
+ m_curSizeX),
+ m_sizeYInt(startRect.GetLocalRect().SizeY(),
+ endRect.GetLocalRect().SizeY(),
+ m_interval,
+ m_curSizeY),
+ m_startRect(startRect),
+ m_endRect(endRect),
+ m_outRect(outRect)
+ {
+ }
+
+ void AnyRectInterpolation::OnStart(double ts)
+ {
+ m_startTime = ts;
+
+ m_angleInt.OnStart(ts);
+ m_segmentInt.OnStart(ts);
+ m_sizeXInt.OnStart(ts);
+ m_sizeYInt.OnStart(ts);
+
+ m_outRect = m_startRect;
+
+ anim::Task::OnStart(ts);
+ }
+
+ void AnyRectInterpolation::OnStep(double ts)
+ {
+ if (ts - m_startTime >= m_interval)
+ {
+ End();
+ return;
+ }
+
+ if (!IsRunning())
+ return;
+
+ m_angleInt.OnStep(ts);
+ m_segmentInt.OnStep(ts);
+ m_sizeXInt.OnStep(ts);
+ m_sizeYInt.OnStep(ts);
+
+ m_outRect = m2::AnyRectD(m_curCenter, m_curAngle, m2::RectD(-m_curSizeX / 2, -m_curSizeY / 2, m_curSizeX / 2, m_curSizeY / 2));
+
+ anim::Task::OnStep(ts);
+ }
+
+ void AnyRectInterpolation::OnEnd(double ts)
+ {
+ m_angleInt.OnEnd(ts);
+ m_segmentInt.OnEnd(ts);
+ m_sizeXInt.OnEnd(ts);
+ m_sizeYInt.OnEnd(ts);
+
+ m_outRect = m_endRect;
+
+ anim::Task::OnEnd(ts);
+ }
+}
diff --git a/anim/anyrect_interpolation.hpp b/anim/anyrect_interpolation.hpp
new file mode 100644
index 0000000000..13df48c8db
--- /dev/null
+++ b/anim/anyrect_interpolation.hpp
@@ -0,0 +1,45 @@
+#pragma once
+
+#include "../geometry/any_rect2d.hpp"
+#include "angle_interpolation.hpp"
+#include "segment_interpolation.hpp"
+#include "value_interpolation.hpp"
+
+namespace anim
+{
+ class AnyRectInterpolation : public Task
+ {
+ private:
+
+ double m_interval;
+
+ AngleInterpolation m_angleInt;
+ double m_curAngle;
+
+ SegmentInterpolation m_segmentInt;
+ m2::PointD m_curCenter;
+
+ ValueInterpolation m_sizeXInt;
+ double m_curSizeX;
+
+ ValueInterpolation m_sizeYInt;
+ double m_curSizeY;
+
+ m2::AnyRectD m_startRect;
+ m2::AnyRectD m_endRect;
+ m2::AnyRectD & m_outRect;
+
+ double m_startTime;
+
+ public:
+
+ AnyRectInterpolation(m2::AnyRectD const & startRect,
+ m2::AnyRectD const & endRect,
+ double rotationSpeed,
+ m2::AnyRectD & outRect);
+
+ void OnStart(double ts);
+ void OnStep(double ts);
+ void OnEnd(double ts);
+ };
+}
diff --git a/anim/segment_interpolation.cpp b/anim/segment_interpolation.cpp
index ae7fbcb974..a8e5bbca8e 100644
--- a/anim/segment_interpolation.cpp
+++ b/anim/segment_interpolation.cpp
@@ -8,8 +8,8 @@ namespace anim
m2::PointD & outPt)
: m_startPt(startPt),
m_endPt(endPt),
- m_interval(interval),
- m_outPt(outPt)
+ m_outPt(outPt),
+ m_interval(interval)
{
m_deltaPt = m_endPt - m_startPt;
}
@@ -23,7 +23,7 @@ namespace anim
void SegmentInterpolation::OnStep(double ts)
{
- if (ts - m_startTime > m_interval)
+ if (ts - m_startTime >= m_interval)
{
End();
return;
diff --git a/anim/value_interpolation.cpp b/anim/value_interpolation.cpp
new file mode 100644
index 0000000000..294ccf7b9d
--- /dev/null
+++ b/anim/value_interpolation.cpp
@@ -0,0 +1,48 @@
+#include "value_interpolation.hpp"
+
+namespace anim
+{
+ ValueInterpolation::ValueInterpolation(double start,
+ double end,
+ double interval,
+ double & out)
+ : m_startValue(start),
+ m_outValue(out),
+ m_endValue(end)
+ {
+ m_dist = end - start;
+ m_interval = interval;
+ }
+
+ void ValueInterpolation::OnStart(double ts)
+ {
+ m_startTime = ts;
+ m_outValue = m_startValue;
+ Task::OnStart(ts);
+ }
+
+ void ValueInterpolation::OnStep(double ts)
+ {
+ if (ts - m_startTime >= m_interval)
+ {
+ End();
+ return;
+ }
+
+ if (!IsRunning())
+ return;
+
+ double elapsedSec = ts - m_startTime;
+ m_outValue = m_startValue + m_dist * elapsedSec / m_interval;
+
+ Task::OnStep(ts);
+ }
+
+ void ValueInterpolation::OnEnd(double ts)
+ {
+ // ensuring that the final value was reached
+ m_outValue = m_endValue;
+ Task::OnEnd(ts);
+ }
+}
+
diff --git a/anim/value_interpolation.hpp b/anim/value_interpolation.hpp
new file mode 100644
index 0000000000..004428d1a7
--- /dev/null
+++ b/anim/value_interpolation.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include "task.hpp"
+
+namespace anim
+{
+ class ValueInterpolation : public Task
+ {
+ private:
+
+ double m_startValue;
+ double m_curValue;
+ double & m_outValue;
+ double m_endValue;
+
+ double m_startTime;
+ double m_interval;
+ double m_dist;
+
+ public:
+
+ ValueInterpolation(double start,
+ double end,
+ double interval,
+ double & out);
+
+ void OnStart(double ts);
+ void OnStep(double ts);
+ void OnEnd(double ts);
+ };
+}