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.