物理引擎实际上是如何模拟物理的?

发布于 2024-11-14 12:49:19 字数 1436 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情域 2024-11-21 12:49:19

创建一个(强大的)物理引擎比乍看起来要复杂得多。诀窍是尽可能地伪造而不是计算准确的值。作为起点,这篇博客文章有一个很棒的内容介绍。我认为 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.

傻比既视感 2024-11-21 12:49:19

原则上,所有物理引擎都只是牛顿第二运动定律的直接应用:

加速度=力/质量

通过对加速度随时间的积分,您可以得到速度。通过对速度进行积分,您可以得到物体在空间中的位置。使用诸如龙格-库塔之类的方法以数字方式执行积分。

主要的复杂性来自:

  • 处理旋转运动
  • 处理脉冲事件,例如碰撞和爆炸
  • 检测速度极端处的碰撞。在高速行驶时,物体最终可能会在检测到碰撞之前穿透甚至穿过彼此。低速时,要稳健地处理一个放在另一个物体上的物体而不在
  • 运动连杆上抖动或滑动是一项挑战,其中物体部分地相互约束(如铰链或滑块)
  • 计算汽车等复杂物体的力和扭矩对
  • 成百上千个物体实时有效地完成所有这些工作

一个好的起点是模拟单个粒子在重力影响下在二维盒子中弹跳。然后,给粒子一个半径,添加更多粒子,并计算它们之间的碰撞。那时,您就有了一个足以用于简单游戏的基本物理引擎。

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.

述情 2024-11-21 12:49:19

看看其中的来源怎么样。这就是我要开始的地方。

http://www.tokamakphysicals.com/

How about looking through the source of one. That's where I would start.

http://www.tokamakphysics.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文