IFit |
bool FitIntoView( BoundingBox boundingBox, bool adjustTargetPosition = true, float adjustmentFactor = 1f, bool waitUntilSceneViewSizeIsValid = true )
FitIntoView adjusts the camera's Distance (for PerspectiveCamera) or ViewWidth (for OrthographicCamera) and TargetPosition (if adjustTargetPosition is true) so that the specified BoundingBox will be visible from one edge of the SceneView to another edge.
When fitIntoViewType is set to the CheckAllPositions, then the method checks each position of the models. This is more precise than CheckBounds but can take much longer when there are objects with a lot of position in the scene. In this cases it is recommended to use the CheckBounds settings.
The adjustmentFactor parameter can be used to set the margin around the scene objects. Its value is multiplied by the calculated Distance or CameraWidth. For example, value 1.1 adds 10% margin around scene objects.
When using OrthographicCamera, the returned CameraWidth and the new TargetPosition will exactly position the object to the bounds of the SceneView. When using PerspectiveCamera there might be some smaller margins (empty space) on one or the other side of the SceneView.
To set fit into view for only part of the scene, you can use the FitIntoView(SceneNode, FitIntoViewType, Boolean, Single, Boolean) overloaded method that also takes a SceneNode as a parameter (SceneNode can be a GroupNode).
To get the calculated Distance or CameraWidth and new TargetPosition without changing the current camera, you can use the GetFitIntoViewDistanceOrViewWidth(SceneNode, FitIntoViewType, Boolean, Vector3) or GetFitIntoViewDistanceOrViewWidth(Vector3, FitIntoViewType, Boolean, Vector3) methods.