具有可移动和可旋转角色/物体/等的游戏中的 AABB

发布于 2024-09-30 21:21:44 字数 382 浏览 0 评论 0原文

我正在创建我的第一个 3D 游戏,但遇到了一些问题。

我读到了 AABB 交叉以及从中构建树木的想法,但是我无法理解的一件事是,如果我的“角色”在游戏过程中旋转,则轴对齐的概念不会保留!

我检查了几个库(例如 oz-collide、OPCODE 等),并且我发现这些实现是针对静态对象进行的,因为它使用没有原点的框(对于非静态,所有节点树中的内容应在每次移动后更新)。

这些库应该超快,但我可能在某个地方弄错了。

解释是什么?

I'm creating my very first 3D game and I've run into a couple of problems.

I read about AABB intersectioning and the idea of building trees from it, but the one thing that I couldn't understand is, if my "character" rotates during the game, the concept of the axis-aligned isn't preserved!

I've checked a couple of libraries (like oz-collide, OPCODE, and more), and I've seen that the implementations were made for static objects, because it uses the boxes without an origin (for non static, all the nodes in the tree should be updated after each movement).

Those libraries supposed to be super-fast, and I had probably mistaken somewhere.

What is the explanation?

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

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

发布评论

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

评论(2

无人接听 2024-10-07 21:21:44

不幸的是,如果你的角色旋转,你需要重新计算你的 AABB,而且它也不一定是合适的。如果你有一个矩形并旋转它,使其不再是直线,则 AABB 将比该对象大。

AABB 速度很快,因为相交测试非常简单,但正如您已经发现的那样,当需要对未与 AABB 轴对齐的对象进行精确相交时,就会出现问题。

AABB 对于快速测试仍然有用,我怀疑这些树就是为此而生的。使用 AABB 树,您可以从更准确的测试阶段快速消除大片对象。如果查询返回几个额外的对象,那并不重要。在您旋转的角色情况下,这可能意味着您的角色被视为位于某个区域,而他/她实际上并不在该区域中。

AABB 树很容易做到这一点,因为每次通过测试时,您都会更深入地了解树并了解更多细节。

当您需要真正精确的交叉点时,可以使用定向边界框 (OBB)。它可以通过分离轴定理来实现。我看到 oz-collide 已经支持 OBB 了。

OBB 上有很多资源,这个对我有帮助:
GPWiki 关于分离轴定理

这是一个 实施

如果需要,您可以根据 OBB 计算 AABB。

Sadly yes, if your character rotates you need to recalculate your AABB, and it will not necessarily be a snug fit either. If you have a rectangle and rotate it so it's no longer rectiliniear the AABB will be bigger than the object.

The AABB is fast because the intersection test is very simple but as you've already discovered it becomes problematic when accurate intersections are needed on objects not aligned to the AABBs axes.

The AABB is still useful for quick tests, which I suspect those trees are made for. With a AABB tree you can quickly eliminate large swathes of objects from a more accurate testing phase. If the query returns a couple of extra objects it doesn't matter much. In your rotated character case this might mean that your character is regarded as in a region when he/she really isn't.

The AABB-tree lends itself to this with ease since each time you pass a test you go deeper into the tree and into more detail.

You can use a Oriented Bounding Box (OBB) when you need really accurate intersections. It can be implemented with the separating axis theorem. I see oz-collide has support for OBBs already.

There are alot of resources on OBBs, this one helped me:
GPWiki on separating axis theorem

Here's an implementation.

You can calculate an AABB from an OBB if you need to.

掩耳倾听 2024-10-07 21:21:44

OZCollide 适用于可移动实体并且与时间无关(您只需给出速度矢量)。
它也适用于 OBB(不仅是 AABB)。

查看在线文档:
http://www.tsarevitch.org/ozcollide/docs/ 链接已损坏

OZCollide works for moveable entities and is time independent (you just have to give a velocity vector).
It also works for OBB (not only AABB).

Check the online documentation:
http://www.tsarevitch.org/ozcollide/docs/ link broken

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