在 Ipad 上将屏幕坐标转换为对象坐标 OpenGL ES 2.0
我正在 OpenGLES 2.0 中制作一个 ipad 应用程序,并且我有一些应该能够通过触摸事件进行转换的对象。所以我需要与屏幕(X,Y,Z)坐标相对应的(x,y,z)对象坐标。我可以在线获取此教程:
http:// softwareprodigy.blogspot.com/2009/08/gluunproject-for-iphone-opengl-es.html
但问题是我正在研究 OpenGL ES 2.0,我有自己的投影、模型和相机矩阵,我将它们传递给顶点着色器。 首先我需要视口矩阵(我提到使用 glViewPort() 内置函数的视口),我怎样才能得到它?
其次,我无法获得所描述的使光线与平面相交的过程? 有人可以解释一下或提供替代方法吗?
好吧,我弄清楚了上面的所有内容及其工作原理,现在我有一个新问题:P
我能够获取 (x,y) 对象坐标,并且也可以根据射线的交集获取 z 坐标。 但是,当我平移或旋转对象时,我的模型矩阵会发生变化,这会导致对象坐标发生变化,但我只知道用于绘制对象的初始坐标(因此我无法确定光线击中的对象是否是正确的)。
有什么方法可以跟踪我的对象坐标??? 一种方法是将相同的变换应用于对象的中心点并保留其值,但这仅适用于球形(对称对象)。有什么想法吗???
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???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenGL中没有视口矩阵,只有视口参数,与传递给glViewport的参数相同。您可以使用 glGetIntegerv 和 GL_VIEWPORT 作为 pname 来获取它们:
来自 glGet OpenGL ES 2.0 手册页
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:
From the glGet OpenGL ES 2.0 man page