本文介绍了使用gluUnProject映射润色X,Y线在z = 0平面的Andr​​oid的OpenGL ES 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我在OpenGL ES 2.0绘制网格在z = 0,只是想触摸输入x / y坐标上飞机转换。看起来这通过光线追踪,其中包括在0和1的运行gluUnProject,然后创建一个线,解决了光线用于z是最好的做法= 0?I've drawn a grid at z=0 in OpenGL 2.0 ES, and just want to convert touch inputs to x/y coordinates on that plane. It seems like this is best done through ray tracing, which involves running gluUnProject on 0 and 1, then creating a ray, solving that ray for z=0?我发现这个code,但它的OpenGL ES 1.0: I-schuetz / Android_OpenGL_PickingI found this code, but it is OpenGL ES 1.0: i-schuetz / Android_OpenGL_Picking 应用程序运行的,所以你可以看到摄像头变形的屏幕截图。 我的code Github上,只有4个文件。该unproject功能我试着写在MyGLRenderer.java:My code on Github, only 4 files. The unproject function I'm trying to write is in MyGLRenderer.java: public float[] unproject(float rx, float ry) { float rz = 1; float[] xyzw = {0, 0, 0, 0}; int[] viewport = {0, 0, mDisplayWidth, mDisplayHeight}; android.opengl.GLU.gluUnProject( rx, ry, rz, // window coordinates mViewMatrix, 0, mProjectionMatrix, 0, viewport, 0, xyzw, 0); xyzw[0] /= xyzw[3]; xyzw[1] /= xyzw[3]; xyzw[2] /= xyzw[3]; xyzw[3] = 1; return xyzw; }我想这个函数来采取Rx和Ry为屏幕,并返回Rx和Ry为Z = 0的平面。I would like this function to take an rx and ry for the screen, and return an rx and ry for the z=0 plane.推荐答案没有什么特别之处是什么 gluUnProject(...)一样。如果你把所有的矩阵和视口尺寸)/ 视窗 )/ 视窗                  †                           对象 XYZ 的是W 的 =(投影矩阵× 模型视图矩阵) 1  × NDC XYZ 1 的                           Object = (Projection Matrix × ModelView Matrix)-1 × NDC现在,你可能会注意到,我打叉的是W 的对象 XYZ ,我们真的不关心这个,但在所有的数学会产生一个讨厌的是W 的价值不过。在这一点上,你可以返回对象 XYZ 作为您的研究 X ,R 是 和研究以ZNow, you may notice that I crossed-out W in Object, we really do not care about this at all but the math will produce a pesky W value nevertheless. At this point, you can return the individual components of Object as your r, r and r. 这篇关于使用gluUnProject映射润色X,Y线在z = 0平面的Andr​​oid的OpenGL ES 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-14 00:43