Gui: Find bounding sphere before drag or animation
This commit is contained in:
@@ -479,6 +479,13 @@ void NavigationStyle::viewAll()
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationStyle::findBoundingSphere() {
|
||||
// Find a bounding sphere for the scene
|
||||
SoGetBoundingBoxAction action(viewer->getSoRenderManager()->getViewportRegion());
|
||||
action.apply(viewer->getSceneGraph());
|
||||
boundingSphere.circumscribe(action.getBoundingBox());
|
||||
}
|
||||
|
||||
/** Rotate the camera by the given amount, then reposition it so we're still pointing at the same
|
||||
* focal point
|
||||
*/
|
||||
@@ -511,29 +518,23 @@ void NavigationStyle::reorientCamera(SoCamera* camera, const SbRotation& rotatio
|
||||
camera->position = rotationCenter + newRotationCenterDistance;
|
||||
|
||||
// Fix issue with near clipping in orthogonal view
|
||||
if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())) {
|
||||
if (camera->getTypeId().isDerivedFrom(SoOrthographicCamera::getClassTypeId())) {
|
||||
|
||||
// Find a bounding sphere for the scene
|
||||
SoGetBoundingBoxAction action(viewer->getSoRenderManager()->getViewportRegion());
|
||||
action.apply(viewer->getSceneGraph());
|
||||
SbSphere boundingSphere;
|
||||
boundingSphere.circumscribe(action.getBoundingBox());
|
||||
// The center of the bounding sphere in camera coordinate system
|
||||
SbVec3f center;
|
||||
camera->orientation.getValue().inverse().multVec(boundingSphere.getCenter() - camera->position.getValue(), center);
|
||||
|
||||
// The center of the bounding sphere in camera coordinate system
|
||||
SbVec3f center;
|
||||
camera->orientation.getValue().inverse().multVec(boundingSphere.getCenter() - camera->position.getValue(), center);
|
||||
SbVec3f dir;
|
||||
camera->orientation.getValue().multVec(SbVec3f(0, 0, -1), dir);
|
||||
|
||||
SbVec3f dir;
|
||||
camera->orientation.getValue().multVec(SbVec3f(0, 0, -1), dir);
|
||||
|
||||
// Reposition the camera but keep the focal point the same
|
||||
// nearDistance is 0 and farDistance is the diameter of the bounding sphere
|
||||
float repositionDistance = -center.getValue()[2] - boundingSphere.getRadius();
|
||||
camera->position = camera->position.getValue() + repositionDistance * dir;
|
||||
camera->nearDistance = 0;
|
||||
camera->farDistance = 2 * boundingSphere.getRadius();
|
||||
camera->focalDistance = camera->focalDistance.getValue() - repositionDistance;
|
||||
}
|
||||
// Reposition the camera but keep the focal point the same
|
||||
// nearDistance is 0 and farDistance is the diameter of the bounding sphere
|
||||
float repositionDistance = -center.getValue()[2] - boundingSphere.getRadius();
|
||||
camera->position = camera->position.getValue() + repositionDistance * dir;
|
||||
camera->nearDistance = 0;
|
||||
camera->farDistance = 2 * boundingSphere.getRadius();
|
||||
camera->focalDistance = camera->focalDistance.getValue() - repositionDistance;
|
||||
}
|
||||
}
|
||||
|
||||
void NavigationStyle::panCamera(SoCamera * cam, float aspectratio, const SbPlane & panplane,
|
||||
@@ -1299,6 +1300,7 @@ void NavigationStyle::setViewingMode(const ViewerMode newmode)
|
||||
// Set up initial projection point for the projector object when
|
||||
// first starting a drag operation.
|
||||
animator->stop();
|
||||
findBoundingSphere();
|
||||
viewer->showRotationCenter(true);
|
||||
this->spinprojector->project(this->lastmouseposition);
|
||||
this->interactiveCountInc();
|
||||
|
||||
Reference in New Issue
Block a user