Help detecting when a 3d element is touched on iPhone

Hi, I’ve got some experience doing 3D programming, but it’s OLD experience, when I did all the math, transformations and projections manually.

Now I’m writing some software for the iPhone, using Open GL ES 2.0… I have learned a lot about managing my objects, rendering, and all that, but now I’m trying to create some interaction.

I know how to detect the touch events, and can determine where a touch starts/stops on the screen, but I’m having a hard time finding a way of determining if a touch is ‘on’ a given object in the scene. I assume there is some function to determine if a touch ‘collides’ with the an element in the space, based on what was rendered there, but I can’t seem to find it.

I guess I could write an algorithm to work it out, but that seems both redundant, and slow.

Please let me know if there is a function for this, and I can probably figure it out from there, although any examples/further instruction would be appreciated.


You’re going to have to write code to do it. Turn your touch point into a ray that casts into the screen and checks for collisions. Search for info on Google about “3D picking.”

Another easier way is to render each object a special color to a texture, then check the color of the pixel you touch and return the object using the ID. Ideally use a binary search when looking up the ID. Search “picking painter’s algorithm.”

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.