From bea2c3b7a7042ad7027f6c2ac42efb5cccc53fb4 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 9 Jul 2012 13:38:21 +0200 Subject: [PATCH] Add optional argument moveToCenter (by default false) to avoid to move camera when using standard views --- src/Gui/NavigationStyle.cpp | 24 +++++++++++++----------- src/Gui/NavigationStyle.h | 2 +- src/Gui/View3DInventorViewer.cpp | 4 ++-- src/Gui/View3DInventorViewer.h | 2 +- src/Gui/View3DPy.cpp | 5 +++-- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index c533e8e76..85cada0b8 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -376,7 +376,7 @@ void NavigationStyle::lookAtPoint(const SbVec3f& pos) } } -void NavigationStyle::setCameraOrientation(const SbRotation& rot) +void NavigationStyle::setCameraOrientation(const SbRotation& rot, SbBool moveToCenter) { SoCamera* cam = viewer->getCamera(); if (cam == 0) return; @@ -387,16 +387,18 @@ void NavigationStyle::setCameraOrientation(const SbRotation& rot) PRIVATE(this)->focal1 = cam->position.getValue() + cam->focalDistance.getValue() * direction; PRIVATE(this)->focal2 = PRIVATE(this)->focal1; - SoGetBoundingBoxAction action(viewer->getViewportRegion()); - action.apply(viewer->getSceneGraph()); - SbBox3f box = action.getBoundingBox(); - if (!box.isEmpty()) { - rot.multVec(SbVec3f(0, 0, -1), direction); - //float s = (this->focal1 - box.getCenter()).dot(direction); - //this->focal2 = box.getCenter() + s * direction; - // setting the center of the overall bounding box as the future focal point - // seems to be a satisfactory solution - PRIVATE(this)->focal2 = box.getCenter(); + if (moveToCenter) { + SoGetBoundingBoxAction action(viewer->getViewportRegion()); + action.apply(viewer->getSceneGraph()); + SbBox3f box = action.getBoundingBox(); + if (!box.isEmpty()) { + rot.multVec(SbVec3f(0, 0, -1), direction); + //float s = (this->focal1 - box.getCenter()).dot(direction); + //this->focal2 = box.getCenter() + s * direction; + // setting the center of the overall bounding box as the future focal point + // seems to be a satisfactory solution + PRIVATE(this)->focal2 = box.getCenter(); + } } // avoid to interfere with spinning (fixes #3101462) diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index be0200dcb..2e4900173 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -127,7 +127,7 @@ public: void updateAnimation(); void redraw(); - void setCameraOrientation(const SbRotation& rot); + void setCameraOrientation(const SbRotation& rot, SbBool moveTocenter=false); void lookAtPoint(const SbVec3f&); void boxZoom(const SbBox2s& box); virtual void viewAll(); diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 93d06c691..7c61cfc01 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1309,9 +1309,9 @@ void View3DInventorViewer::pubSeekToPoint(const SbVec3f& pos) this->seekToPoint(pos); } -void View3DInventorViewer::setCameraOrientation(const SbRotation& rot) +void View3DInventorViewer::setCameraOrientation(const SbRotation& rot, SbBool moveTocenter) { - navigation->setCameraOrientation(rot); + navigation->setCameraOrientation(rot, moveTocenter); } void View3DInventorViewer::setCameraType(SoType t) diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 71e5a2bf3..a7b1593c1 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -231,7 +231,7 @@ public: * \a TRUE the reorientation is animated, otherwise its directly * set. */ - void setCameraOrientation(const SbRotation& rot); + void setCameraOrientation(const SbRotation& rot, SbBool moveTocenter=false); void setCameraType(SoType t); void moveCameraTo(const SbRotation& rot, const SbVec3f& pos, int steps, int ms); /** diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index 14ab2e623..0d0572c99 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -464,7 +464,8 @@ Py::Object View3DInventorPy::viewRotateRight(const Py::Tuple& args) Py::Object View3DInventorPy::setCameraOrientation(const Py::Tuple& args) { PyObject* o; - if (!PyArg_ParseTuple(args.ptr(), "O!", &PyTuple_Type, &o)) + PyObject* m; + if (!PyArg_ParseTuple(args.ptr(), "O!|O!", &PyTuple_Type, &o, &PyBool_Type, &m)) throw Py::Exception(); try { @@ -473,7 +474,7 @@ Py::Object View3DInventorPy::setCameraOrientation(const Py::Tuple& args) float q1 = (float)Py::Float(tuple[1]); float q2 = (float)Py::Float(tuple[2]); float q3 = (float)Py::Float(tuple[3]); - _view->getViewer()->setCameraOrientation(SbRotation(q0, q1, q2, q3)); + _view->getViewer()->setCameraOrientation(SbRotation(q0, q1, q2, q3), m==Py_True); } catch (const Base::Exception& e) { throw Py::Exception(e.what());