将鼠标侦听器添加到 GL 空间内的对象

发布于 2024-11-07 18:23:51 字数 231 浏览 3 评论 0原文

作为我正在编写的游戏的一部分,我有一个纹理地平面,目前作为四边形实现。

我需要能够监听鼠标点击并确定它们在地平面上的坐标。

我可以轻松实现一个返回视空间内坐标的侦听器。然而,视点是可移动的,因此视空间中的像素并不总是对应于地平面上的相同坐标。

是否可以为四边形实现鼠标侦听器?

否则,是否有另一种平面实现可以让我对平面进行纹理处理并侦听鼠标事件。

任何建议都非常感谢!

As part of a game I am writing, I have a textured ground plane that is currently implemented as a quad.

I need to be able to listen for mouse clicks and pin point their coordinates on the ground plane.

I can easily implement a listener that returns the coordinates within the viewspace. However, the viewpoint is moveable, so a pixel in the viewspace does not always correspond to the same coordinates on the ground plane.

Is it possible to implement a mouse listener for a quad?

Otherwise, is there an alternative plane implementation that will allow me to texture the plane and listen for mouse events.

Any advice greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

夏の忆 2024-11-14 18:23:51

OpenGL 只是将东西绘制到屏幕上。特别是它可以绘制点、线、三角形、四边形和凸平面多边形。一旦设置了像素,OpenGL 就不再保留它所绘制的内容。

您所考虑的术语称为场景图,但 OpenGL 不是这样的东西。

然而,您当然可以实现一个使用 OpenGL 来绘制内容的场景图,并且该场景图可以实现事件管理并将事件侦听器关联到它绘制的内容。

OpenGL just draws stuff to the screen. In particular it draws points, lines, triangles, quads and convex planar polygons. Once the pixels have been set, OpenGL has no persistency about what it drew.

The terms in which you're thinking in is called a scene graph, but OpenGL is not such a thing.

However you can of course implement a scene graph that used OpenGL for drawing stuff, and this scene graph could implement event management and associate event listeners to stuff it drew.

一身仙ぐ女味 2024-11-14 18:23:51

我读到你的问题时想到的第一件事是(挑选)。但由于您只有一个四边形,因此您将无法确定四边形内的位置。

另一种解决方案是在 OpenGL 范围之外解决此问题并计算光线与四边形的交集。为了确定从视点到场景的光线,您仍然需要 OpenGL 上下文。

The first thing I thought of reading your question was (Picking). But since you've only a single quad you won't be able to determine positions within the quad.

Another solution would be to solve this problem outside the scope of OpenGL and calculate the intersection of the ray and the quad. To determine the ray that goes from the point of view to the scene you would still need the OpenGL context though.

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