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;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,8 @@ public:
|
||||
|
||||
enum RotationCenterMode {
|
||||
ScenePointAtCursor, /**< Find the point in the scene at the cursor position. If there is no point then the focal plane is used */
|
||||
FocalPointAtCursor /**< Find the point on the focal plane at the cursor position. */
|
||||
FocalPointAtCursor, /**< Find the point on the focal plane at the cursor position. */
|
||||
BoundingBoxCenter /**< Find the center point of the bounding box of the scene. */
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user