Iphone OpengGL ES: detecting clicks on a primitive

天涯浪子 提交于 2019-12-08 12:18:52

问题


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!!!!


回答1:


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?



来源:https://stackoverflow.com/questions/4349440/iphone-openggl-es-detecting-clicks-on-a-primitive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!