#4857 AppFwk: Add handling of comparison view to the 3d navigation policies

This commit is contained in:
Jacob Støren 2019-10-16 14:08:16 +02:00
parent d438158691
commit e3dc32bd71
4 changed files with 38 additions and 42 deletions

View File

@ -79,18 +79,7 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
if (me->button() == Qt::MidButton && me->modifiers() == Qt::NoModifier && isRotationEnabled()) if (me->button() == Qt::MidButton && me->modifiers() == Qt::NoModifier && isRotationEnabled())
{ {
cvf::HitItemCollection hic; this->pickAndSetPointOfInterest(me->x(), me->y());
bool hitSomething = m_viewer->rayPick( me->x(), me->y(), &hic);
if (hitSomething)
{
cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint();
this->setPointOfInterest(pointOfInterest);
}
else
{
initializeRotationCenter();
}
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY); m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
m_roationSensitivityCalculator.init(me); m_roationSensitivityCalculator.init(me);

View File

@ -81,18 +81,7 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent)
if (me->button() == Qt::RightButton && isRotationEnabled()) if (me->button() == Qt::RightButton && isRotationEnabled())
{ {
cvf::HitItemCollection hic; this->pickAndSetPointOfInterest(me->x(), me->y());
bool hitSomething = m_viewer->rayPick( me->x(), me->y(), &hic);
if (hitSomething)
{
cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint();
this->setPointOfInterest(pointOfInterest);
}
else
{
initializeRotationCenter();
}
m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY); m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY);
m_roationSensitivityCalculator.init(me); m_roationSensitivityCalculator.init(me);

View File

@ -159,19 +159,20 @@ void caf::TrackBallBasedNavigation::setPointOfInterest(cvf::Vec3d poi)
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void caf::TrackBallBasedNavigation::updatePointOfInterestDuringZoomIfNecessary(int zoomX, int zoomY) void caf::TrackBallBasedNavigation::pickAndSetPointOfInterest(int winPosX, int winPosY)
{ {
bool hitSomething = false;
cvf::HitItemCollection hic; cvf::HitItemCollection hic;
if (shouldRaytraceForNewPoiDuringWheelZoom(zoomX, zoomY)) bool hitSomething = m_viewer->rayPick( winPosX, winPosY, &hic);
{
hitSomething = m_viewer->rayPick(zoomX, zoomY, &hic);
updateWheelZoomPosition(zoomX, zoomY);
}
if (hitSomething) if (hitSomething)
{ {
cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint(); cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint();
if (m_viewer->isMousePosWithinComparisonView( winPosX, winPosY ))
{
pointOfInterest -= m_viewer->comparisonViewEyePointOffset();
}
this->setPointOfInterest(pointOfInterest); this->setPointOfInterest(pointOfInterest);
} }
else else
@ -180,6 +181,22 @@ void caf::TrackBallBasedNavigation::updatePointOfInterestDuringZoomIfNecessary(i
} }
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void caf::TrackBallBasedNavigation::updatePointOfInterestDuringZoomIfNecessary(int winPosX, int winPosY)
{
if (shouldRaytraceForNewPoiDuringWheelZoom(winPosX, winPosY))
{
this->pickAndSetPointOfInterest(winPosX, winPosY);
updateWheelZoomPosition(winPosX, winPosY);
}
else
{
initializeRotationCenter();
}
}
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -271,24 +288,24 @@ cvf::ref<cvf::Ray> caf::TrackBallBasedNavigation::createZoomRay(int cvfXPos, int
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void caf::TrackBallBasedNavigation::updateWheelZoomPosition(int zoomX, int zoomY) void caf::TrackBallBasedNavigation::updateWheelZoomPosition(int winPosX, int winPosY)
{ {
m_lastWheelZoomPosX = zoomX; m_lastWheelZoomPosX = winPosX;
m_lastWheelZoomPosY = zoomY; m_lastWheelZoomPosY = winPosY;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
bool caf::TrackBallBasedNavigation::shouldRaytraceForNewPoiDuringWheelZoom(int zoomX, int zoomY) const bool caf::TrackBallBasedNavigation::shouldRaytraceForNewPoiDuringWheelZoom(int winPosX, int winPosY) const
{ {
// Raytrace if the last zoom position isn't set // Raytrace if the last zoom position isn't set
if (m_lastWheelZoomPosX == -1 || m_lastWheelZoomPosY == -1) if (m_lastWheelZoomPosX == -1 || m_lastWheelZoomPosY == -1)
{ {
return true; return true;
} }
int diffX = zoomX - m_lastWheelZoomPosX; int diffX = winPosX - m_lastWheelZoomPosX;
int diffY = zoomY - m_lastWheelZoomPosY; int diffY = winPosY - m_lastWheelZoomPosY;
const int pixelThreshold = 5; const int pixelThreshold = 5;
if (diffX * diffX + diffY * diffY > pixelThreshold * pixelThreshold) if (diffX * diffX + diffY * diffY > pixelThreshold * pixelThreshold)

View File

@ -107,7 +107,8 @@ protected:
void setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ) override; void setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection ) override;
cvf::Vec3d pointOfInterest() override; cvf::Vec3d pointOfInterest() override;
void setPointOfInterest(cvf::Vec3d poi) override; void setPointOfInterest(cvf::Vec3d poi) override;
void updatePointOfInterestDuringZoomIfNecessary(int zoomX, int zoomY); void pickAndSetPointOfInterest(int winPosX, int winPosY);
void updatePointOfInterestDuringZoomIfNecessary(int winPosX, int winPosY);
void forcePointOfInterestUpdateDuringNextWheelZoom(); void forcePointOfInterestUpdateDuringNextWheelZoom();
// Track ball navigation specific // Track ball navigation specific
@ -134,8 +135,8 @@ protected:
bool isRotationEnabled() { return m_isRotationEnabled; } bool isRotationEnabled() { return m_isRotationEnabled; }
private: private:
void updateWheelZoomPosition(int zoomX, int zoomY); void updateWheelZoomPosition(int winPosX, int winPosY);
bool shouldRaytraceForNewPoiDuringWheelZoom(int zoomX, int zoomY) const; bool shouldRaytraceForNewPoiDuringWheelZoom(int winPosX, int winPosY) const;
private: private:
bool m_consumeEvents; bool m_consumeEvents;