I am making a WPF program with the ability to graphically modify data in 3D. To give the user the ability to simultaneously select multiple graphical objects, I want to implement a selection rectangle. (Just like in Windows Explorer.) The general functionality of programs like this one is to have two different functions for the selection rectangle and that the user can somehow choose which method to use.
- Any object is selected, partially or completely inside the rectangle.
- Only objects that are inside the rectangle are selected.
The second method is performed using the bounding box of each object and checks if it is inside the rectangle. On the other hand, on the one hand, this seems to be a pretty definite job. All my graphic objects are complex three-dimensional numbers and can be rotated by the user in any way. At the moment, I canโt find any other way besides checking if any of the triangles in the grid intersects any of the objects of the 2D rectangle, and this can be quite time-consuming.
I have little experience with WPF 3D, but I have done this before in OpenGL. Then I could tell OpenGL to draw a specific area of โโthe screen, and compile a list of objects that were visible in a specific area. All I need to get the functionality that I wanted is about 5 lines of code.
I think my question is this:
- Is there a way to do this using WPF 3D, similar to the OpenGL approach?
- If not, is there another smart way to find all objects (Visual3D) in the viewport, which is partially behind the 2D rectangle?
I refuse to believe that I am the only one who has such a problem, so I hope that a smart mind can point me in the right direction.
Regards, Sverre
Thanks for your reply!
The 2D rectangle is directly in front of the camera and extends infinitely forward. I want to get any object that is partially or completely inside this truncation.
The camera used is a spelling or perspective projection camera ( System.Windows.Media.Media3D.ProjectionCamera ). The reason we don't use the matrix camera is because we use a third-party tool that does not support the matrix camera. But I'm sure there is a way to get the matrix from the projection camera, so hopefully this is not a problem.
Theoretically, your decision seems to be what we need, but I'm not sure how to proceed. Do you have links to sample code, or can you give some tips on how to implement this?
Btw: Since we are working with WPF, we do not have direct access to DirectX. At least this is what we have concluded after some research. You mentioned the use of the z-buffer, with which we were not able to access through WPF. If you know how to access the z-buffer, they really appreciate it! This is a topic, but we struggled to disable the z-buffer for some time, but refused ...
Regards, Sverre