![]() |
|
2D sprite to bounding box hit test - 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: 2D sprite to bounding box hit test (/showthread.php?tid=4446) |
2D sprite to bounding box hit test - BiMMate - 04-17-2024 Is there a way to get elements inside a 2D rectangle? I mean, probably I can draw an overly sprite for the rectangle following user's pointer, but after having screen U,V coordinates I'll need a hit test on elements that I don't know how to solve. Maybe getting a camera direction ray and move it along the edges, but that would not retrieve elements inside the rectangle. Maybe a bounding box created from perpendicular plane to camera and long enough could do the job, but I am totally lost Any tip about this? RE: 2D sprite to bounding box hit test - abenedik - 04-23-2024 I have just added a new sample that shows how to render scene to ID bitmap where each object is rendered with its own color that represents the ID of the object (https://github.com/ab4d/Ab4d.SharpEngine.Samples/blob/main/Ab4d.SharpEngine.Samples.Common/HitTesting/HitTestingWithIdBitmapSample.cs). This sample shows how to get the hit object by checking the colors at the specified mouse coordinates. Get the latest version of the samples to get the new "Hit-testing with ID bitmap". This sample can be easily extended to get objects in a rectangle by checking the colors in the rectangular area instead of checking the color of a single pixel. |