diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index e3f524d6b5..cbb85043e5 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -1052,6 +1052,31 @@ void NavigationStyle::saveCursorPosition(const SoEvent * const ev) setRotationCenter(current_planept); break; } + case BoundingBoxCenter: + { + const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion(); + float ratio = vp.getViewportAspectRatio(); + + SoCamera* cam = viewer->getSoRenderManager()->getCamera(); + if (!cam) break; // no camera + + SoGetBoundingBoxAction action(viewer->getSoRenderManager()->getViewportRegion()); + action.apply(viewer->getSceneGraph()); + SbBox3f boundingBox = action.getBoundingBox(); + SbVec3f boundingBoxCenter = boundingBox.getCenter(); + setRotationCenter(boundingBoxCenter); + + // To drag around the center point of the bbox we have to determine + // its projection on the screen becaue this information is used in + // NavigationStyle::spin() for the panning + SbViewVolume vv = cam->getViewVolume(ratio); + vv.projectToScreen(boundingBoxCenter, boundingBoxCenter); + SbVec2s size = vp.getViewportSizePixels(); + short tox = static_cast(boundingBoxCenter[0] * size[0]); + short toy = static_cast(boundingBoxCenter[1] * size[1]); + this->localPos.setValue(tox, toy); + break; + } default: break; } diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index 0e5b1179d0..28652e7d05 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -101,7 +101,8 @@ public: enum RotationCenterMode { ScenePointAtCursor, /**< Find the point in the scene at the cursor position. If there is no point then the focal plane is used */ - FocalPointAtCursor /**< Find the point on the focal plane at the cursor position. */ + FocalPointAtCursor, /**< Find the point on the focal plane at the cursor position. */ + BoundingBoxCenter /**< Find the center point of the bounding box of the scene. */ }; public: