简体   繁体   English

如何进行正确的二维网格到圆碰撞检测

[英]How to make a correct 2d mesh-to-circle collision detection

I'm trying to do a mesh-to-circle collision system for my game. 我正在尝试为我的游戏制作一个网格到圆的碰撞系统。 I've seen some examples where you iterate over all the verts of the mesh and check if they are inside the circle. 我看过一些示例,其中您遍历了网格的所有顶点,并检查它们是否在圆内。 But the problem is that sometimes the vertices are not inside the circle, but the lines that this vertices form are. 但是问题在于,有时顶点不在圆内,而是此顶点形成的线在圆内。 In this cases, the collision check evaluates to false when it should evaluate to true. 在这种情况下,冲突检查应评估为true时评估为false。 How can I make a good collision detection of this type? 如何进行这种类型的良好碰撞检测? (in c/c++) (在C / C ++中)

If you want you could calculate the distance from the line to the center of the circle. 如果需要,可以计算从直线到圆心的距离。 But I think it will be too costly. 但是我认为这太昂贵了。 If the distance is lower than the radio you could have a collision. 如果距离小于收音机,则可能发生碰撞。 You will need to check if this part of the line is between the points. 您将需要检查线的这一部分是否在两点之间。 Distance line to point 线到点距离

实际上,一个快速的Google会让您知道这是堆栈上已经存在的一个问题的重复: 圆线段碰撞检测算法?

Just iterate over all the edges. 只是遍历所有边缘。 And don't worry about the vertices: if a vertex is inside the circle, some edge is bound to cross it (unless the entire grid is inside the circle, which I'm guessing isn't likely). 而且不必担心顶点:如果顶点在圆内,则一定有一条边与之相交(除非整个网格都在圆内,我猜这不太可能)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM