diff --git a/ApplicationCode/UserInterface/RiuCadNavigation.cpp b/ApplicationCode/UserInterface/RiuCadNavigation.cpp index 26a5869a62..edea8f4cee 100644 --- a/ApplicationCode/UserInterface/RiuCadNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuCadNavigation.cpp @@ -60,7 +60,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) cvfEventPos(me->x(), me->y(), &translatedMousePosX, &translatedMousePosY); if (me->button() == Qt::MidButton && me->modifiers() == Qt::NoModifier && isRotationEnabled()) - { + { cvf::HitItemCollection hic; bool hitSomething = m_viewer->rayPick( me->x(), me->y(), &hic); @@ -86,6 +86,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) m_hasMovedMouseDuringNavigation = false; isEventHandled = true; } + forcePointOfInterestUpdateDuringNextWheelZoom(); } break; case QEvent::MouseButtonRelease: @@ -103,6 +104,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) } } + forcePointOfInterestUpdateDuringNextWheelZoom(); } break; case QEvent::MouseMove: @@ -133,11 +135,12 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) { if (inputEvent->modifiers() == Qt::NoModifier) { - initializeRotationCenter(); + QWheelEvent* we = static_cast(inputEvent); + + updatePointOfInterestDuringZoomIfNecessary(we->x(), we->y()); + if (m_isRotCenterInitialized) { - QWheelEvent* we = static_cast ( inputEvent); - int translatedMousePosX, translatedMousePosY; cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY); diff --git a/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp b/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp index 25ead7cfba..41aa323e60 100644 --- a/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp @@ -89,6 +89,7 @@ bool RiuGeoQuestNavigation::handleInputEvent(QInputEvent* inputEvent) isEventHandled = true; } } + forcePointOfInterestUpdateDuringNextWheelZoom(); } break; case QEvent::MouseButtonRelease: @@ -144,11 +145,12 @@ bool RiuGeoQuestNavigation::handleInputEvent(QInputEvent* inputEvent) { if (inputEvent->modifiers() == Qt::NoModifier) { - initializeRotationCenter(); + QWheelEvent* we = static_cast(inputEvent); + + updatePointOfInterestDuringZoomIfNecessary(we->x(), we->y()); + if (m_isRotCenterInitialized) { - QWheelEvent* we = static_cast(inputEvent); - int translatedMousePosX, translatedMousePosY; cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY); diff --git a/ApplicationCode/UserInterface/RiuRmsNavigation.cpp b/ApplicationCode/UserInterface/RiuRmsNavigation.cpp index f081ec8588..8ca48f53cb 100644 --- a/ApplicationCode/UserInterface/RiuRmsNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuRmsNavigation.cpp @@ -105,7 +105,7 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent) m_isZooming = true; } } - + forcePointOfInterestUpdateDuringNextWheelZoom(); } break; case QEvent::MouseButtonRelease: @@ -130,6 +130,7 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent) m_hasMovedMouseDuringNavigation = false; } } + forcePointOfInterestUpdateDuringNextWheelZoom(); } break; case QEvent::MouseMove: @@ -169,7 +170,10 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent) { if (inputEvent->modifiers() == Qt::NoModifier) { - initializeRotationCenter(); + QWheelEvent* we = static_cast(inputEvent); + + updatePointOfInterestDuringZoomIfNecessary(we->x(), we->y()); + if (m_isRotCenterInitialized) { QWheelEvent* we = static_cast ( inputEvent); diff --git a/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp b/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp index a8340535bc..13b4c39e02 100644 --- a/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp @@ -104,6 +104,7 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent) m_hasMovedMouseDuringNavigation = false; isEventHandled = true; } + forcePointOfInterestUpdateDuringNextWheelZoom(); } break; case QEvent::MouseButtonRelease: @@ -121,6 +122,7 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent) } } + forcePointOfInterestUpdateDuringNextWheelZoom(); } break; case QEvent::MouseMove: @@ -151,11 +153,12 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent) { if (inputEvent->modifiers() == Qt::NoModifier) { - initializeRotationCenter(); + QWheelEvent* we = static_cast(inputEvent); + + updatePointOfInterestDuringZoomIfNecessary(we->x(), we->y()); + if (m_isRotCenterInitialized) { - QWheelEvent* we = static_cast ( inputEvent); - int translatedMousePosX, translatedMousePosY; cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY); diff --git a/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp b/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp index 0a7f233ae6..a5b205f421 100644 --- a/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp @@ -42,6 +42,7 @@ #include "cvfRay.h" #include "cvfManipulatorTrackball.h" +#include #include #include "cvfTrace.h" @@ -68,6 +69,7 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent) { if (! inputEvent) return false; bool isEventHandled = false; + switch (inputEvent->type()) { case QEvent::MouseButtonPress: @@ -123,6 +125,7 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent) m_isZooming = true; } } + forcePointOfInterestUpdateDuringNextWheelZoom(); } break; case QEvent::MouseButtonRelease: @@ -147,6 +150,7 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent) m_hasMovedMouseDuringNavigation = false; } } + forcePointOfInterestUpdateDuringNextWheelZoom(); } break; case QEvent::MouseMove: @@ -186,11 +190,12 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent) { if (inputEvent->modifiers() == Qt::NoModifier) { - initializeRotationCenter(); + QWheelEvent* we = static_cast(inputEvent); + + updatePointOfInterestDuringZoomIfNecessary(we->x(), we->y()); + if (m_isRotCenterInitialized) { - QWheelEvent* we = static_cast ( inputEvent); - int translatedMousePosX, translatedMousePosY; cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY); diff --git a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp index e71b46b904..b1fc7a0db0 100644 --- a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp @@ -45,6 +45,7 @@ #include "cvfRay.h" #include "cvfManipulatorTrackball.h" +#include #include #include @@ -59,6 +60,8 @@ caf::TrackBallBasedNavigation::TrackBallBasedNavigation() : m_isZooming(false), m_lastPosX(0), m_lastPosY(0), + m_lastWheelZoomPosX(-1), + m_lastWheelZoomPosY(-1), m_consumeEvents(false) { @@ -86,6 +89,8 @@ void caf::TrackBallBasedNavigation::init() m_isZooming = false; m_lastPosX = 0; m_lastPosY = 0; + m_lastWheelZoomPosX = -1; + m_lastWheelZoomPosY = -1; } //-------------------------------------------------------------------------------------------------- @@ -149,7 +154,39 @@ void caf::TrackBallBasedNavigation::setPointOfInterest(cvf::Vec3d poi) m_trackball->setRotationPoint(poi); m_isRotCenterInitialized = true; m_viewer->updateParallelProjectionCameraPosFromPointOfInterestMove(m_pointOfInterest); +} +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void caf::TrackBallBasedNavigation::updatePointOfInterestDuringZoomIfNecessary(int zoomX, int zoomY) +{ + bool hitSomething = false; + cvf::HitItemCollection hic; + if (shouldRaytraceForNewPoiDuringWheelZoom(zoomX, zoomY)) + { + hitSomething = m_viewer->rayPick(zoomX, zoomY, &hic); + updateWheelZoomPosition(zoomX, zoomY); + } + + if (hitSomething) + { + cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint(); + this->setPointOfInterest(pointOfInterest); + } + else + { + initializeRotationCenter(); + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void caf::TrackBallBasedNavigation::forcePointOfInterestUpdateDuringNextWheelZoom() +{ + m_lastWheelZoomPosX = -1; + m_lastWheelZoomPosY = -1; } //-------------------------------------------------------------------------------------------------- @@ -230,3 +267,33 @@ cvf::ref caf::TrackBallBasedNavigation::createZoomRay(int cvfXPos, int return ray; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void caf::TrackBallBasedNavigation::updateWheelZoomPosition(int zoomX, int zoomY) +{ + m_lastWheelZoomPosX = zoomX; + m_lastWheelZoomPosY = zoomY; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool caf::TrackBallBasedNavigation::shouldRaytraceForNewPoiDuringWheelZoom(int zoomX, int zoomY) const +{ + // Raytrace if the last zoom position isn't set + if (m_lastWheelZoomPosX == -1 || m_lastWheelZoomPosY == -1) + { + return true; + } + int diffX = zoomX - m_lastWheelZoomPosX; + int diffY = zoomY - m_lastWheelZoomPosY; + + const int pixelThreshold = 5; + if (diffX * diffX + diffY * diffY > pixelThreshold * pixelThreshold) + { + return true; + } + return false; +} diff --git a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h index a27596fb12..e2ddd26ec6 100644 --- a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h +++ b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h @@ -37,6 +37,8 @@ #include "cafNavigationPolicy.h" +#include + namespace cvf { class ManipulatorTrackball; class Ray; @@ -68,6 +70,8 @@ protected: virtual void setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ); virtual cvf::Vec3d pointOfInterest(); virtual void setPointOfInterest(cvf::Vec3d poi); + void updatePointOfInterestDuringZoomIfNecessary(int zoomX, int zoomY); + void forcePointOfInterestUpdateDuringNextWheelZoom(); // Track ball navigation specific void initializeRotationCenter(); @@ -91,9 +95,15 @@ protected: bool isSupposedToConsumeEvents() { return m_consumeEvents; } bool isRotationEnabled() { return m_isRotationEnabled; } +private: + void updateWheelZoomPosition(int zoomX, int zoomY); + bool shouldRaytraceForNewPoiDuringWheelZoom(int zoomX, int zoomY) const; + private: bool m_consumeEvents; bool m_isRotationEnabled; + int m_lastWheelZoomPosX; + int m_lastWheelZoomPosY; }; } // End namespace caf