Converting screen coordinates to object coordinates OpenGL ES 2.0 on Ipad
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 hav开发者_如何学运维e 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???
There is no viewport matrix in OpenGL, only the viewport parameters, which are the same you pass to glViewport. You can get them using glGetIntegerv with GL_VIEWPORT as pname:
GL_VIEWPORT params returns four values: the x and y window coordinates of the viewport, followed by its width and height. Initially the x and y window coordinates are both set to 0, and the width and height are set to the width and height of the window into which the GL will do its rendering. See glViewport.
From the glGet OpenGL ES 2.0 man page
精彩评论