Gui: Improve lookAtPoint (#13556)

* Gui: Rename NavigationStyle::pan to setupPanningPlane

* Gui: Replace duplicate code with NavigationStyle::setupPanningPlane

* Gui: Use panning plane when hit point not found in lookAtPoint

Also enables navigation animations when pressing MMB while the mouse is not over an object

* Gui: Remove unused methods
This commit is contained in:
Bas Ruigrok
2024-05-06 17:45:14 +02:00
committed by GitHub
parent f3590de466
commit 98320cc839
12 changed files with 67 additions and 109 deletions

View File

@@ -327,27 +327,41 @@ void NavigationStyle::seekToPoint(const SbVec3f& scenepos)
viewer->seekToPoint(scenepos);
}
SbBool NavigationStyle::lookAtPoint(const SbVec2s screenpos)
void NavigationStyle::lookAtPoint(const SbVec2s screenpos)
{
SoCamera* cam = viewer->getSoRenderManager()->getCamera();
if (!cam)
return false;
const SoCamera* camera = viewer->getCamera();
if (!camera) {
return;
}
SoRayPickAction rpaction(viewer->getSoRenderManager()->getViewportRegion());
SoRayPickAction rpaction(viewer->getViewportRegion());
rpaction.setPoint(screenpos);
rpaction.setRadius(viewer->getPickRadius());
rpaction.apply(viewer->getSoRenderManager()->getSceneGraph());
SoPickedPoint * picked = rpaction.getPickedPoint();
if (!picked) {
this->interactiveCountInc();
return false;
const SoPickedPoint* picked = rpaction.getPickedPoint();
// Point is either the hitpoint or the projected point on the panning plane
SbVec3f point;
if (picked) {
point = picked->getPoint();
}
else {
const SbViewportRegion& vp = viewer->getViewportRegion();
const float aspectratio = vp.getViewportAspectRatio();
SbViewVolume vv = camera->getViewVolume(aspectratio);
// See note in Coin docs for SoCamera::getViewVolume re:viewport mapping
if (aspectratio < 1.0) {
vv.scale(1.0 / aspectratio);
}
SbLine line;
vv.projectPointToLine(normalizePixelPos(screenpos), line);
panningplane.intersect(line, point);
}
SbVec3f hitpoint;
hitpoint = picked->getPoint();
lookAtPoint(hitpoint);
return true;
lookAtPoint(point);
}
void NavigationStyle::lookAtPoint(const SbVec3f& position)
@@ -593,35 +607,28 @@ void NavigationStyle::panCamera(SoCamera * cam, float aspectratio, const SbPlane
}
}
void NavigationStyle::pan(SoCamera* camera)
void NavigationStyle::setupPanningPlane(const SoCamera* camera)
{
// The plane we're projecting the mouse coordinates to get 3D
// coordinates should stay the same during the whole pan
// operation, so we should calculate this value here.
if (!camera) { // can happen for empty scenegraph
if (!camera) { // can happen for empty scenegraph
this->panningplane = SbPlane(SbVec3f(0, 0, 1), 0);
}
else {
const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion();
float aspectratio = vp.getViewportAspectRatio();
const SbViewportRegion& vp = viewer->getViewportRegion();
const float aspectratio = vp.getViewportAspectRatio();
SbViewVolume vv = camera->getViewVolume(aspectratio);
// See note in Coin docs for SoCamera::getViewVolume re:viewport mapping
if(aspectratio < 1.0)
if (aspectratio < 1.0) {
vv.scale(1.0 / aspectratio);
}
this->panningplane = vv.getPlane(camera->focalDistance.getValue());
}
}
void NavigationStyle::panToCenter(const SbPlane & pplane, const SbVec2f & currpos)
{
const SbViewportRegion & vp = viewer->getSoRenderManager()->getViewportRegion();
float ratio = vp.getViewportAspectRatio();
panCamera(viewer->getSoRenderManager()->getCamera(), ratio, pplane, SbVec2f(0.5,0.5), currpos);
this->rotationCenterFound = false;
}
/** Dependent on the camera type this will either shrink or expand the
* height of the viewport (orthogonal camera) or move the camera
* closer or further away from the focal point in the scene.
@@ -1382,7 +1389,7 @@ void NavigationStyle::setViewingMode(const ViewerMode newmode)
case PANNING:
animator->stop();
pan(viewer->getSoRenderManager()->getCamera());
setupPanningPlane(viewer->getSoRenderManager()->getCamera());
this->interactiveCountInc();
break;