Hey,
In my editor you can select multiple objects by dragging a screen space rectangle around several objects using the mouse, aka rubber band selection. The editor view is 3D and uses a perspective camera, basically the game running in a special editor mode. I would want the selection to select the 3D scene objects that appear inside the rectangle, nothing more.
My current approach is to transform the corner points of the selection rectangle from screen space to NDC space and do the same for the corners of every world-space bounding box of every potentially hit object. This allows me to do a simple 2D rectangle-to-rectangle collision test to see which objects are inside the selection rectangle. This works, but depending on the shape of the objects, their world transform as well as the camera transform I get a lot of false positives.
Any idea how to do this more efficiently? I was thinking the following might work:
For each potentially hit object (basically all visible geometry):
- Iterate over all vertices of the object and transform them to NDC space
- Create a 2D convex hull out of the vertices
- Perform a rectangle-to-convex hull collision test to see if the object touches or resides in the selection rectangle.
However, the above seems very complex for such a simple feature, not to mention slow, as the calculations would have to be done every time the mouse moves. I guess the convex hulls could be cached until the camera moves, but that only complicates the system further.
I can already perform ray-to-mesh intersection tests perfectly, the problem comes when I want to perform tests with something "fatter" than just a ray...
So, how would you do this?