From b116a92be3af709192fcdce8a787c64f6defeb8d Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 23 Oct 2020 12:21:16 +0200 Subject: [PATCH] Center the camera on the cursor at first tick of optical zoom --- GraphicsView/include/CGAL/Qt/qglviewer.h | 4 ++- GraphicsView/include/CGAL/Qt/qglviewer_impl.h | 26 ++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/GraphicsView/include/CGAL/Qt/qglviewer.h b/GraphicsView/include/CGAL/Qt/qglviewer.h index 540e15119a1..045ae469063 100644 --- a/GraphicsView/include/CGAL/Qt/qglviewer.h +++ b/GraphicsView/include/CGAL/Qt/qglviewer.h @@ -1167,7 +1167,6 @@ protected: QMap wheelBinding_; QMap clickBinding_; ::Qt::Key currentlyPressedKey_; - bool z_is_pressed; // S t a t e F i l e QString stateFileName_; @@ -1212,6 +1211,9 @@ protected: bool is_sharing; bool is_linked; QOpenGLContext* shared_context; + // Zoom + bool _first_tick; + public: //! Is used to know if the openGL context is 4.3 or ES 2.0. //! @returns `true` if the context is 4.3. diff --git a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h index 411f9d18bc2..add5d8df7fd 100644 --- a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h +++ b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h @@ -155,6 +155,7 @@ void CGAL::QGLViewer::defaultConstructor() { is_sharing = false; is_linked = false; shared_context = nullptr; + _first_tick = true; } CGAL_INLINE_FUNCTION @@ -1544,6 +1545,17 @@ void CGAL::QGLViewer::wheelEvent(QWheelEvent *e) { MouseActionPrivate map = wheelBinding_[wbp]; switch (map.handler) { case qglviewer::CAMERA: + if(currentlyPressedKey_ == ::Qt::Key_Z && _first_tick) + { + _first_tick = false; + makeCurrent(); + //orient camera to the cursor. + bool found = false; + qglviewer::Vec point; + point = camera()->pointUnderPixel(mapFromGlobal(QCursor::pos()), found); + if(found) + camera()->lookAt(point); + } camera()->frame()->startAction(map.action, map.withConstraint); camera()->frame()->wheelEvent(e, camera()); break; @@ -2263,21 +2275,11 @@ void CGAL::QGLViewer::keyPressEvent(QKeyEvent *e) { const ::Qt::Key key = ::Qt::Key(e->key()); - const ::Qt::KeyboardModifiers modifiers = e->modifiers(); - if(key == ::Qt::Key_Z && ! e->isAutoRepeat()) { - makeCurrent(); - //orient camera to the cursor. - bool found = false; - qglviewer::Vec point; - point = camera()->pointUnderPixel(mapFromGlobal(QCursor::pos()), found); - if(!found) - return; - camera()->lookAt(point); - update(); - return; + _first_tick = true; } + const ::Qt::KeyboardModifiers modifiers = e->modifiers(); QMap::ConstIterator it = keyboardBinding_ .begin(), end =