Projection of Square onto 2D Plane (OpenGL ES2)

二次信任 提交于 2019-12-23 04:42:30

问题


I'm in the process of creating a coverflow view for android, but I'm running into a little bit of a roadblock when handling clicks on the view. I'm having trouble determining which square is beneath the click. In order to determine which square is clicked, the (X,Y) data from the click event is taken and converted into the opengl view space. The trouble comes when placing this on a square: the transposition, rotation, and compares can all be done in java, but this seems like a huge waste, since all these operations are being done when rendering the view.

So, my question is: How can I extract the 2d view-mapped object coordinates during the opengl render process?

I've gotten my brain in a bit of a twist trying to figure out what is actually in opengl's model and projection matrices, and I can't seem to find any specification of what the numbers in the matrix actually mean.

Thanks!


回答1:


You can use gluUnProject() and gluProject() for converting between object and window space and save yourself some math. Docs are here and here.




回答2:


There is another technique that involves rendering one frame where all the primitives in the scene are rendered in different colors. Then you can test the pixel color under the touch event. There are tricks that you can play with this technique like shrinking the viewport so that it is only a small area around the touch and rendering that to a texture so the user never sees it.



来源:https://stackoverflow.com/questions/11300416/projection-of-square-onto-2d-plane-opengl-es2

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