Skip to content

Commit

Permalink
+ fixes #1497: Implement getCameraOrientation similarly to getViewDir…
Browse files Browse the repository at this point in the history
…ection
  • Loading branch information
wwmayer committed Apr 2, 2014
1 parent 8c91a78 commit 25d0242
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/Gui/View3DInventorViewer.cpp
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/View3DInventorViewer.h
Expand Up @@ -230,6 +230,8 @@ class GuiExport View3DInventorViewer : public SoQtViewer, public Gui::SelectionS
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. */
Expand Down
41 changes: 34 additions & 7 deletions src/Gui/View3DPy.cpp
Expand Up @@ -52,6 +52,8 @@
#include <Base/Exception.h>
#include <Base/Interpreter.h>
#include <Base/PlacementPy.h>
#include <Base/Rotation.h>
#include <Base/RotationPy.h>
#include <Base/VectorPy.h>
#include <Base/GeometryPyCXX.h>

Expand Down Expand Up @@ -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()");
Expand Down Expand Up @@ -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());
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/Gui/View3DPy.h
Expand Up @@ -75,6 +75,7 @@ class View3DInventorPy : public Py::PythonExtension<View3DInventorPy>
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&);
Expand Down

0 comments on commit 25d0242

Please sign in to comment.