From f7d97541aee552acb84f2f4c0aa43ac623c59860 Mon Sep 17 00:00:00 2001 From: ExMix Date: Thu, 14 May 2015 13:29:50 +0300 Subject: [PATCH] [drape] model view angle interpolation --- .../animation/base_viewport_animation.hpp | 4 ++-- drape_frontend/animation/interpolations.cpp | 16 ++++++++++++++- drape_frontend/animation/interpolations.hpp | 13 +++++++++++- .../animation/modelview_angle_animation.cpp | 20 +++++++++++++++++++ .../animation/modelview_angle_animation.hpp | 19 ++++++++++++++++++ .../animation/modelview_center_animation.cpp | 4 ++-- .../animation/modelview_center_animation.hpp | 2 +- drape_frontend/drape_frontend.pro | 2 ++ drape_frontend/user_event_stream.cpp | 1 - drape_head/qtoglcontext.cpp | 2 +- 10 files changed, 74 insertions(+), 9 deletions(-) create mode 100644 drape_frontend/animation/modelview_angle_animation.cpp create mode 100644 drape_frontend/animation/modelview_angle_animation.hpp diff --git a/drape_frontend/animation/base_viewport_animation.hpp b/drape_frontend/animation/base_viewport_animation.hpp index 0e6f7f94d3..bf9f61c30d 100644 --- a/drape_frontend/animation/base_viewport_animation.hpp +++ b/drape_frontend/animation/base_viewport_animation.hpp @@ -6,10 +6,10 @@ namespace df { -class BaseViewportAnimation : public BaseInterpolator +class BaseModeViewAnimation : public BaseInterpolator { public: - BaseViewportAnimation(double duration) : BaseInterpolator(duration) {} + BaseModeViewAnimation(double duration) : BaseInterpolator(duration) {} virtual void Apply(Navigator & navigator) = 0; }; diff --git a/drape_frontend/animation/interpolations.cpp b/drape_frontend/animation/interpolations.cpp index ddef8de248..515ffb7a08 100644 --- a/drape_frontend/animation/interpolations.cpp +++ b/drape_frontend/animation/interpolations.cpp @@ -1,12 +1,26 @@ #include "drape_frontend/animation/interpolations.hpp" +#include "geometry/angles.hpp" + namespace df { -m2::PointD Interpolate(m2::PointD const & startPt, m2::PointD const & endPt, double t) +m2::PointD InterpolatePoint(m2::PointD const & startPt, m2::PointD const & endPt, double t) { m2::PointD diff = endPt - startPt; return startPt + diff * t; } +InerpolateAngle::InerpolateAngle(double startAngle, double endAngle) +{ + m_startAngle = ang::AngleIn2PI(startAngle); + m_delta = ang::GetShortestDistance(m_startAngle, ang::AngleIn2PI(endAngle)); +} + +double InerpolateAngle::Interpolate(double t) +{ + return m_startAngle + m_delta * t; +} + + } // namespace df diff --git a/drape_frontend/animation/interpolations.hpp b/drape_frontend/animation/interpolations.hpp index 6f809043af..a3c0084692 100644 --- a/drape_frontend/animation/interpolations.hpp +++ b/drape_frontend/animation/interpolations.hpp @@ -4,5 +4,16 @@ namespace df { - m2::PointD Interpolate(m2::PointD const & startPt, m2::PointD const & endPt, double t); + m2::PointD InterpolatePoint(m2::PointD const & startPt, m2::PointD const & endPt, double t); + + class InerpolateAngle + { + public: + InerpolateAngle(double startAngle, double endAngle); + double Interpolate(double t); + + private: + double m_startAngle; + double m_delta; + }; } // namespace df diff --git a/drape_frontend/animation/modelview_angle_animation.cpp b/drape_frontend/animation/modelview_angle_animation.cpp new file mode 100644 index 0000000000..fd5c41f557 --- /dev/null +++ b/drape_frontend/animation/modelview_angle_animation.cpp @@ -0,0 +1,20 @@ +#include "modelview_angle_animation.hpp" + +namespace df +{ + +ModelViewAngleAnimation::ModelViewAngleAnimation(double startAngle, double endAngle, double duration) + : BaseViewportAnimation(duration) + , m_angle(startAngle, endAngle) +{ +} + +void ModelViewAngleAnimation::Apply(Navigator & navigator) +{ + double resultAngle = m_angle.Interpolate(GetT()); + m2::AnyRectD r = navigator.Screen().GlobalRect(); + r.SetAngle(resultAngle); + navigator.SetFromRect(r); +} + +} diff --git a/drape_frontend/animation/modelview_angle_animation.hpp b/drape_frontend/animation/modelview_angle_animation.hpp new file mode 100644 index 0000000000..cb6a8ae0a1 --- /dev/null +++ b/drape_frontend/animation/modelview_angle_animation.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include "drape_frontend/animation/base_viewport_animation.hpp" +#include "drape_frontend/animation/interpolations.hpp" + +namespace df +{ + +class ModelViewAngleAnimation : public BaseViewportAnimation +{ +public: + ModelViewAngleAnimation(double startAngle, double endAngle, double duration); + void Apply(Navigator & navigator) override; + +private: + InerpolateAngle m_angle; +}; + +} diff --git a/drape_frontend/animation/modelview_center_animation.cpp b/drape_frontend/animation/modelview_center_animation.cpp index b8a1c8c353..9a3d1b49eb 100644 --- a/drape_frontend/animation/modelview_center_animation.cpp +++ b/drape_frontend/animation/modelview_center_animation.cpp @@ -7,7 +7,7 @@ namespace df ModelViewCenterAnimation::ModelViewCenterAnimation(m2::PointD const & start, m2::PointD const & end, double duration) - : BaseViewportAnimation(duration) + : BaseModeViewAnimation(duration) , m_startPt(start) , m_endPt(end) { @@ -15,7 +15,7 @@ ModelViewCenterAnimation::ModelViewCenterAnimation(m2::PointD const & start, void ModelViewCenterAnimation::Apply(Navigator & navigator) { - m2::PointD center = Interpolate(m_startPt, m_endPt, GetT()); + m2::PointD center = InterpolatePoint(m_startPt, m_endPt, GetT()); navigator.CenterViewport(center); } diff --git a/drape_frontend/animation/modelview_center_animation.hpp b/drape_frontend/animation/modelview_center_animation.hpp index b9e6b32c23..9321636cb8 100644 --- a/drape_frontend/animation/modelview_center_animation.hpp +++ b/drape_frontend/animation/modelview_center_animation.hpp @@ -5,7 +5,7 @@ namespace df { -class ModelViewCenterAnimation : public BaseViewportAnimation +class ModelViewCenterAnimation : public BaseModeViewAnimation { public: ModelViewCenterAnimation(m2::PointD const & start, m2::PointD const & end, double duration); diff --git a/drape_frontend/drape_frontend.pro b/drape_frontend/drape_frontend.pro index f8c3cf092c..f736d50236 100755 --- a/drape_frontend/drape_frontend.pro +++ b/drape_frontend/drape_frontend.pro @@ -50,6 +50,7 @@ SOURCES += \ visual_params.cpp \ my_position.cpp \ user_event_stream.cpp \ + animation/modelview_angle_animation.cpp HEADERS += \ animation/base_viewport_animation.hpp \ @@ -99,3 +100,4 @@ HEADERS += \ visual_params.hpp \ my_position.hpp \ user_event_stream.hpp \ + animation/modelview_angle_animation.hpp diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index 6a359e6d55..81dfa5890d 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -1,4 +1,3 @@ -#include "drape_frontend/animation/modelview_center_animation.hpp" #include "drape_frontend/user_event_stream.hpp" #include "drape_frontend/visual_params.hpp" diff --git a/drape_head/qtoglcontext.cpp b/drape_head/qtoglcontext.cpp index 750dbe5b4c..9d72f9dc12 100644 --- a/drape_head/qtoglcontext.cpp +++ b/drape_head/qtoglcontext.cpp @@ -45,5 +45,5 @@ void QtOGLContext::present() void QtOGLContext::setDefaultFramebuffer() { - GLFunctions::glBindFramebuffer(GL_FRAMEBUFFER, 0); + GLFunctions::glBindFramebuffer(GL_FRAMEBUFFER, m_nativeContext->defaultFramebufferObject()); }