How to detect which 3d object has been touched?

筅森魡賤 提交于 2019-12-11 05:07:53

问题


Assume I have 3 cubes in random location/rotation that are visible in the viewport. I want to be able to detect if which of the cube has been touched if I touch ( or click on emulator) a specific cube. If I just touch empty space instead of a cube, this should also be properly detected. I know there is onTouchEvent callback that you over-ride on a View but this only gives me x,y coordinate of where the touch occurred. I am looking for OpenGL-ES based solution and more specifically for Java based Android application.


回答1:


THere could be several objects (or none) that are on that x / y coordinate. You should find them all, and then if there are any, check the z-coordinate to see which one is the closest to the viewport (and so the one that was touched).




回答2:


Often wondered about best way to do this without glSelect()... this answer looks good: iPhone OpenGL ES - How to Pick

(You can ignore the fact it's an iOS question... the OpenGL ES API is the same on both platforms AFAIK).



来源:https://stackoverflow.com/questions/5040349/how-to-detect-which-3d-object-has-been-touched

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