在 Ipad 上将屏幕坐标转换为对象坐标 OpenGL ES 2.0

发布于 2024-11-17 22:09:24 字数 725 浏览 5 评论 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栩栩如生 2024-11-24 22:09:24

OpenGL中没有视口矩阵,只有视口参数,与传递给glViewport的参数相同。您可以使用 glGetIntegerv 和 GL_VIEWPORT 作为 pname 来获取它们:

GL_VIEWPORT
params 返回四个值:

x

y
视口的窗口坐标,
其次是它的宽度和高度。
最初的
x

y
窗口坐标均设置为 0,
并且宽度和高度设置为窗口的宽度和高度
GL 将进行渲染。
请参阅 glViewport。

来自 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:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文