I am making an ipad application in OpenGLES 2.0 and I have some objects that I should be able to translate with the touch event. So I need the (x,y,z) object coordinates corresponding to the screen (X,Y,Z) coordinates. I was able to get this tutotial online:
http://softwareprodigy.blogspot.com/2009/08/gluunproject-for-iphone-opengl-es.html
But the problem is as I am working on OpenGL ES 2.0, I have my own projection, model and camera matrix which I pass to the vertex shader. First I need the Viewport matrix (I mention the viewport using glViewPort() built in function), How can I get that ?
Secondly, I was not able to get the process described to intersect a ray with the planes? Can somebody explain it or provide an alternate method ??
oK I figured out everything from above and its working, Now I have a new problem :P
I am able to get the (x,y) object coordinates and can get the z coordinate too based on the intersection of the ray. However, when I translate or rotate my objects, my model matrix changes and this results in the change of object coordinates but I know the initial coordinates only which i used to draw the objects (so I cannot determine if the object hit by the ray is correct).
Is there any way I can keep track of my object coordinates ??? One way is to apply the same transforms to the centre point of the object and keep its value but this would only work with spherical(symmetrical objects). Any ideas???