PDA

View Full Version : How to "click" on 3D objects with mouse



Exaxis
09-24-2011, 02:31 PM
I've reached a subject that I've become thoroughly stuck on. I'm trying to figure out how to implement mouse clicks in my OpenGL program. Specifically, I want to be able to have a simple way where if the use holds a mouse over an object and clicks, then that object is "selected."

So let me see if I at least have my logic correct: It seems like what I really need is a way to convert from "Screen" coordinates to the 3D "World" coordinates. If I could do that, then I could manually check to see if any objects were selected. Does this sound about right?

mobeen
09-24-2011, 07:44 PM
Hi,
You can use
1) color picking (http://www.lighthouse3d.com/opengl/picking/index.php3?color1) or
2) selection buffer (http://www.lighthouse3d.com/opengl/picking/index.php?openglway2) or
3) you can cast a ray into the scene and manually test ur world geometry for intersection with the ray ( OpenGL FAQ (http://www.opengl.org/resources/faq/technical/selection.htm#sele0010) ).

I have shared latter of the 2 ways here (http://www.spacesimulator.net/wiki/index.php/3d_Engine_Projects) scroll down to the bottom.

See if this helps.

Exaxis
09-24-2011, 09:15 PM
Hi,
You can use
1) color picking (http://www.lighthouse3d.com/opengl/picking/index.php3?color1) or
2) selection buffer (http://www.lighthouse3d.com/opengl/picking/index.php?openglway2) or
3) you can cast a ray into the scene and manually test ur world geometry for intersection with the ray ( OpenGL FAQ (http://www.opengl.org/resources/faq/technical/selection.htm#sele0010) ).

I have shared latter of the 2 ways here (http://www.spacesimulator.net/wiki/index.php/3d_Engine_Projects) scroll down to the bottom.

See if this helps.

Thanks a lot! Those posts are VERY informative and show me that things don't work the way I thought they did!

I'm going to study them more thoroughly and decide which method I want to use. Thanks again! :)

ugluk
09-25-2011, 04:07 AM
There are also other ways: say you transform object AABBs into screen space, then you don't need to do the ray casting and can do the selection the old way (say you also sort the AABBs by their distance and pick the closest matching one). Anyway, if you have an idea of your own, don't dismiss it, because you hear something else in these forums, try it and learn.