OpenGL-ES: How to set an object at the coordinates of the touch?

故事扮演 提交于 2020-01-05 09:04:38

问题


I'm looking for a way to have an opengl object(triangles etc) at the location on the screen where you touch the screen. I now have an 3D pyramid on the screen, wich moves over the screen, based on the difference between the start of your touch, and where you dragged it to.
In normal surfaceViews I could just do something like element.x = event.getX(), but this will not work in openGL. So anyone has an idea?
ps: i'm using java/Android.


回答1:


OpenGL is nor like a surface view, where each element is persistent. It's the 3D equivalent to pens and brushes. You need to keep track of all data yourself.

So in your touch event handler you use the input coordinate to project a ray so some plane perpendicular to the view. You've to implement this projection yourself, but it's easy enough: Search for "ray plane intersection". This gives you the coordinates on the plane, that corresponds with that points projection on the screen where the user touched. You use this coordinates to transform the object and redraw the scene.



来源:https://stackoverflow.com/questions/6534800/opengl-es-how-to-set-an-object-at-the-coordinates-of-the-touch

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