游戏中具有可移动和可旋转角色/对象/等的AABB [英] AABB in a game with moveable and rotateable characters/objects/etc

查看:86
本文介绍了游戏中具有可移动和可旋转角色/对象/等的AABB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那天我正在创建自己的第一个3d游戏,但遇到了一些问题。



我了解了AABB交叉路口和建造的想法树木,但是
我无法理解的一件事是,如果我的角色在游戏中旋转,则不会保留轴对齐的概念!



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



那些库应该是超快速的,我可能在某个地方弄错了。 / p>

有人可以帮我解决一下这个话题吗?

解决方案

可悲的是,如果角色旋转,则需要重新计算AABB,也不一定很合适。如果您有一个矩形并旋转它,以使其不再是矩形,那么AABB将比对象大。



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



AABB仍可用于快速测试,我怀疑这些树是为。借助AABB树,您可以从更准确的测试阶段中快速消除大量物体。如果查询返回了几个额外的对象,那就没关系了。在轮换角色的情况下,这可能意味着您的角色实际上不在某个区域内。



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



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



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



这里是实施



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


In those day I'm creating my very first 3d game and I've ran into 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.

Can somebody please help me with shedding some light on this topic?

解决方案

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.

这篇关于游戏中具有可移动和可旋转角色/对象/等的AABB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆