Creating a (robust) physics engine is a lot more complicated then it may seem at first. The trick is to fake as much as possible rather than calculate the exact values. As a starting point, this blog post has a great introduction. I think this paper by Thomas Jakobsen is also a good read and introduces certain concepts. This blog also has a few interesting articles explaining the details of integrators and how to manage physics for online games.
Going through the source code of physics engines such as Box2D is a good idea to see implementation, but if you don't know the theory of what they're doing, it can come across as confusing. The reason for this is because of the fact that the theory is often too inefficient to implement in a real time game and so algorithms and techniques are used to strike a balance between realism and speed.
If you're creating your own physics engine because you want to use it in a commercial game, I'd suggest choosing an already existing solution instead. (For example, Angry Birds uses Box2D). However, if you're doing it for the experience and for learning about physics engines, it's certainly something that'll teach you quite a bit about efficiency and smart techniques.
In principle, all physics engines are simply a direct application of Newton's second law of motion:
acceleration = force / mass
By integrating acceleration over time, you get velocity. By integrating velocity, you get the positions of the object in space. The integrals are performed numerically, using something like Runge-Kutta.
The main complications arise from:
Handling rotational motion
Handling impulse events, such as collisions and explosions
Detecting collisions at the extreme ends of velocity. At high speeds, objects can end up penetrating or even passing through each other before the collision is detected. At low speeds, it is a challenge to robustly handle one object resting on another without jittering or sliding around
Kinematic linkages, where objects are partially constrained to each other (like a hinge or slider)
Calculating the forces and torques for complex objects such as cars or aircraft
Doing all this efficiently in real time for hundreds or thousands of objects
A good place to start is to simulate a single particle bouncing around in a 2-dimensional box under the influence of gravity. Then, give the particle a radius, add more of them, and calculate collisions between them. At that point, you have a basic physics engine that's enough to use for simple games.
发布评论
评论(3)
创建一个(强大的)物理引擎比乍看起来要复杂得多。诀窍是尽可能地伪造而不是计算准确的值。作为起点,这篇博客文章有一个很棒的内容介绍。我认为 Thomas Jakobsen 的这篇论文也值得一读,并介绍了某些概念。 此博客还有一些有趣的文章,解释了集成器的详细信息以及如何管理在线游戏的物理。
查看 Box2D 等物理引擎的源代码是了解实现的好主意,但如果您不知道它们正在做什么的理论,它可能会让人感到困惑。这样做的原因是因为该理论通常效率太低而无法在实时游戏中实现,因此需要使用算法和技术来在真实性和速度之间取得平衡。
如果您要创建自己的物理引擎,因为您想在商业游戏中使用它,我建议您选择现有的解决方案。 (例如,《愤怒的小鸟》使用 Box2D)。然而,如果您这样做是为了体验和学习物理引擎,那么它肯定会教会您很多有关效率和智能技术的知识。
Creating a (robust) physics engine is a lot more complicated then it may seem at first. The trick is to fake as much as possible rather than calculate the exact values. As a starting point, this blog post has a great introduction. I think this paper by Thomas Jakobsen is also a good read and introduces certain concepts. This blog also has a few interesting articles explaining the details of integrators and how to manage physics for online games.
Going through the source code of physics engines such as Box2D is a good idea to see implementation, but if you don't know the theory of what they're doing, it can come across as confusing. The reason for this is because of the fact that the theory is often too inefficient to implement in a real time game and so algorithms and techniques are used to strike a balance between realism and speed.
If you're creating your own physics engine because you want to use it in a commercial game, I'd suggest choosing an already existing solution instead. (For example, Angry Birds uses Box2D). However, if you're doing it for the experience and for learning about physics engines, it's certainly something that'll teach you quite a bit about efficiency and smart techniques.
原则上,所有物理引擎都只是牛顿第二运动定律的直接应用:
加速度=力/质量
通过对加速度随时间的积分,您可以得到速度。通过对速度进行积分,您可以得到物体在空间中的位置。使用诸如龙格-库塔之类的方法以数字方式执行积分。
主要的复杂性来自:
一个好的起点是模拟单个粒子在重力影响下在二维盒子中弹跳。然后,给粒子一个半径,添加更多粒子,并计算它们之间的碰撞。那时,您就有了一个足以用于简单游戏的基本物理引擎。
In principle, all physics engines are simply a direct application of Newton's second law of motion:
acceleration = force / mass
By integrating acceleration over time, you get velocity. By integrating velocity, you get the positions of the object in space. The integrals are performed numerically, using something like Runge-Kutta.
The main complications arise from:
A good place to start is to simulate a single particle bouncing around in a 2-dimensional box under the influence of gravity. Then, give the particle a radius, add more of them, and calculate collisions between them. At that point, you have a basic physics engine that's enough to use for simple games.
看看其中的来源怎么样。这就是我要开始的地方。
http://www.tokamakphysicals.com/
How about looking through the source of one. That's where I would start.
http://www.tokamakphysics.com/