03-02-2021, 12:14 PM
(This post was last modified: 03-11-2021, 06:10 PM by Somanna.)
Is it possible to select an area in the view port using the mouse (i.e. by clicking and holding the mouse left button and draging the mouse) and then zoom the selected area to fit into view? If yes how?
See the "Rectangular selection" sample in the "Ab3d.DXEngine hit testing" section of the Ab3d.DXEngine samples. The sample shows two possible ways to do the rectangular object selection.
After you have the list of selected objects, you can call the camera.FitIntoView method - choose the method that takes IList<Visual3D> visuals as an argument - pass the selected objects.
I would advice you to check the Ab3d.PowerToys samples and Ab3d.DXEngine samples.
Your plan is to create a list of Visual3D objects that you will pass to the FitIntoView method.
If you want a rectangular selection, then you can use the 2 techniques described in the Rectangular selection sample.
If you want to support free form selection, then it would be probably best to render the scene to object id bitmap where the colors in the bitmap define the ids of the objects. Then with some 2D technique, you check the pixel colors (ids) in the selected area. Apart from a general advice to search the internet on how to do that, I cannot help you more.
What you are trying to achieve is viable in 2D or with orthographic camera, since you actually make a selection and then fit it onto the screen because orthographic camera is based on a rectangular bounding box. In 3D, when you draw a rectangle, it's not actually a rectangle but a frustum since each corner of the rectangle is projected onto a line. You have two ways to solve this:
1) You set a constant distance to get a rectangle out of the frustum. Then what you are trying to do reduces to fitting selection into view. The distance can be also acquired if you are working on top of a large object and the rectangle is on top of the object - you get the plane to fit into view based on the corners.
2) You can use perspective model of a camera used in computer vision. You do the focus there based on focus distance and field of view. For example, you would start with camera at origin, with fovy 45°. Then when you try to zoom using the rectangle you compute the aspect and update the fovy to the fraction of 45. The focus in this case would not update the position. The position would be updated only when you move the camera (rotation, drag move).