0

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???

4

1 に答える 1

1

OpenGLにはビューポートマトリックスはなく、glViewportに渡すのと同じビューポートパラメータのみがあります。GL_VIEWPORTをpnameとしてglGetIntegervを使用してそれらを取得できます。

GL_VIEWPORT paramsは、ビューポートのxウィンドウ座標とyウィンドウ座標、それに続く幅と高さの4つの値を返します。最初に、xウィンドウとyウィンドウの座標は両方とも0に設定され、幅と高さはGLがレンダリングを行うウィンドウの幅と高さに設定されます。glViewportを参照してください。

glGet OpenGLES2.0のマニュアルページから

于 2011-06-29T20:23:06.970 に答える