Reputation: 21
is it possible to check if ONLY THE opengl object on the iphone screen has been touched? I can only figure it out for the whole screen, but thats not what I want :-(
e.g. a coin game: we have several coins in the opengl world. if the user pressed one coin he gets a point.... and so on ;-)
is this possible ?
thanks marinka ;-)
Upvotes: 2
Views: 373
Reputation: 3762
An old school method of picking involves rendering your openGL scene to a off-screen buffer each frame, using a specific color for each object. Figure out the pixel the user clicked on, and grab the color at that pixel from your buffer. Simple reverse map that color to the object that was rendered with it, and you know which object (if any) was clicked on.
It does have the benefit of doing depth sorting for you (for example, if your coins are on top of each other).
Code example found here: http://gpwiki.org/index.php/OpenGL_Selection_Using_Unique_Color_IDs
Upvotes: 1
Reputation: 1208
It is a lot like detecting collisions(But a lot faster :). Find the position of the tap and then compare it to the position of the coin. If they are with in a certain radius then you have tapped the coin. I am not sure if OpenGLES (but it's very unlikely) that it provides any mechanism.
Upvotes: 0