如何有效地检测射线和网格的相交检测?

发布于 2024-09-19 04:06:57 字数 487 浏览 4 评论 0原文

我在 iPhone 的 OpenGL ES 应用程序中有几个 3D 模型,有时我希望用户触摸屏幕并对它们进行操作。问题是要识别屏幕上呈现的哪些内容已被触摸。为了实现这一目标,我按照 OpenGL FAQ 的建议计算了拾取光线,现在我想检测它是否与任何模型相交。

我查看了 irrlicht 源代码,发现我可以计算光线与每个模型三角形之间的交点(他们通过首先计算光线是否与三角形平面相交,然后查看交点是否落入三角形,但有一种更有效的方法,如所述 此处)。

我的问题是:我真的需要对每个模型的每个三角形进行所有这些计算吗?难道没有更好的方法(也许不是那么精确)来达到类似的结果吗?

I have several 3d models in an OpenGL ES application for iPhone and at some point i want the user to touch the screen and act on them. The problem is to recognize which, among the ones rendered on the screen, has been touched. In order to achieve this I calculated the picking ray as suggested by the OpenGL FAQ, and I now want to detect if it intersects to any model.

I've looked up at the irrlicht source code and found that I can calculate the intersection between the ray and each single model triangle (they do this by calculating if the ray intersects the triangle plane first and then by seeing whether the intersection point falls into the triangle, but there is a more efficient way to do so as stated here).

My question is: do I really need to do all this computation for each single triangle of every model? Isn't there a better way (maybe not so precise) to achieve a similar result?

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

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

发布评论

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

评论(1

全部不再 2024-09-26 04:06:57

你说得很对,有更好的方法来穿过这棵树。一种方法是围绕对象构建一个八叉树。然后,如果射线与 8 个线段之一相交,您可以检查它与 8 个子线段中的哪一个相交,依此类推,直到剩下几个三角形来进行相交测试。另一种方法是构建Kd树

有很多方法可以有效地处理这个问题。查找有关 光线追踪加速结构

You are quite right there ARE better ways to go through the tree. One method is to build an octtree around the object. Then if the ray intersects one of the 8 segments you can check which of its 8 children it intersects and so on until you are left with a few triangles to do an intersection test against. Another method is to build a K-d tree.

There are many many ways to efficiently handle this problem. Look up info on ray tracing acceleration structures.

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