询问 Box2d 是否发生了碰撞
我正在使用 Box2dx(移植到 C#;针对 XNA 进行了优化)。它处理碰撞解决,但我如何判断两个对象当前是否正在碰撞?
这是我正在尝试编写的函数:
public bool IsColliding(GameObjectController collider1, GameObjectController collider2)
其中 collider1.Model.Body
是 Box2d Body
,而 collider1.Model.BodyDef
是Box2d BodyDef
。 (当然,collider2
也是如此。)
更新: 看起来像接触监听器,或者这可能有用:
AABB collisionBox;
model.Body.GetFixtureList().GetAABB(out collisionBox);
Why does GetFixtureList()
return一个固定装置?
I'm using Box2dx (ported to C#; optimized for XNA). It handles collision resolution, but how can I tell if two objects are currently colliding?
This is the function I'm trying to write:
public bool IsColliding(GameObjectController collider1, GameObjectController collider2)
Where collider1.Model.Body
is the Box2d Body
, and collider1.Model.BodyDef
is the Box2d BodyDef
. (The same goes for collider2
, of course.)
UPDATE: Looks like contact listeners or this could be useful:
AABB collisionBox;
model.Body.GetFixtureList().GetAABB(out collisionBox);
Why does GetFixtureList()
return one fixture?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您知道形状类型,则可以使用以下任何函数来直接检查重叠。
它们都有两种形状和两种变换。结果是一个 Manifold 对象,其中包含形状边界相交的点的集合。如果点数大于零,则发生碰撞。
您可以通过类实现 ContactListener 接口来间接获取相同的信息。
禁止从 Contact._fixtureA.Body 和 Contact._fixtureB.Body 中找到这两个实体。您必须向世界注册侦听器对象。
GetFixtureList()、GetBodyList()、GetJointList() 等返回链表中的第一个元素。通过对元素调用 GetNext() 可以找到列表中的下一个元素。您可以使用以下代码迭代该列表。当 GetNext() 返回 null 时,就不再有元素了。
If you know the shape types you can use any of the following functions to directly check for overlap.
They all take two shapes and two transforms. The result is a Manifold object which contains a collection of points where the shape boundaries intersect. If the number of points is greater than zero you have a collision.
You can get the same information indirectly by implementing the ContactListener interface by a class.
The two bodies ban be found from Contact._fixtureA.Body and Contact._fixtureB.Body. You have to register the listener object with the World.
GetFixtureList(), GetBodyList(), GetJointList(), etc. return the first element in a linked list. The next element in the list is found by calling GetNext() on the element. You can iterate over the list with the following code. When GetNext() returns null there are no more elements.