From ff516f0a2b579d28059d23b92c4a04657af41355 Mon Sep 17 00:00:00 2001 From: Bas Ruigrok Date: Thu, 5 Jun 2025 18:35:30 +0200 Subject: [PATCH] Gui: Improve orthographic camera rotation stability --- src/Gui/Navigation/NavigationStyle.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Gui/Navigation/NavigationStyle.cpp b/src/Gui/Navigation/NavigationStyle.cpp index ca3d7c3887..7137011838 100644 --- a/src/Gui/Navigation/NavigationStyle.cpp +++ b/src/Gui/Navigation/NavigationStyle.cpp @@ -700,6 +700,19 @@ void NavigationStyle::reorientCamera(SoCamera* camera, const SbRotation& rotatio // Reposition camera so the rotation center stays in the same place camera->position = rotationCenter + newRotationCenterDistance; + if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())) { + // Adjust the camera position to keep the focal point in the same place while making sure + // the focal distance stays small. This increases rotation stability for small and large + // scenes + + SbVec3f direction; + camera->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction); + + constexpr float orthographicFocalDistance = 1; + camera->position = getFocalPoint() - orthographicFocalDistance * direction; + camera->focalDistance = orthographicFocalDistance; + } + #if (COIN_MAJOR_VERSION * 100 + COIN_MINOR_VERSION * 10 + COIN_MICRO_VERSION < 403) // Fix issue with near clipping in orthogonal view if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())) {