如何检查点是否与自定义 2D 物理引擎的 AABB 相交
我在谷歌上找不到创建 2D 碰撞 AABB 的方法,我想知道它的数学原理是如何工作的。我当时想我可以使用某种矩阵变换来实现它,但这个想法彻底失败了。所以基本上,我想知道任何可以帮助我创建角度对齐边界框并检查点是否与其相交的资源,或者对其数学和逻辑的解释。
编辑:我不知道我是否说清楚了,但我需要测试与它们的碰撞。只是为了让这一点变得清晰。
I've found no way of creating a 2D collision AABB on google, and I was wondering how the maths of it work. I was thinking that I could use some kind of matrix transforms to achieve it but that idea failed epically. So basically, I want to know of any resource that can help me create an Angle-Aligned Bounding Box and check if a point intersects it, or an explanation of the maths and logic of it.
Edit: I don't know if I made it clear, but I need to test collisions with them. Just to make that crystal clear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两个矩形之间的相交检查不允许您检查旋转的矩形。因为简单的相交函数将不起作用。您计算包含“实际”旋转矩形的矩形的想法,然后检查边界矩形上的碰撞。
下面是一些代码,它将基于另一个矩形和旋转矩阵变换返回一个矩形:
当然,这种类型的碰撞检测速度很快,但不准确。您的边界矩形不会是您形状的 1:1 表示。如果您需要更高的准确性,则可以在使用 AABB 检查后使用逐像素碰撞检查。
这个答案可能也会引起您的兴趣,特别是关于SAT。
An intersection check between two Rectangles does not allow you to check against a rotated rectangle. The as the simple intersects function will not work. Your idea of calculating a Rectangle that encompasses your "actual" rotated Rectangle, and then checking for collisions on the Bounding Rectangles instead.
Here is some code that will return a Rectangle based on another Rectangle and a Rotation Matrix transformation:
Of course, this type of collision detection is fast, but not accurate. Your Bounding rectangle will not be a 1:1 representation of your shape. If you need more accuracy, you could then use a per-pixel collision check after checking with AABB.
This answer might also be of interest to you, particularly the answer on SAT.