diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index efff055f33..e22c9b94c5 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -1296,6 +1296,14 @@ SbVec3f View3DInventorViewer::getUpDirection() const return upvec; } +SbRotation View3DInventorViewer::getCameraOrientation() const +{ + SoCamera* cam = this->getCamera(); + if (!cam) + return SbRotation(0,0,0,1); // this is the default + return cam->orientation.getValue(); +} + SbVec3f View3DInventorViewer::getPointOnScreen(const SbVec2s& pnt) const { const SbViewportRegion& vp = this->getViewportRegion(); diff --git a/src/Gui/View3DInventorViewer.h b/src/Gui/View3DInventorViewer.h index 73895062cb..80916e39a8 100644 --- a/src/Gui/View3DInventorViewer.h +++ b/src/Gui/View3DInventorViewer.h @@ -230,6 +230,8 @@ public: SbVec3f getViewDirection() const; /** Returns the up direction */ SbVec3f getUpDirection() const; + /** Returns the orientation of the camera. */ + SbRotation getCameraOrientation() const; /** Returns the 3d point on the focal plane to the given 2d point. */ SbVec3f getPointOnScreen(const SbVec2s&) const; /** Returns the near plane represented by its normal and base point. */ diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index ec29f72978..37fc027e6f 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -52,6 +52,8 @@ #include #include #include +#include +#include #include #include @@ -102,6 +104,7 @@ void View3DInventorPy::init_type() add_varargs_method("getViewDirection",&View3DInventorPy::getViewDirection,"getViewDirection()"); add_varargs_method("setCamera",&View3DInventorPy::setCamera,"setCamera()"); add_varargs_method("setCameraOrientation",&View3DInventorPy::setCameraOrientation,"setCameraOrientation()"); + add_varargs_method("getCameraOrientation",&View3DInventorPy::getCameraOrientation,"getCameraOrientation()"); add_varargs_method("getCameraType",&View3DInventorPy::getCameraType,"getCameraType()"); add_varargs_method("setCameraType",&View3DInventorPy::setCameraType,"setCameraType()"); add_varargs_method("listCameraTypes",&View3DInventorPy::listCameraTypes,"listCameraTypes()"); @@ -530,16 +533,30 @@ Py::Object View3DInventorPy::setCameraOrientation(const Py::Tuple& args) { PyObject* o; PyObject* m=Py_False; - if (!PyArg_ParseTuple(args.ptr(), "O!|O!", &PyTuple_Type, &o, &PyBool_Type, &m)) + if (!PyArg_ParseTuple(args.ptr(), "O|O!", &o, &PyBool_Type, &m)) throw Py::Exception(); try { - Py::Tuple tuple(o); - float q0 = (float)Py::Float(tuple[0]); - 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), PyObject_IsTrue(m)); + if (PyTuple_Check(o)) { + Py::Tuple tuple(o); + float q0 = (float)Py::Float(tuple[0]); + 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), PyObject_IsTrue(m)); + } + else if (PyObject_TypeCheck(o, &Base::RotationPy::Type)) { + Base::Rotation r = (Base::Rotation)Py::Rotation(o,false); + double q0, q1, q2, q3; + r.getValue(q0, q1, q2, q3); + _view->getViewer()->setCameraOrientation(SbRotation((float)q0, (float)q1, (float)q2, (float)q3), PyObject_IsTrue(m)); + } + else { + throw Py::ValueError("Neither tuple nor rotation object"); + } + } + catch (const Py::Exception&) { + throw; // re-throw } catch (const Base::Exception& e) { throw Py::Exception(e.what()); @@ -554,6 +571,16 @@ Py::Object View3DInventorPy::setCameraOrientation(const Py::Tuple& args) return Py::None(); } +Py::Object View3DInventorPy::getCameraOrientation(const Py::Tuple& args) +{ + if (!PyArg_ParseTuple(args.ptr(), "")) + throw Py::Exception(); + SbRotation rot = _view->getViewer()->getCameraOrientation(); + float q0,q1,q2,q3; + rot.getValue(q0,q1,q2,q3); + return Py::Rotation(Base::Rotation(q0,q1,q2,q3)); +} + Py::Object View3DInventorPy::viewPosition(const Py::Tuple& args) { PyObject* p=0; diff --git a/src/Gui/View3DPy.h b/src/Gui/View3DPy.h index 657bee956c..c5a9caabdf 100644 --- a/src/Gui/View3DPy.h +++ b/src/Gui/View3DPy.h @@ -75,6 +75,7 @@ public: Py::Object getViewDirection(const Py::Tuple&); Py::Object setCamera(const Py::Tuple&); Py::Object setCameraOrientation(const Py::Tuple&); + Py::Object getCameraOrientation(const Py::Tuple&); Py::Object getCameraType(const Py::Tuple&); Py::Object setCameraType(const Py::Tuple&); Py::Object getCameraNode(const Py::Tuple&);