How to "click" on 3D objects with mouse

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?

Hi,
You can use

  1. color picking or
  2. selection buffer or
  3. you can cast a ray into the scene and manually test ur world geometry for intersection with the ray ( OpenGL FAQ ).

I have shared latter of the 2 ways here 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! :slight_smile:

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.