From 8e7b0b90bfc66babd1156a4f8f7c1c4ec8354e6c Mon Sep 17 00:00:00 2001 From: Bas Ruigrok Date: Sat, 16 Aug 2025 11:22:47 +0200 Subject: [PATCH] Gui: Perspective camera set focal distance to rotation center depth to fix zooming at new rotation center --- src/Gui/Navigation/NavigationStyle.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Gui/Navigation/NavigationStyle.cpp b/src/Gui/Navigation/NavigationStyle.cpp index 12b76c95f9..ba02def974 100644 --- a/src/Gui/Navigation/NavigationStyle.cpp +++ b/src/Gui/Navigation/NavigationStyle.cpp @@ -1026,6 +1026,20 @@ void NavigationStyle::setRotationCenter(const SbVec3f& cnt) { this->rotationCenter = cnt; this->rotationCenterFound = true; + + const auto camera = getCamera(); + if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) { + SbVec3f direction; + camera->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); + + // Calculate distance from camera to rotation center + const auto rotationCenterDistance = rotationCenter - camera->position.getValue(); + const auto rotationCenterDepth = rotationCenterDistance.dot(direction); + + // Set focal distance to match rotation center depth so we can zoom at the new rotation + // center with a perspective camera + camera->focalDistance.setValue(rotationCenterDepth); + } } SbVec3f NavigationStyle::getFocalPoint() const