Gui: [skip ci] implement new RotationCenterMode called BoundingBoxCenter

This commit is contained in:
wmayer
2020-11-27 15:12:10 +01:00
parent 056030b1d2
commit c582e8a085
2 changed files with 27 additions and 1 deletions

View File

@@ -1052,6 +1052,31 @@ void NavigationStyle::saveCursorPosition(const SoEvent * const ev)
setRotationCenter(current_planept);
break;
}
case BoundingBoxCenter:
{
const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion();
float ratio = vp.getViewportAspectRatio();
SoCamera* cam = viewer->getSoRenderManager()->getCamera();
if (!cam) break; // no camera
SoGetBoundingBoxAction action(viewer->getSoRenderManager()->getViewportRegion());
action.apply(viewer->getSceneGraph());
SbBox3f boundingBox = action.getBoundingBox();
SbVec3f boundingBoxCenter = boundingBox.getCenter();
setRotationCenter(boundingBoxCenter);
// To drag around the center point of the bbox we have to determine
// its projection on the screen becaue this information is used in
// NavigationStyle::spin() for the panning
SbViewVolume vv = cam->getViewVolume(ratio);
vv.projectToScreen(boundingBoxCenter, boundingBoxCenter);
SbVec2s size = vp.getViewportSizePixels();
short tox = static_cast<short>(boundingBoxCenter[0] * size[0]);
short toy = static_cast<short>(boundingBoxCenter[1] * size[1]);
this->localPos.setValue(tox, toy);
break;
}
default:
break;
}