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?
I found this code, but it is OpenGL ES 1.0: i-schuetz / Android_OpenGL_Picking
Screenshot of app running so you can see camera distortion.
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;
}
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.