From cc2207b24751b9de40e3737ba1c7b6f742841d1c Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Fri, 20 Nov 2015 17:34:15 +0300 Subject: [PATCH] Correct setting of center. --- drape_frontend/navigator.cpp | 3 +-- drape_frontend/user_event_stream.cpp | 36 +++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/drape_frontend/navigator.cpp b/drape_frontend/navigator.cpp index c587d39d61..c831eb2fb4 100644 --- a/drape_frontend/navigator.cpp +++ b/drape_frontend/navigator.cpp @@ -183,8 +183,7 @@ ScreenBase const Navigator::ScaleInto(ScreenBase const & screen, m2::RectD bound m2::RectD clipRect = res.ClipRect(); - // TODO: This assert fails in 3d mode, do proper check. - //ASSERT(boundRect.IsPointInside(clipRect.Center()), ("center point should be inside boundRect")); + ASSERT(boundRect.IsPointInside(clipRect.Center()), ("center point should be inside boundRect")); if (clipRect.minX() < boundRect.minX()) { diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index c2498c8101..cf5670cd6f 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -313,13 +313,43 @@ bool UserEventStream::SetScale(m2::PointD const & pxScaleCenter, double factor, bool UserEventStream::SetCenter(m2::PointD const & center, int zoom, bool isAnim) { + m2::PointD targetCenter = center; + ang::Angle angle; + m2::RectD localRect; + + ScreenBase const &screen = GetCurrentScreen(); + double const scale3d = screen.PixelRect().SizeX() / screen.PixelRectIn3d().SizeX(); if (zoom == -1) { - m2::AnyRectD r = GetTargetRect(); - return SetRect(m2::AnyRectD(center, r.Angle(), r.GetLocalRect()), isAnim); + m2::AnyRectD const r = GetTargetRect(); + angle = r.Angle(); + localRect = r.GetLocalRect(); + } + else + { + angle = screen.GlobalRect().Angle(); + + localRect = df::GetRectForDrawScale(zoom, center); + CheckMinGlobalRect(localRect); + CheckMinMaxVisibleScale(m_isCountryLoaded, localRect, zoom); + + localRect.Offset(-center); + localRect.Scale(scale3d); + + double const aspectRatio = screen.PixelRect().SizeY() / screen.PixelRect().SizeX(); + if (aspectRatio > 1.0) + localRect.Inflate(0.0, localRect.SizeY() / 2.0 * aspectRatio); + else + localRect.Inflate(localRect.SizeX() / 2.0 / aspectRatio, 0.0); } - return SetRect(df::GetRectForDrawScale(zoom, center), zoom, true, isAnim); + if (screen.isPerspective()) + { + double const centerOffset3d = localRect.SizeY() * (1.0 - 1.0 / (scale3d * cos(screen.GetRotationAngle()))) / 2.0; + targetCenter = targetCenter.Move(centerOffset3d, angle.cos(), -angle.sin()); + } + + return SetRect(m2::AnyRectD(targetCenter, angle, localRect), isAnim); } bool UserEventStream::SetRect(m2::RectD rect, int zoom, bool applyRotation, bool isAnim)