![]() |
|
Ortographic camera zoom to BoundingBox - Printable Version +- AB4D Forum (https://forum.ab4d.com) +-- Forum: Products Forums (https://forum.ab4d.com/forumdisplay.php?fid=4) +--- Forum: Ab4d.SharpEngine (https://forum.ab4d.com/forumdisplay.php?fid=12) +--- Thread: Ortographic camera zoom to BoundingBox (/showthread.php?tid=4499) |
Ortographic camera zoom to BoundingBox - BiMMate - 10-29-2025 Hi I have this method to zoom to a BoundingBox: Code: private void Zoom(bool isZoomSelection, BoundingBox? bBox = null)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? RE: Ortographic camera zoom to BoundingBox - abenedik - 10-30-2025 As you said, when using the Orthographics camera, you need to change the ViewWidth. But in your code, when you set up the animation, you always animate the Distance. You should also use the following code instead: Code: var distanceProperty = _targetPositionCamera.ProjectionType == ProjectionTypes.OrthographicI also see that when you use animation (Settings.SingleInstance.CameraAnimationDuration > 0), then you also animate the TargetPosition to the new position that is calculated from the GetFitIntoViewDistanceOrViewWidth method. But when you do not use animation, you set TargetPosition to the center position of the bounding box. This can create different results. I would advise you to restructure the code so you would always use the results of the GetFitIntoViewDistanceOrViewWidth method and then create the animation if CameraAnimationDuration > 0 or just set the TargetPosition and Distance / ViewWidth in case of no animation. Also, if you post the code here, please clean it before posting. For example, the code here has Threads.ExecuteOnUIThread that is irrelevant for this sample. Also it uses some methods that may be also relevant for how the code behaves, but the source is not provided and just clutters the code, for example: BimScene.GetSceneBoundingBox, BimScene.GetSelectionBoundingBox(), this.UpdateCameraPosition(). It is also not clear what happens in this.CameraAnimation_Completed. When I tried to reproduce the issue, I copied your code to my project, and then I needed to clean the code so it could start. It would be much nicer if you could do that already and post only the code that is relevant to the problem. This would also make the posted code much cleaner for other visitors. Anyway, after I had cleaned the code and added the code that animates ViewWidth in case of the Orthographic camera, the animation worked. Here is the cleaned code that I used (added to SharpEngineSceneViewInXaml.xaml.cs sample): Code: private CameraAnimation? _cameraAnimation;Node: I admit that FitIntoView is not perfect—I have spent a lot of time trying to achieve an optimal fit, but I was not successful. RE: Ortographic camera zoom to BoundingBox - BiMMate - 10-30-2025 Thanks for your quick response You are totally right, I should have clean my code before submitting. I probably didn't pay too much attention thinking that it was self-explanatory I changed the code and it works perfect now I also implemented your suggestion to use same logic in both scenario (with or without camera animations) Thank you very much for your Help Andrej |