Gui: [skip ci] implement new RotationCenterMode called BoundingBoxCenter
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user