Detecting objects near cursor to snap to - any alternatives to picking ray?

169 views Asked by At

In the problem of detecting objects near the mouse cursor to snap to (in a 3d view), we are using the picking ray method (which basically forms a 3d region of the cursor's immediate neighborhood and then detects objects present in the region).

I wonder if it is the only way to solve the task. Can I use, for example, the view matrix to get the 2D coordinates of the object in view space, then search for any objects in the cursor's vicinity?

I am not happy with the picking ray method because it is relatively expensive, so the question is essentially about whether any space transformation-based method will generally be faster. I am new to 3D programming so please give me a direction to dig into.

1

There are 1 answers

2
AudioBubble On BEST ANSWER

You can probably speedup the ray picking process by forming a hierarchy of nested bounding boxes around the objects, and checking for intersection of the rays with the bounding boxes. This way, you can spare a lot of intersection tests.

There is an alternative, exploiting the available rendering engine: instead of rendering to screen with the normal rendering attributes, you can render the same view in an off-screen plane, using flat shading and setting a different color for every object. You will obtain an object map that instantaneously tells you the object id for any pixel.