#129168 - ikaris - Sun May 20, 2007 12:54 am
This post
http://forum.gbadev.org/viewtopic.php?t=12438
talks about detecting if a sprite is touched with the stylus...
How about 3D objects ?
Bounding spheres ?
Access to some sort of buffer ?
Any suggestions ?
I did a few searches, and didn't find anything... although its possible I'm blind.
#129176 - gabebear - Sun May 20, 2007 1:58 am
The picking example in the libnds examples is probably what you want.
If you don't already know how picking works in OpenGL then you should start there. Try http://www.lighthouse3d.com/opengl/picking/ for a good explanation of how it works.
I know the example isn't that well commented... sorry... It probably should be a tutorial and not just an example.
Man... surfing is tiring.
#129183 - Ant6n - Sun May 20, 2007 4:17 am
AFAIK it comes down to getting a ray from the camera into the world that represents where you clicked on screen, and then doing the collision detection on that.
#129195 - ikaris - Sun May 20, 2007 1:11 pm
Ant6n wrote: |
AFAIK it comes down to getting a ray from the camera into the world that represents where you clicked on screen, and then doing the collision detection on that. |
OK, I figured raycasting would be involved.
However, what does the ray collide with ?
A bounding sphere would be less accurate for complex models, but detecting a hit on a complex polygon model would be heavier.
Which method do you people use ?
#129212 - gabebear - Sun May 20, 2007 6:15 pm
If you are doing picking the easiest thing to do is bound on the actual model. Picking uses the 3D hardware so if you can see it, you can pick it. Generally you use a simplified 3D model for picking; no texturing, simplify complex areas, and such.
You can use bounding spheres/boxes for clicking, but it won't be as accurate unless you are clicking on a sphere or box.
#129213 - silent_code - Sun May 20, 2007 6:32 pm
you can still colorcode stuff and read back the pixel that is touched. that requires rendering the scene in a backbuffer and not displaying it. that might be slower (if screencapturing is required) than the following:
when using a collision detection solution, you use a hirarchy of bounding volumes. and sometimes simplified meshes are used, but we're talking nds here, so meshes wil usually be quite simple.
first shoot the ray into the world to check what parts are involved (and therefore you get the objects to check), then check with which bounding spheres the ray intersects and take the one object closest to the ray's origin. after that you check for collisions with sub volumes (again spheres or aabbs/obb) and finally, if you really have to have it very exact, you check the primitives (quads, tris etc.) inside the bbs.
if you find, that that's not the object selected, check the next object, behind the current one. else, you're done.
a lot of work, that can be very much optimized, but it should get you on track. it may help to use a rather short ray segment, because else it's potentially a lot of testing for lots of small objects in the background.
also, there was a thread about this topic like half a year ago. look for it!
hope it helps.
#129262 - a128 - Mon May 21, 2007 8:13 am
The Picking example in libnds do not work.
#129764 - gabebear - Sat May 26, 2007 6:36 am
a128, make sure you have matching libnds and examples, or just make sure you have the latest cvs versions. The picking example works fine for me and I just downloaded the latest cvs examples and libnds.
I know some other people had problems with that example and I never figured out exactly what the problem was, but reinstalling devkitpro fixed the problem for them.