简单的碰撞检测 [英] Simple collision detection
问题描述
我想写一个平台游戏,我所做的一切都是益智游戏,不需要物理。
我需要的只是简单的碰撞检测,我会提供的物理引擎是所有的位置对象,它应该输出:
- 与任何对象(和什么对象)碰撞的特定对象类型
。
所有的移动/速度/重力/点击/反射的模拟将使用自定义代码完成,因为我想实现的是一个有奇怪物理学的世界。
我应该滚自己的引擎吗?我可以使用现有的像chipmunk / box2d吗?如果我需要实现自己的我将如何进行碰撞检测,而不是一个昂贵的操作? (像一个只是检查 O(n ^ 2)
中的一切的简单实现。
我可以使用objective-c或c ++,我更喜欢c ++ (应该有更好的性能)。
对于这种问题,我建议你写自己的库。 / p>
是的,您可以在现有的图书馆中找到这种功能,不过您会从编写自己的图书中学到更多。
我建议查看图形和树形数据结构。
I want to write a platform game, all I done before was puzzle games with no need of physics.
All I need is simple collision detection, what I will supply the physics engine is position of all objects and it should output:
- All objects of a specific object type (bullets) that collide with any object (and what object), just a list of pairs.
- For every object of a specific object type (players and npcs) if its on ground or in mid air.
All the simulation of move/speed/gravity/hits/reflections will be done using custom code because what I want to implement is a world with strange physics.
Should I roll my own engine? can I use existing ones like chipmunk/box2d? If I need to implement my own how will I make collision detection not a costly operation? (like a naive implementation of just checking everything in O(n^2)
.
I can use objective-c or c++, I would prefer c++ (it should have better performance).
For this kind of problem, I'd recommend you write your own library.
Yes, you can find this kind of feature in existing libraries, however you'll learn a lot more from writing your own.
I recommend looking into graph and tree data structures.
这篇关于简单的碰撞检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!