Click or drag to resize
Ab4d.SharpEngine logo

IFitIntoViewCameraFitIntoView(Vector3, Int32, FuncSingle, Single, Boolean, Single, Boolean) Method

FitIntoView animates the camera's Distance (for PerspectiveCamera) or ViewWidth (for OrthographicCamera) and TargetPosition (if adjustTargetPosition is true) so that all the specified positions will be visible from one edge of the viewport to another edge.

Namespace: Ab4d.SharpEngine.Cameras
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 4.1.9680+a1b1e43de1ad9a7e35472c33948d688d7b40ef79
Syntax
C#
bool FitIntoView(
	Vector3[] positions,
	int animationDurationInMilliseconds,
	Func<float, float>? easingFunction = null,
	bool adjustTargetPosition = true,
	float adjustmentFactor = 1f,
	bool waitUntilCameraIsValid = true
)

Parameters

positions  Vector3
Array of Vector3 that defines the positions that will be used to fit into view
animationDurationInMilliseconds  Int32
duration of animation in milliseconds
easingFunction  FuncSingle, Single  (Optional)
easing function (see Ab4d.SharpEngine.Common.EasingFunctions for different easing functions). When null linear interpolation is used.
adjustTargetPosition  Boolean  (Optional)
true if the TargetPosition is adjusted; false if TargetPosition is preserved (default value is true)
adjustmentFactor  Single  (Optional)
factor that is multiplied by the calculated Distance or ViewWidth. Can be used to add margin to the bounds - for example value 1.1 would add 10% margin. Default value is 1.0 (no margin).
waitUntilCameraIsValid  Boolean  (Optional)
when true (by default) and if the camera is not valid (for example because the SceneView size is not defined yet), then the FitIntoView will be called when the camera becomes valid. When false, then FitIntoView is called only if camera is currently valid. See return value for info if camera was changed.

Return Value

Boolean
true if camera was changed; false when camera is not valid (see waitUntilCameraIsValid parameter for more info)
Remarks

FitIntoView adjusts the camera's Distance (for PerspectiveCamera) or ViewWidth (for OrthographicCamera) and TargetPosition (if adjustTargetPosition is true) so that all the specified positions will be visible from one edge of the viewport 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 case 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).

This method animates the camera changes. To immediately change the camera, use the FitIntoView method without animationDurationInMilliseconds and easingFunction parameters, or set animationDurationInMilliseconds to 0.

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.

See Also