gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > "glPick" :picking, selecting in 3D

#72389 - ishraam - Sat Feb 18, 2006 5:10 am

I think the DS has no "hardware" method to select an object in 3D, like OpenGL has (I mean when you try so "click" on a 3D object rendered on the touchscreen). Am I wrong?

If not, is there a "best" way to do it ?
I have thought about rendering one more pass with only colored untextured & unlit objects, each color acting as an ID. Then it would simply be a matter of coord matching.
The "select color pass" would not need to be used/drawn each time, only 1/5 frames for example (not to use dynamic management).
The objects could also have a special version, just like with LOD, with fewer faces to be drawn.

I think that would fit the purpose.

Any comment or other idea ?

#72396 - gladius - Sat Feb 18, 2006 8:05 am

That's one possibility. I think the more common method is to do the ray casting (cast a ray from the viewer through the scene with the direction determined by the mouse position) yourself. It's not too hard to code a ray/triangle and ray/sphere intersection routine, and there are a bunch on the web as well.

For speed you first do ray/sphere intersection with the different objects in the scene, then only if the sphere is hit do you go down to the triangle level if you need accuracy.

You can also do some spatial subdivision such as octtrees or kd-trees for speed.

#72440 - tepples - Sat Feb 18, 2006 4:47 pm

If your game has sufficiently general collision detection code, you could reuse that.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#72482 - dovoto - Sat Feb 18, 2006 10:13 pm

The DS has a register which tracks which vertices made it past the culling stage and are actualy going to be rendered. This could easily be used to implement the picking routine presented in gl (just check for a change in vertex count after each object is rendered and you will get a hit/miss, make your view small enough and centered on the possition of interest and you will get a nice 3D selection).

The challenge comes from freezing the current frame and rendering the picking frame somewhere it wont be seen. I am not certain of how one might do this other than through video capture techniques. This would be very useful to some people so investigating it would be worth the time in my opinion.
_________________
www.drunkencoders.com

#72500 - ishraam - Sun Feb 19, 2006 4:01 am

gladius : Yup I know about ray casting. But don't like it when I need to implement it all in software.

dovoto : That's the "other idea" I was waiting for ^_^.