Add optional argument moveToCenter (by default false) to avoid to move camera when using standard views
This commit is contained in:
parent
a9ad8068a8
commit
bea2c3b7a7
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
/**
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue
Block a user