From 7773ad03c1d08c7fa7f39f026676e7c2eb4ef911 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 16 Jan 2016 00:06:37 +0100 Subject: [PATCH] + fix bug in animated fit for orthographic camera if view width < height --- src/Gui/View3DInventorViewer.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index d0aa02dc0..1aadf8f76 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1898,10 +1898,15 @@ void View3DInventorViewer::animatedViewAll(int steps, int ms) SbVec3f campos = cam->position.getValue(); SbRotation camrot = cam->orientation.getValue(); - SoGetBoundingBoxAction action(this->getSoRenderManager()->getViewportRegion()); + SbViewportRegion vp = this->getSoRenderManager()->getViewportRegion(); + SoGetBoundingBoxAction action(vp); action.apply(this->getSoRenderManager()->getSceneGraph()); SbBox3f box = action.getBoundingBox(); +#if (COIN_MAJOR_VERSION >= 3) + float aspectRatio = vp.getViewportAspectRatio(); +#endif + if (box.isEmpty()) return; @@ -1918,6 +1923,11 @@ void View3DInventorViewer::animatedViewAll(int steps, int ms) if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) { isOrthographic = true; height = static_cast(cam)->height.getValue(); +#if (COIN_MAJOR_VERSION >= 3) + if (aspectRatio < 1.0f) + diff = sphere.getRadius() * 2 - height * aspectRatio; + else +#endif diff = sphere.getRadius() * 2 - height; pos = (box.getCenter() - direction * sphere.getRadius()); } @@ -1936,7 +1946,8 @@ void View3DInventorViewer::animatedViewAll(int steps, int ms) float s = float(i)/float(steps); if (isOrthographic) { - static_cast(cam)->height.setValue(height + diff * s); + float camHeight = height + diff * s; + static_cast(cam)->height.setValue(camHeight); } SbVec3f curpos = campos * (1.0f-s) + pos * s;