仅在我的 2d 引擎中集成 Box2D 碰撞检测?
我已经将 box2d 集成到我的引擎中(调试绘制等),并且在一个世界中我可以放入一些 2d 正方形/矩形等。
我看到 这篇 帖子,其中用户基本上没有使用世界进行碰撞检测,但是用户没有解释任何有关他如何使用世界的信息流形(b2Manifold)等
另一篇文章,在cocos2d论坛中,(向下滚动到第三个回复中的用户 Lam )
有人可以帮助我吗?基本上想添加碰撞检测,而不需要使用 b2World 等。
非常感谢!
I have integrated box2d in my engine, ( Debug Draw, etc. ) and with a world I can throw in some 2d squares/rectangles etc.
I saw this post, where the user is basically not using a world for collision detection, however the user doesn't explain anything about how he's using the manifold (b2Manifold), etc.
Another post, is in the cocos2d forum, ( scroll down to the user Lam in the third reply )
Could anyone help me a bit with this?, basically want to add collision detection without the need of using b2World ,etc etc.
Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有什么理由不能使用 b2World 吗?仅仅因为您使用它,并不意味着您必须使用物理模拟,除非您的性能受到严重限制。
请参阅此示例,了解仅在 Cocos2d 中使用 Box2D 进行碰撞。也许您可以应用与您的项目类似的内容: http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
Is there any reason you can't use a b2World? Just because you use it, doesn't mean you have to use the physics simulations, unless you're severely performance limited.
See this example on using Box2D for collision only in Cocos2d. Maybe you can apply something similar to your project: http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
对我来说,这两篇文章中的代码似乎都很完整。您从两个多边形形状及其相应的变换开始,然后从 b2CollidePolygons 中您得到一个接触流形。
b2Manifold 只是两个形状边界相交点的集合。在发布的代码中,作者使用如果流形的点数大于零,则存在重叠。根据形状的性质,当它们重叠时可以有不同数量的交点。
请注意,b2World 的碰撞处理非常稳健。除了简单的碰撞查询之外,它还具有宽相剔除、光线投射、空间树、开始接触和结束接触事件、高效的内存管理等等。 API 中提供了用于大多数此类任务的类,但我不能说我熟悉手动使用它们。可能值得一看。
The code in both of those posts seems complete to me. You begin with two polygon shapes and their corresponding transforms and from b2CollidePolygons you get back a contact manifold.
The b2Manifold is just a collection of points at which the two shapes' boundaries intersect. In the posted code the author uses that if the manifold's point count is greater than zero there is an overlap. Depending on the nature of the shapes there can be different number of intersection points when they overlap.
Note that the collision handling of the b2World is quite robust. Beyond simple collision queries it has broad-phase culling, ray-casting, a spatial tree, begin-contact and end-contact events, efficient memory management to name some things. There are classes in the API for most of these tasks but I can't say I'm familiar with using them manually. Could be worth a look.