Having lost a couple of hours searching for a working sample of ray picking with an implementation of the gluUnProject function for iPhone OpenGL ES, and several hours making it work, we’ve decided to give it out to the community.

The interesting part of the project can be found in the glu.h / glu.c files and EAGLView.m.

The implementation of the Ray Picking algorithm can be found in the function called: checkCollision().

Here is a little sketch (that works better than a thousand words):

The project can be downloaded here: Ray Picking Project.

4 Responses to “iPhone gluUnProject”

  1. Hello there, I been looking for a sample like this for ages, dont suppose you could help me. ?

  2. hi ,
this sample code was very helpful to understand ray picking. Thanks.
i got a question regarding multiple objects drawn using push/ pop stack.something similar to this.



    for (i=0 to 20) objects



    each object is a unit cube (textured to sphere) with its own transformation.

In such a case how does ray picking work. How should i keep track of center point of the object to calculate ray intersection. i really appreciate any help.




  3. Did you have any issues with glUnproject() ? I found that if you have a translated object (at least in the Z direction), gluUnproject() returns near and far coordinats that don't actually translate to the given point, so my code it fails. My understanding of the linear algebra of opengl is too weak to understand what's going on in the reverse projection.

Leave a Reply

You must be logged in to post a comment.