0

I have created a 3d environment full of 3D cubes, does anyone have any idea how you would detect a touch on one of these Cubes. I thinking if I could get the cubes screen position (coords start from bottom left) then it would be pretty easy

UPDATE:

I added the function -(CGPoint)getScreenCoorOfPoint:(IMPoint3D)_point3D which seems to give me my items position in the world but the bit I am now stuck on is:

  • I have objects that have a position

  • I have my position in the world (gluLookAt eye[0], eye[1], eye[2])

  • and then I have where I tapped on the screen

How do I join all this up, its the last thing in my way to archiving greatness!!!!

Burf2000
  • 5,001
  • 14
  • 58
  • 117

1 Answers1

2

Look up OpenGL picking on Google. There are two main methods to accomplish this, I recommend you use the second one described at OpenGL.org as it does not involve rendering anything offscreen:

[…] involves shooting a pick ray through the mouse location and testing for intersections with the currently displayed objects. OpenGL doesn't test for ray intersections, but you'll need to interact with OpenGL to generate the pick ray.

Also see this question for some discussion on the matter: Screen-to-World coordinate conversion in OpenGLES an easy task?

Community
  • 1
  • 1
Julio Gorgé
  • 10,056
  • 2
  • 45
  • 60
  • I read that OpenGL ES for the iPhone does not support picking – Burf2000 Dec 03 '10 at 20:30
  • 3
    OpenGL ES may lack OpenGL's selection mode, but that's only one way of doing picking. Go for view projection + ray intersection instead as I suggested. See http://efreedom.com/Question/1-2540447/iPhone-OpenGL-ES-Pick or http://stackoverflow.com/questions/2231433/opengl-es-iphone-touch-picking . An even better resource: http://eigenclass.blogspot.com/2008/10/opengl-es-picking-using-ray-boundingbox.html – Julio Gorgé Dec 03 '10 at 20:41
  • First link was very useful, and gives me the positions of objective but does not update if that makes sense. So if I move the object pos does not change. I surely missing something – Burf2000 Dec 03 '10 at 22:25