Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ortographic camera zoom to BoundingBox
#1
Video 
Hi
I have this method to zoom to a BoundingBox:
Code:
    private void Zoom(bool isZoomSelection, BoundingBox? bBox = null)
    {
        if (this.BimScene is null)
        {
            return;
        }

        Threads.ExecuteOnUIThread(() =>
        {
            // BoundingBox can be NaN when there are no models -> Get RootNode BoundingBox instead with the grid
            bBox ??= !isZoomSelection
                ? this.BimScene.GetSceneBoundingBox()
                : this.BimScene.GetSelectionBoundingBox();
            if (bBox.Value.SizeX is float.NaN
                || bBox.Value.SizeY is float.NaN
                || bBox.Value.SizeZ is float.NaN)
            {
                bBox = this.BimScene.RootNode.GetLocalBoundingBox();
            }

            if (Settings.SingleInstance.CameraAnimationDuration > 0)
            {
                var corn = bBox.Value.GetCorners();
                var dist = this.targetPositionCamera.GetFitIntoViewDistanceOrViewWidth(corn, FitIntoViewType.CheckBounds, true, out var targ);
        
                var cameraAnimation = AnimationBuilder.CreateCameraAnimation(this.targetPositionCamera);
                cameraAnimation.EasingFunction = EasingFunctions.QuadraticEaseInOutFunction;
                cameraAnimation.Set(CameraAnimatedProperties.TargetPosition, targ, Settings.SingleInstance.CameraAnimationDuration);
                cameraAnimation.Set(CameraAnimatedProperties.Distance, dist, Settings.SingleInstance.CameraAnimationDuration);

                if (this.currentCameraAnimation is not null)
                {
                    this.currentCameraAnimation.Completed -= this.CameraAnimation_Completed;
                    this.currentCameraAnimation.Stop();
                }

                cameraAnimation.Start();
                this.currentCameraAnimation = cameraAnimation;
                
                this.currentCameraAnimation.Completed += this.CameraAnimation_Completed;
            }
            else
            {
                this.targetPositionCamera.TargetPosition = bBox.Value.GetCenterPosition();
                this.targetPositionCamera.FitIntoView(bBox.Value, false, 1.1f);
            
                this.UpdateCameraPosition();
            }
        }, true);
    }

It works pretty well when in perspective projection, but it does not work for ortographic
I know I must set ViewWidth and AspectRatio to handle that, so, could you please point me in the right direction to calculate the ViewWidth?
  


Messages In This Thread
Ortographic camera zoom to BoundingBox - by BiMMate - 10-29-2025, 10:24 AM

Forum Jump:


Users browsing this thread:
1 Guest(s)