Box2D-如何知道2个灯具何时接触? [英] Box2D - How can I know when 2 Fixtures are touching?

查看:59
本文介绍了Box2D-如何知道2个灯具何时接触?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是很好奇,如果我的身体中有两个或两个以上不连接在一起的固定装置,我该如何在代码中确定性地确定?这是我的意思的示例:

I'm just curious, in the case that I have a body that has 2 or more fixtures in it that are not "joined together", how can I determine this definitively in code? Here is an example of what I mean:

我标记了每个独特夹具的顶点,只是为了完全清楚地表明它们是彼此不共享顶点的单独形状。但是它们被组合成一个整体。如您所见,两个固定装置彼此非常靠近或触摸,并且一个固定装置彼此分开。我想知道如何在Box2D中查询物体的固定装置,以便能够在运行时找到它。

I marked the vertices for each distinctive fixture just to make it completely clear that these are separate shapes which do not share vertices with each other. They are however combined into a single body. As you can see, two fixtures are within very close proximity to each other or "touching", and one is set apart by itself. I'm wondering how I can query the fixtures of a body in Box2D to be able to find this out at runtime.

为了使所有这些东西都可见,它是用于创建和处理的可破坏的身体。该图像粗略地表示了将孔穿入体内的一组固定装置之后将发生的情况。我需要查询以查看哪些固定装置相互接触,以便可以将一个主体一分为二,就像它们自然应该在那一点一样。

In order to put this all into perspective, it's for creating and processing destructible bodies. The image is a rough representation of what will happen after a hole has been punched through a set of fixtures in a body. I need to query to see which fixtures touch each other so that I can split the one body into two, as naturally they should be at that point.

推荐答案

如果您已经准备好新的灯具,则可以使用b2TestOverlap函数检查它们是否重叠。该函数位于b2Collision.h中:

If you already have the new fixtures prepared you could use the b2TestOverlap function to check if they are overlapping. The function is found in b2Collision.h:

/// Determine if two generic shapes overlap.
bool b2TestOverlap( const b2Shape* shapeA, int32 indexA,
                    const b2Shape* shapeB, int32 indexB,
                    const b2Transform& xfA, const b2Transform& xfB );

形状可以通过fixture-> GetShape()找到,并且索引参数对于多边形。
由于固定装置位于同一主体上,因此最后两个参数都可以是body-> GetTransform()。

The shapes can be found by fixture->GetShape(), and the index parameters will be zero for polygons. As the fixtures are on the same body, the last two parameters can both be body->GetTransform().

我自己从未使用过它,所以我不能肯定地告诉您,但是请注意此函数的名称是 overlap,对于您在图中的A和B灯具,它可能不会返回正数,因为从技术上讲,我不认为它们是重叠的。如果是这种情况,我想您是一个人,因为Box2D不提供任何动人测试。

I have never used this myself so I couldn't tell you for sure, but noting that the name of this function is 'overlap', it may not return a positive for the case of your A and B fixtures in the diagram since technically I don't think they are overlapping. If this is the case, I think you are on your own because Box2D doesn't offer any 'touching' tests.

btwConstantinius提及的联系人列表仅有效用于不同物体上的灯具发生碰撞-同一物体上的灯具不会发生碰撞。

btw the contact list mentioned by Constantinius is only valid for fixtures on different bodies colliding - fixtures on the same body don't collide.

这篇关于Box2D-如何知道2个灯具何时接触?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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