From 621f187fe6df06dc8ba2ad4fcf3c73744880da3e Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Thu, 21 Apr 2016 15:11:58 +0300 Subject: [PATCH] Perspective enabling fixed. --- drape_frontend/animation_system.cpp | 16 +++++++++- drape_frontend/animation_system.h | 3 ++ drape_frontend/user_event_stream.cpp | 45 ++++++++++++++-------------- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/drape_frontend/animation_system.cpp b/drape_frontend/animation_system.cpp index f52e753446..63e92679f5 100644 --- a/drape_frontend/animation_system.cpp +++ b/drape_frontend/animation_system.cpp @@ -201,6 +201,14 @@ AngleInterpolator::AngleInterpolator(double delay, double startAngle, double end { } +AngleInterpolator::AngleInterpolator(double delay, double duration, double startAngle, double endAngle) + : Interpolator(duration, delay) + , m_startAngle(startAngle) + , m_endAngle(endAngle) + , m_angle(startAngle) +{ +} + void AngleInterpolator::Advance(double elapsedSeconds) { TBase::Advance(elapsedSeconds); @@ -551,11 +559,17 @@ Animation::PropertyValue MapFollowAnimation::GetProperty(TObject object, TProper PerspectiveSwitchAnimation::PerspectiveSwitchAnimation(double startAngle, double endAngle) : Animation(false, false) { - m_angleInterpolator = make_unique_dp(startAngle, endAngle); + m_angleInterpolator = make_unique_dp(GetRotateDuration(startAngle, endAngle), startAngle, endAngle); m_objects.insert(Animation::MapPlane); m_properties.insert(Animation::AnglePerspective); } +// static +double PerspectiveSwitchAnimation::GetRotateDuration(double startAngle, double endAngle) +{ + return 0.5 * fabs(endAngle - startAngle) / math::pi4; +} + Animation::TObjectProperties const & PerspectiveSwitchAnimation::GetProperties(TObject object) const { ASSERT(object == Animation::MapPlane, ()); diff --git a/drape_frontend/animation_system.h b/drape_frontend/animation_system.h index 9f03206ebb..5fc3b0a6da 100644 --- a/drape_frontend/animation_system.h +++ b/drape_frontend/animation_system.h @@ -195,6 +195,7 @@ class AngleInterpolator: public Interpolator public: AngleInterpolator(double startAngle, double endAngle); AngleInterpolator(double delay, double startAngle, double endAngle); + AngleInterpolator(double delay, double duration, double startAngle, double endAngle); static double GetRotateDuration(double startAngle, double endAngle); @@ -250,6 +251,8 @@ class PerspectiveSwitchAnimation : public Animation public: PerspectiveSwitchAnimation(double startAngle, double endAngle); + static double GetRotateDuration(double startAngle, double endAngle); + Animation::Type GetType() const override { return Animation::MapPerspective; } TAnimObjects const & GetObjects() const override diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index 43491875ce..bf47cfd0e7 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -259,11 +259,13 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChange, bool & { double const angle = AnimationSystem::Instance().GetPerspectiveAngle(screen.GetRotationAngle()); m_navigator.SetRotationIn3dMode(angle); - //TouchCancel(m_touches); } modelViewChange = true; } + if (m_perspectiveAnimation) + TouchCancel(m_touches); + if (GetValidTouchesCount(m_touches) == 1) { if (m_state == STATE_WAIT_DOUBLE_TAP) @@ -500,7 +502,7 @@ bool UserEventStream::SetFollowAndRotate(m2::PointD const & userPos, m2::PointD targetLocalRect.SizeY() / screen.PixelRect().SizeY()); drape_ptr anim = make_unique_dp(userPos, screen.GetScale(), targetScale, screen.GetAngle(), -azimuth, - screen.GtoP(userPos), pixelPos, screen.PixelRectIn3d()); + screen.GtoP(userPos), pixelPos, screen.PixelRect()); if (df::IsAnimationAllowed(anim->GetDuration(), screen)) { @@ -533,32 +535,28 @@ void UserEventStream::SetEnable3dMode(double maxRotationAngle, double angleFOV, double const startAngle = isAnim ? 0.0 : maxRotationAngle; double const endAngle = maxRotationAngle; - if (isAnim || !immediatelyStart) + + drape_ptr anim = make_unique_dp(startAngle, endAngle); + anim->SetOnStartAction([this, startAngle, endAngle, angleFOV, &viewportChanged](Animation const &) { - drape_ptr anim = make_unique_dp(startAngle, endAngle); - anim->SetOnStartAction([this, startAngle, endAngle, angleFOV](Animation const &) - { - m_perspectiveAnimation = true; - m_navigator.Enable3dMode(startAngle, endAngle, angleFOV); - }); - anim->SetOnFinishAction([this](Animation const &) - { - m_perspectiveAnimation = false; - }); - if (immediatelyStart) - { - //AnimationSystem::Instance().FinishObjectAnimations(Animation::MapPlane, false /* rewind */); - AnimationSystem::Instance().AddAnimation(move(anim), true /* force */); - } - else - AnimationSystem::Instance().PushAnimation(move(anim)); - } + m_perspectiveAnimation = true; + m_navigator.SetFromRect(AnimationSystem::Instance().GetRect(GetCurrentScreen(), viewportChanged)); + m_navigator.Enable3dMode(startAngle, endAngle, angleFOV); + }); + anim->SetOnFinishAction([this](Animation const &) + { + m_perspectiveAnimation = false; + }); + if (immediatelyStart) + AnimationSystem::Instance().AddAnimation(move(anim), true /* force */); + else + AnimationSystem::Instance().PushAnimation(move(anim)); } void UserEventStream::SetDisable3dModeAnimation(bool & viewportChanged) { AnimationSystem::Instance().FinishAnimations(Animation::MapLinear, true /* rewind */); - //AnimationSystem::Instance().FinishObjectAnimations(Animation::MapPlane, false /* rewind */); + m_navigator.SetFromRect(AnimationSystem::Instance().GetRect(GetCurrentScreen(), viewportChanged)); double const startAngle = m_navigator.Screen().GetRotationAngle(); @@ -569,9 +567,10 @@ void UserEventStream::SetDisable3dModeAnimation(bool & viewportChanged) { m_perspectiveAnimation = true; }); - anim->SetOnFinishAction([this](Animation const &) + anim->SetOnFinishAction([this, &viewportChanged](Animation const &) { m_perspectiveAnimation = false; + m_navigator.SetFromRect(AnimationSystem::Instance().GetRect(GetCurrentScreen(), viewportChanged)); m_navigator.Disable3dMode(); if (m_pendingEvent != nullptr && m_pendingEvent->m_type == UserEvent::EVENT_SET_RECT) {