diff options
author | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2016-06-20 15:09:09 +0300 |
---|---|---|
committer | Daria Volvenkova <d.volvenkova@corp.mail.ru> | 2016-07-07 15:31:08 +0300 |
commit | fdf4f75816a9ba288d3d0d5108f13054890ad555 (patch) | |
tree | 262483bcadefe5b8e3f927853625e5d109ccd425 /drape_frontend | |
parent | eb300949c0f0a17b14976fac3ed047a3ae3e43df (diff) |
Automatic perspective angle calculation in ScreenBase.
Diffstat (limited to 'drape_frontend')
-rw-r--r-- | drape_frontend/animation_system.cpp | 21 | ||||
-rw-r--r-- | drape_frontend/animation_system.hpp | 7 | ||||
-rwxr-xr-x | drape_frontend/frontend_renderer.cpp | 18 | ||||
-rw-r--r-- | drape_frontend/navigator.cpp | 60 | ||||
-rw-r--r-- | drape_frontend/navigator.hpp | 4 | ||||
-rw-r--r-- | drape_frontend/screen_operations.cpp | 12 | ||||
-rw-r--r-- | drape_frontend/screen_operations.hpp | 2 | ||||
-rw-r--r-- | drape_frontend/user_event_stream.cpp | 43 | ||||
-rw-r--r-- | drape_frontend/user_event_stream.hpp | 1 |
9 files changed, 86 insertions, 82 deletions
diff --git a/drape_frontend/animation_system.cpp b/drape_frontend/animation_system.cpp index 886441d148..76d113ecdf 100644 --- a/drape_frontend/animation_system.cpp +++ b/drape_frontend/animation_system.cpp @@ -75,17 +75,22 @@ private: } // namespace -bool AnimationSystem::GetRect(ScreenBase const & currentScreen, m2::AnyRectD & rect) +void AnimationSystem::UpdateLastScreen(ScreenBase const & currentScreen) { - return GetRect(currentScreen, bind(&AnimationSystem::GetProperty, this, _1, _2, _3), rect); + m_lastScreen = currentScreen; +} + +bool AnimationSystem::GetScreen(ScreenBase const & currentScreen, ScreenBase & screen) +{ + return GetScreen(currentScreen, bind(&AnimationSystem::GetProperty, this, _1, _2, _3), screen); } -void AnimationSystem::GetTargetRect(ScreenBase const & currentScreen, m2::AnyRectD & rect) +void AnimationSystem::GetTargetScreen(ScreenBase const & currentScreen, ScreenBase & screen) { - GetRect(currentScreen, bind(&AnimationSystem::GetTargetProperty, this, _1, _2, _3), rect); + GetScreen(currentScreen, bind(&AnimationSystem::GetTargetProperty, this, _1, _2, _3), screen); } -bool AnimationSystem::GetRect(ScreenBase const & currentScreen, TGetPropertyFn const & getPropertyFn, m2::AnyRectD & rect) +bool AnimationSystem::GetScreen(ScreenBase const & currentScreen, TGetPropertyFn const & getPropertyFn, ScreenBase & screen) { ASSERT(getPropertyFn != nullptr, ()); @@ -105,10 +110,8 @@ bool AnimationSystem::GetRect(ScreenBase const & currentScreen, TGetPropertyFn c if (getPropertyFn(Animation::MapPlane, Animation::Position, value)) pos = value.m_valuePointD; - m2::RectD localRect = currentScreen.PixelRect(); - localRect.Offset(-localRect.Center()); - localRect.Scale(scale); - rect = m2::AnyRectD(pos, angle, localRect); + screen = currentScreen; + screen.SetFromParams(pos, angle, scale); return true; } diff --git a/drape_frontend/animation_system.hpp b/drape_frontend/animation_system.hpp index 7a23337e1a..c989da99f2 100644 --- a/drape_frontend/animation_system.hpp +++ b/drape_frontend/animation_system.hpp @@ -19,8 +19,9 @@ class AnimationSystem : private noncopyable public: static AnimationSystem & Instance(); - bool GetRect(ScreenBase const & currentScreen, m2::AnyRectD & rect); - void GetTargetRect(ScreenBase const & currentScreen, m2::AnyRectD & rect); + void UpdateLastScreen(ScreenBase const & currentScreen); + bool GetScreen(ScreenBase const & currentScreen, ScreenBase & screen); + void GetTargetScreen(ScreenBase const & currentScreen, ScreenBase & screen); bool SwitchPerspective(Animation::SwitchPerspectiveParams & params); bool GetPerspectiveAngle(double & angle); @@ -66,7 +67,7 @@ private: using TGetPropertyFn = function<bool (Animation::TObject object, Animation::TProperty property, Animation::PropertyValue & value)>; - bool GetRect(ScreenBase const & currentScreen, TGetPropertyFn const & getPropertyFn, m2::AnyRectD & rect); + bool GetScreen(ScreenBase const & currentScreen, TGetPropertyFn const & getPropertyFn, ScreenBase & screen); bool GetProperty(Animation::TObject object, Animation::TProperty property, Animation::PropertyValue & value) const; diff --git a/drape_frontend/frontend_renderer.cpp b/drape_frontend/frontend_renderer.cpp index 9b826a08c7..d8c9010db5 100755 --- a/drape_frontend/frontend_renderer.cpp +++ b/drape_frontend/frontend_renderer.cpp @@ -811,17 +811,24 @@ void FrontendRenderer::InvalidateRect(m2::RectD const & gRect) void FrontendRenderer::OnResize(ScreenBase const & screen) { - m2::RectD const viewportRect = screen.isPerspective() ? screen.PixelRectIn3d() : screen.PixelRect(); + m2::RectD const viewportRect = screen.PixelRectIn3d(); + double const kEps = 1e-5; + bool const viewportChanged = !m2::IsEqualSize(m_lastReadedModelView.PixelRectIn3d(), viewportRect, kEps, kEps); m_myPositionController->UpdatePixelPosition(screen); m_myPositionController->OnNewPixelRect(); - m_viewport.SetViewport(0, 0, viewportRect.SizeX(), viewportRect.SizeY()); - m_contextFactory->getDrawContext()->resize(viewportRect.SizeX(), viewportRect.SizeY()); + if (viewportChanged) + { + m_viewport.SetViewport(0, 0, viewportRect.SizeX(), viewportRect.SizeY()); + m_contextFactory->getDrawContext()->resize(viewportRect.SizeX(), viewportRect.SizeY()); + m_framebuffer->SetSize(viewportRect.SizeX(), viewportRect.SizeY()); + } + RefreshProjection(screen); RefreshPivotTransform(screen); - m_framebuffer->SetSize(viewportRect.SizeX(), viewportRect.SizeY()); + } void FrontendRenderer::AddToRenderGroup(dp::GLState const & state, @@ -1647,7 +1654,8 @@ void FrontendRenderer::PositionChanged(m2::PointD const & position) void FrontendRenderer::ChangeModelView(m2::PointD const & center, int zoomLevel) { - AddUserEvent(SetCenterEvent(center, zoomLevel, true)); + AddUserEvent(FollowAndRotateEvent(center, m_userEventStream.GetCurrentScreen().PixelRectIn3d().Center(), -m_userEventStream.GetCurrentScreen().GetAngle(), zoomLevel, true)); + //AddUserEvent(SetCenterEvent(center, zoomLevel, true)); } void FrontendRenderer::ChangeModelView(double azimuth) diff --git a/drape_frontend/navigator.cpp b/drape_frontend/navigator.cpp index 273e8c1194..ecaefccea2 100644 --- a/drape_frontend/navigator.cpp +++ b/drape_frontend/navigator.cpp @@ -26,18 +26,45 @@ Navigator::Navigator() { } -void Navigator::SetFromRects(m2::AnyRectD const & glbRect, m2::RectD const & pxRect) +void Navigator::SetFromRect2(m2::AnyRectD const & r) { + ScreenBase tmp = m_Screen; + m2::RectD const & worldR = df::GetWorldRect(); - m_Screen.SetFromRects(glbRect, pxRect); - m_Screen = ScaleInto(m_Screen, worldR); + tmp.SetFromRect2d(r); + tmp = ScaleInto(tmp, worldR); + + m_Screen = tmp; if (!m_InAction) + m_StartScreen = tmp; +} + +void Navigator::SetScreen(ScreenBase const & screen) +{ + m2::RectD const & worldR = df::GetWorldRect(); + ScreenBase tmp = screen; + tmp = ScaleInto(tmp, worldR); + + VisualParams const & p = VisualParams::Instance(); + + if (!CheckMaxScale(tmp, p.GetTileSize(), p.GetVisualScale())) { - m_StartScreen.SetFromRects(glbRect, pxRect); - m_StartScreen = ScaleInto(m_StartScreen, worldR); + int const scale = scales::GetUpperStyleScale() - 1; + m2::RectD newRect = df::GetRectForDrawScale(scale, screen.GetOrg()); + newRect.Scale(m_Screen.GetScale3d()); + CheckMinMaxVisibleScale(newRect, scale, m_Screen.GetScale3d()); + tmp = m_Screen; + tmp.SetFromRect(m2::AnyRectD(newRect)); + + ASSERT(CheckMaxScale(tmp, p.GetTileSize(), p.GetVisualScale()), ()); } + + m_Screen = tmp; + + if (!m_InAction) + m_StartScreen = tmp; } void Navigator::SetFromRect(m2::AnyRectD const & r) @@ -88,25 +115,11 @@ void Navigator::OnSize(int w, int h) { m2::RectD const & worldR = df::GetWorldRect(); - double const fov = m_Screen.GetAngleFOV(); - double const rotation = m_Screen.GetRotationAngle(); - if (m_Screen.isPerspective()) - { - m_Screen.ResetPerspective(); - m_StartScreen.ResetPerspective(); - } - m_Screen.OnSize(0, 0, w, h); m_Screen = ShrinkAndScaleInto(m_Screen, worldR); m_StartScreen.OnSize(0, 0, w, h); m_StartScreen = ShrinkAndScaleInto(m_StartScreen, worldR); - - if (fov != 0.0) - { - m_Screen.ApplyPerspective(rotation, rotation, fov); - m_StartScreen.ApplyPerspective(rotation, rotation, fov); - } } m2::PointD Navigator::GtoP(m2::PointD const & pt) const @@ -197,6 +210,7 @@ bool Navigator::ScaleImpl(m2::PointD const & newPt1, m2::PointD const & newPt2, { m2::PointD const center3d = oldPt1; m2::PointD const center2d = screen.P3dtoP(center3d); + m2::PointD const centerG = screen.PtoG(center2d); m2::PointD const offset = center2d - center3d; math::Matrix<double, 3, 3> const newM = screen.GtoPMatrix() * ScreenBase::CalcTransform(oldPt1 + offset, oldPt2 + offset, @@ -204,6 +218,7 @@ bool Navigator::ScaleImpl(m2::PointD const & newPt1, m2::PointD const & newPt2, doRotateScreen); ScreenBase tmp = screen; tmp.SetGtoPMatrix(newM); + tmp.MatchGandP3d(centerG, center3d); if (!skipMinScaleAndBordersCheck && !CheckMinScale(tmp)) return false; @@ -310,13 +325,6 @@ void Navigator::Disable3dMode() m_Screen.ResetPerspective(); } -bool Navigator::UpdatePerspective() -{ - double const maxPerspAngle = m_Screen.GetMaxRotationAngle(); - m_Screen.UpdatePerspectiveParameters(); - return maxPerspAngle != m_Screen.GetMaxRotationAngle(); -} - m2::AnyRectD ToRotated(Navigator const & navigator, m2::RectD const & rect) { double const dx = rect.SizeX(); diff --git a/drape_frontend/navigator.hpp b/drape_frontend/navigator.hpp index 01c3272d95..25d9ea0fbb 100644 --- a/drape_frontend/navigator.hpp +++ b/drape_frontend/navigator.hpp @@ -18,9 +18,10 @@ class Navigator public: Navigator(); + void SetScreen(ScreenBase const & screen); void SetFromRect(m2::AnyRectD const & r); + void SetFromRect2(m2::AnyRectD const & r); void CenterViewport(m2::PointD const & p); - void SetFromRects(m2::AnyRectD const & glbRect, m2::RectD const & pxRect); void SetFromRect(m2::AnyRectD const & r, uint32_t tileSize, double visualScale); void OnSize(int w, int h); @@ -48,7 +49,6 @@ public: void Enable3dMode(double currentRotationAngle, double maxRotationAngle, double angleFOV); void SetRotationIn3dMode(double rotationAngle); void Disable3dMode(); - bool UpdatePerspective(); private: // Internal screen corresponding to the state when navigation began with StartDrag or StartScale. diff --git a/drape_frontend/screen_operations.cpp b/drape_frontend/screen_operations.cpp index 5060097425..acc083dedc 100644 --- a/drape_frontend/screen_operations.cpp +++ b/drape_frontend/screen_operations.cpp @@ -272,16 +272,4 @@ bool ApplyScale(m2::PointD const & pixelScaleCenter, double factor, ScreenBase & return true; } -double CalculatePerspectiveAngle(ScreenBase const & screen) -{ - double const kStartPerspectiveScale = 0.5; - double const kMaxScale = 0.2; - double const kMaxPerspectiveAngle = math::pi4; - - double const currentScale = screen.GetScale(); - if (currentScale > kStartPerspectiveScale) - return 0.0; - return kMaxPerspectiveAngle * (kStartPerspectiveScale - currentScale) / (kStartPerspectiveScale - kMaxScale); -} - } // namespace df diff --git a/drape_frontend/screen_operations.hpp b/drape_frontend/screen_operations.hpp index e9239180e5..dd34bdad7e 100644 --- a/drape_frontend/screen_operations.hpp +++ b/drape_frontend/screen_operations.hpp @@ -28,6 +28,4 @@ m2::PointD CalculateCenter(double scale, m2::RectD const & pixelRect, bool ApplyScale(m2::PointD const & pixelScaleCenter, double factor, ScreenBase & screen); -double CalculatePerspectiveAngle(ScreenBase const & screen); - } // namespace df diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index d5d7e10092..0f7c91dbbd 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -147,6 +147,8 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChanged, bool swap(m_events, events); } + m2::RectD const prevPixelRect = GetCurrentScreen().PixelRect(); + m_modelViewChanged = !events.empty() || m_state == STATE_SCALE || m_state == STATE_DRAG; for (UserEvent const & e : events) { @@ -163,7 +165,6 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChanged, bool break; case UserEvent::EVENT_RESIZE: m_navigator.OnSize(e.m_resize.m_width, e.m_resize.m_height); - m_viewportChanged = true; breakAnim = true; TouchCancel(m_touches); if (m_state == STATE_DOUBLE_TAP_HOLD) @@ -268,12 +269,13 @@ ScreenBase const & UserEventStream::ProcessEvents(bool & modelViewChanged, bool } if (m_modelViewChanged) - m_viewportChanged |= m_navigator.UpdatePerspective(); + m_animationSystem.UpdateLastScreen(GetCurrentScreen()); modelViewChanged = m_modelViewChanged; - viewportChanged = m_viewportChanged; + + double const kEps = 1e-5; + viewportChanged = !m2::IsEqualSize(prevPixelRect, GetCurrentScreen().PixelRect(), kEps, kEps); m_modelViewChanged = false; - m_viewportChanged = false; return m_navigator.Screen(); } @@ -282,9 +284,9 @@ void UserEventStream::ApplyAnimations() { if (m_animationSystem.AnimationExists(Animation::MapPlane)) { - m2::AnyRectD rect; - if (m_animationSystem.GetRect(GetCurrentScreen(), rect)) - m_navigator.SetFromRect(rect); + ScreenBase screen; + if (m_animationSystem.GetScreen(GetCurrentScreen(), screen)) + m_navigator.SetScreen(screen); Animation::SwitchPerspectiveParams switchPerspective; if (m_animationSystem.SwitchPerspective(switchPerspective)) @@ -298,7 +300,6 @@ void UserEventStream::ApplyAnimations() { m_navigator.Disable3dMode(); } - m_viewportChanged = true; } double perspectiveAngle; @@ -434,15 +435,15 @@ bool UserEventStream::SetCenter(m2::PointD const & center, int zoom, bool isAnim bool UserEventStream::SetRect(m2::RectD rect, int zoom, bool applyRotation, bool isAnim) { - ScreenBase const & screen = GetCurrentScreen(); - CheckMinGlobalRect(rect, screen.GetScale3d()); - CheckMinMaxVisibleScale(rect, zoom, screen.GetScale3d()); + CheckMinGlobalRect(rect, kDefault3dScale); + CheckMinMaxVisibleScale(rect, zoom, kDefault3dScale); m2::AnyRectD targetRect = applyRotation ? ToRotated(m_navigator, rect) : m2::AnyRectD(rect); return SetRect(targetRect, isAnim); } bool UserEventStream::SetRect(m2::AnyRectD const & rect, bool isAnim) { + isAnim = false; if (isAnim) { auto onStartHandler = [this](ref_ptr<Animation> animation) @@ -473,7 +474,7 @@ bool UserEventStream::SetRect(m2::AnyRectD const & rect, bool isAnim) } ResetMapPlaneAnimations(); - m_navigator.SetFromRect(rect); + m_navigator.SetFromRect2(rect); return true; } @@ -581,10 +582,9 @@ bool UserEventStream::FilterEventWhile3dAnimation(UserEvent::EEventType type) co void UserEventStream::SetEnable3dMode(double maxRotationAngle, double angleFOV, bool isAnim, bool immediatelyStart) { - ResetAnimationsBeforeSwitch3D(); + return; - //m_navigator.Enable3dMode(0.0, maxRotationAngle, angleFOV); - //return; + ResetAnimationsBeforeSwitch3D(); if (immediatelyStart) InterruptFollowAnimations(true /* force */); @@ -609,12 +609,11 @@ void UserEventStream::SetEnable3dMode(double maxRotationAngle, double angleFOV, void UserEventStream::SetDisable3dModeAnimation() { + return; + ResetAnimationsBeforeSwitch3D(); InterruptFollowAnimations(true /* force */); - //m_navigator.Disable3dMode(); - //return; - if (m_discardedFOV > 0.0 && IsScaleAllowableIn3d(GetDrawTileScale(GetCurrentScreen()))) { m_discardedFOV = m_discardedAngle = 0.0; @@ -676,9 +675,9 @@ m2::AnyRectD UserEventStream::GetCurrentRect() const m2::AnyRectD UserEventStream::GetTargetRect() const { - m2::AnyRectD targetRect; - m_animationSystem.GetTargetRect(m_navigator.Screen(), targetRect); - return targetRect; + ScreenBase targetScreen; + m_animationSystem.GetTargetScreen(m_navigator.Screen(), targetScreen); + return targetScreen.GlobalRect(); } bool UserEventStream::ProcessTouch(TouchEvent const & touch) @@ -1232,7 +1231,7 @@ void UserEventStream::UpdateDoubleTapAndHold(Touch const & touch) TEST_CALL(DOUBLE_TAP_AND_HOLD); ASSERT_EQUAL(m_state, STATE_DOUBLE_TAP_HOLD, ()); float const kPowerModifier = 10.0f; - float const scaleFactor = exp(kPowerModifier * (touch.m_location.y - m_startDoubleTapAndHold.y) / GetCurrentScreen().PixelRect().SizeY()); + float const scaleFactor = exp(kPowerModifier * (touch.m_location.y - m_startDoubleTapAndHold.y) / GetCurrentScreen().PixelRectIn3d().SizeY()); m_startDoubleTapAndHold = touch.m_location; m2::PointD scaleCenter = m_startDragOrg; diff --git a/drape_frontend/user_event_stream.hpp b/drape_frontend/user_event_stream.hpp index ebb5cab618..28d926f428 100644 --- a/drape_frontend/user_event_stream.hpp +++ b/drape_frontend/user_event_stream.hpp @@ -383,7 +383,6 @@ private: AnimationSystem & m_animationSystem; bool m_modelViewChanged = false; - bool m_viewportChanged = false; bool m_perspectiveAnimation = false; unique_ptr<UserEvent> m_pendingEvent; |