Gui: Expose the upDirection vector to Python

This commit is contained in:
Pieter Hijma
2023-07-06 15:56:24 +02:00
committed by WandererFan
parent 52e1c7c33b
commit c765d64891
2 changed files with 24 additions and 0 deletions

View File

@@ -127,6 +127,9 @@ void View3DInventorPy::init_type()
add_varargs_method("getViewDirection",&View3DInventorPy::getViewDirection,"getViewDirection() --> tuple of floats\n"
"returns the direction vector the view is currently pointing at as tuple with xyz values\n"
);
add_varargs_method("getUpDirection",&View3DInventorPy::getUpDirection,"getUpDirection() --> tuple of integers\n"
"Returns the up direction vector\n"
);
add_varargs_method("setViewDirection",&View3DInventorPy::setViewDirection,"setViewDirection(tuple) --> None\n"
"Sets the direction the view is pointing at. The direction must be given as tuple with\n"
"three coordinates xyz"
@@ -1042,6 +1045,26 @@ Py::Object View3DInventorPy::getViewDirection(const Py::Tuple& args)
}
}
Py::Object View3DInventorPy::getUpDirection(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
try {
SbVec3f dvec = getView3DIventorPtr()->getViewer()->getUpDirection();
return Py::Vector(Base::Vector3f(dvec[0], dvec[1], dvec[2]));
}
catch (const Base::Exception& e) {
throw Py::RuntimeError(e.what());
}
catch (const std::exception& e) {
throw Py::RuntimeError(e.what());
}
catch (...) {
throw Py::RuntimeError("Unknown C++ exception");
}
}
Py::Object View3DInventorPy::setViewDirection(const Py::Tuple& args)
{
PyObject* object;