diff --git a/drape_frontend/animation/model_view_animation.cpp b/drape_frontend/animation/model_view_animation.cpp index 970f6112be..99c5dd94d6 100644 --- a/drape_frontend/animation/model_view_animation.cpp +++ b/drape_frontend/animation/model_view_animation.cpp @@ -171,14 +171,11 @@ m2::PointD FollowAndRotateAnimation::CalculateCenter(m2::RectD const & localRect m2::PointD const & userPos, m2::PointD const & pixelPos, double azimuth) { - m2::PointD formingVector = pixelRect.Center() - pixelPos; - formingVector.x *= (localRect.SizeX() / pixelRect.SizeX()); - formingVector.y *= (localRect.SizeY() / pixelRect.SizeY()); - double const centerOffset = formingVector.Length(); - - m2::PointD viewVector = userPos.Move(1.0, azimuth + math::pi2) - userPos; - viewVector.Normalize(); - return userPos + (viewVector * centerOffset); + double const scale = localRect.SizeX() / pixelRect.SizeX(); + m2::PointD formingVector = (pixelRect.Center() - pixelPos) * scale; + formingVector.y = -formingVector.y; + formingVector.Rotate(azimuth); + return userPos + formingVector; } m2::AnyRectD FollowAndRotateAnimation::GetRect(ScreenBase const & screen, double elapsedTime) const diff --git a/drape_frontend/my_position_controller.cpp b/drape_frontend/my_position_controller.cpp index f69aa54f8f..d39b32b78b 100644 --- a/drape_frontend/my_position_controller.cpp +++ b/drape_frontend/my_position_controller.cpp @@ -172,9 +172,9 @@ void MyPositionController::CorrectScalePoint(m2::PointD & pt1, m2::PointD & pt2) { if (IsModeChangeViewport()) { - m2::PointD const ptDiff = GetCurrentPixelBinding() - ((pt1 + pt2) * 0.5); - pt1 += ptDiff; - pt2 += ptDiff; + m2::PointD const oldPt1(pt1); + pt1 = GetCurrentPixelBinding(); + pt2 = pt2 - oldPt1 + pt1; } } diff --git a/drape_frontend/navigator.cpp b/drape_frontend/navigator.cpp index d4ee02f7b9..29927161a9 100644 --- a/drape_frontend/navigator.cpp +++ b/drape_frontend/navigator.cpp @@ -415,13 +415,11 @@ bool Navigator::ScaleImpl(m2::PointD const & newPt1, m2::PointD const & newPt2, bool skipMinScaleAndBordersCheck, bool doRotateScreen, ScreenBase & screen) { - math::Matrix const newM = screen.GtoPMatrix() * ScreenBase::CalcTransform(oldPt1, oldPt2, newPt1, newPt2); - - double oldAngle = screen.GetAngle(); + math::Matrix const newM = + screen.GtoPMatrix() * ScreenBase::CalcTransform(oldPt1, oldPt2, + newPt1, newPt2, doRotateScreen); ScreenBase tmp = screen; tmp.SetGtoPMatrix(newM); - if (!doRotateScreen) - tmp.Rotate(-(tmp.GetAngle() - oldAngle)); if (!skipMinScaleAndBordersCheck && !CheckMinScale(tmp)) return false; diff --git a/geometry/geometry_tests/screen_test.cpp b/geometry/geometry_tests/screen_test.cpp index 529a30e909..943a8cbe67 100644 --- a/geometry/geometry_tests/screen_test.cpp +++ b/geometry/geometry_tests/screen_test.cpp @@ -98,7 +98,8 @@ UNIT_TEST(ScreenBase_CalcTransform) math::Matrix m = ScreenBase::CalcTransform( m2::PointD(0, 1), m2::PointD(1, 1), m2::PointD( s * sin(a) + dx, s * cos(a) + dy), - m2::PointD(s * cos(a) + s * sin(a) + dx, -s * sin(a) + s * cos(a) + dy)); + m2::PointD(s * cos(a) + s * sin(a) + dx, -s * sin(a) + s * cos(a) + dy), + true /* allow rotate */); ScreenBase::ExtractGtoPParams(m, a1, s1, dx1, dy1); diff --git a/geometry/screenbase.cpp b/geometry/screenbase.cpp index 08af3c49a0..fdd0f8cb8d 100644 --- a/geometry/screenbase.cpp +++ b/geometry/screenbase.cpp @@ -153,10 +153,11 @@ int ScreenBase::GetHeight() const ScreenBase::MatrixT const ScreenBase::CalcTransform(m2::PointD const & oldPt1, m2::PointD const & oldPt2, - m2::PointD const & newPt1, m2::PointD const & newPt2) + m2::PointD const & newPt1, m2::PointD const & newPt2, + bool allowRotate) { - double s = newPt1.Length(newPt2) / oldPt1.Length(oldPt2); - double a = ang::AngleTo(newPt1, newPt2) - ang::AngleTo(oldPt1, oldPt2); + double const s = newPt1.Length(newPt2) / oldPt1.Length(oldPt2); + double const a = allowRotate ? ang::AngleTo(newPt1, newPt2) - ang::AngleTo(oldPt1, oldPt2) : 0.0; MatrixT m = math::Shift( diff --git a/geometry/screenbase.hpp b/geometry/screenbase.hpp index bfa912e302..eb767e365f 100644 --- a/geometry/screenbase.hpp +++ b/geometry/screenbase.hpp @@ -116,7 +116,8 @@ public: /// Compute arbitrary pixel transformation, that translates the (oldPt1, oldPt2) -> (newPt1, newPt2) static MatrixT const CalcTransform(m2::PointD const & oldPt1, m2::PointD const & oldPt2, - m2::PointD const & newPt1, m2::PointD const & newPt2); + m2::PointD const & newPt1, m2::PointD const & newPt2, + bool allowRotate); /// Setting GtoP matrix extracts the Angle and m_Org parameters, leaving PixelRect intact void SetGtoPMatrix(MatrixT const & m);