C# 2d 游戏物理资源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/165404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:24:07  来源:igfitidea点击:

Resources for 2d game physics

c#f#2dphysics

提问by Erik Forbes

I'm looking for some good references for learning how to model 2d physics in games. I am notlooking for a library to do it for me - I want to think and learn, not blindly use someone else's work.

我正在寻找一些很好的参考资料来学习如何在游戏中建模 2d 物理。我不是在寻找一个图书馆来为我做这件事——我想思考和学习,而不是盲目地使用别人的作品。

I've done a good bit of Googling, and while I've found a few tutorials on GameDev, etc., I find their tutorials hard to understand because they are either written poorly, or assume a level of mathematical understanding that I don't yet possess.

我已经做了很多谷歌搜索,虽然我在 GameDev 等上找到了一些教程,但我发现他们的教程很难理解,因为它们要么写得不好,要么假设我对数学有一定程度的理解还没有拥有。

For specifics - I'm looking for how to model a top-down 2d game, sort of like a tank combat game - and I want to accurately model (among other things) acceleration and speed, heat buildup of 'components,' collisions between models and level boundaries, and missile-type weapons.

具体来说 - 我正在寻找如何建模自上而下的 2d 游戏,有点像坦克战斗游戏 - 我想准确地建模(除其他外)加速度和速度,“组件”的热量积聚,之间的碰撞模型和关卡边界,以及导弹类武器。

Websites, recommended books, blogs, code examples - all are welcome if they will aid understanding. I'm considering using C# and F# to build my game, so code examples in either of those languages would be great - but don't let language stop you from posting a good link. =)

网站、推荐书籍、博客、代码示例 - 如果它们有助于理解,我们都欢迎。我正在考虑使用 C# 和 F# 来构建我的游戏,所以这两种语言中的任何一种的代码示例都会很棒 - 但不要让语言阻止您发布一个好的链接。=)

Edit: I don't mean that I don't understand math - it's more the case that I don't know what I need to know in order to understand the systems involved, and don't really know how to find the resources that will teach me in an understandable way.

编辑:我并不是说我不懂数学——更多的情况是我不知道为了理解所涉及的系统我需要知道什么,并且不知道如何找到需要的资源会以一种可以理解的方式教我。

采纳答案by mistrmark

Here are some resources I assembled a few years ago. Of note is the Verlet Integration. I am also including links to some open source and commercial physics engines I found at that time. There is a stackoverflow article on this subject here: 2d game physics?

这是我几年前收集的一些资源。值得注意的是 Verlet 集成。我还包括了我当时发现的一些开源和商业物理引擎的链接。这里有一篇关于这个主题的 stackoverflow 文章:2d 游戏物理?

Physics Methods

物理方法

Books

图书

  • "Game Physics Engine Development", Ian Millington -- I own this book and highly recommend it. The book builds a physics engine in C++ from scratch. The Author starts with basic particle physics and then adds "laws of motion", constraints, rigid-body physics and on and on. He includes well documented source code all the way through.
  • “游戏物理引擎开发”,伊恩米林顿——我拥有这本书并强烈推荐它。这本书从头开始用 C++ 构建了一个物理引擎。作者从基本粒子物理学开始,然后添加“运动定律”、约束、刚体物理学等等。他从头到尾都包含有据可查的源代码。

Physics Engines

物理引擎

回答by David Koelle

回答by Chris Smith

F# has a feature called Units of Measurewhich does dimensional analysis for you, providing errors if you get it wrong. For example if you say:

F# 有一个叫做Units of Measure的功能它为你做维度分析,如果你弄错了,就会提供错误。例如,如果你说:

let distance : float<meters> = gravity * 3.0<seconds>

That would yield a compile-error, since gravity is < meters/seconds^2 > and not < meters >. Also, since F# is just .NET you can write your math/physics code in a class library and reference that from your C#.

这会产生编译错误,因为重力是<米/秒^2>而不是<米>。此外,由于 F# 只是 .NET,您可以在类库中编写数学/物理代码,并从 C# 中引用该代码。

I'd reccomend you check out these blog posts for more information:

我建议您查看这些博客文章以获取更多信息:

回答by angelo

This is a great tutorial that demonstrates 2D physics concepts using flash and is not specific to flash. http://www.rodedev.com/tutorials/gamephysics/game_physics.swf

这是一个很棒的教程,它使用 Flash 演示了 2D 物理概念,而不是特定于 Flash。 http://www.rodedev.com/tutorials/gamephysics/game_physics.swf

回答by DavidG

This is a great resourcefor writing your first engine. It's in 3D but it's very easy to convert down to 2D. I know at least one big company that followed this tutorial for their internal engine, and i personally have followed his steps for my own engine. He explains all the basic physics concepts in spring/impulse based physics, and shows you how to write your own intergrater.

这是编写您的第一个引擎的绝佳资源。它是 3D 的,但很容易转换为 2D。我知道至少有一家大公司在他们的内部引擎上遵循了本教程,我个人也遵循了他的步骤来开发我自己的引擎。他解释了基于弹簧/脉冲的物理中的所有基本物理概念,并向您展示了如何编写自己的积分器。

回答by James

Even if you want to learn it all from the bottom up, an open source physics library that is well coded and documented contains far more information than a book. How do I deal with situation x... find in files can be faster than a paper index.

即使您想自下而上地学习这一切,编码和记录良好的开源物理库包含的信息也比书多得多。我如何处理情况 x... 在文件中查找可能比文件索引更快。

Original response:

原回复:

What, no mention of Box2D? Its an open source side project of a blizzard employee, has a good community, and well, works great.

什么,没有提到Box2D?它是暴雪员工的一个开源项目,有一个很好的社区,而且效果很好。

In my (brief) experience with Box2D, integrating it with Torque Game Builder, I found the API clean to use, documentation was clear, it supported all the physics objects I expected (joints in particular were a requirement), and the community looked friendly and active (sometime around early 2010).

在我使用 Box2D 的(简短)体验中,将其与 Torque Game Builder 集成,我发现 API 易于使用,文档清晰,它支持我期望的所有物理对象(特别是关节是必需的),并且社区看起来很友好并且活跃(大约在 2010 年初的某个时候)。

Judging by forum posters, it also appeared that managers were receptive to source contributions (that did not carry license baggage).

从论坛海报来看,管理人员似乎也愿意接受来源贡献(不携带许可证包袱)。

It's island based solver seemed quite fast, as I expected from its reputation, not that I did any major performance testing.

它的基于岛的求解器似乎非常快,正如我对它的声誉所期望的那样,而不是我进行了任何主要的性能测试。

回答by Jon Harrop

The F#.NET Journalhas published two articles about this:

F#.NET 杂志发表了两篇关于此的文章:

回答by epaik

Speaking from experience, implementing a 2D physics engine is pretty difficult. I'll detail the several steps I took when creating my engine.

从经验上讲,实现 2D 物理引擎非常困难。我将详细介绍我在创建引擎时所采取的几个步骤。

  1. Collision detection. Collision detection can be a difficult problem, even when you're not dealing with 3D worlds or networked simulations. For 2D physics, you definitely want to use the Separating Axis Theorem. Once you've implement SAT, you're half-way done making the dynamics portion of your engine.

  2. Kinematics/Dynamics. Chris Hecker has written an excellent online resourcewhich walked me through collision response step-by-step.

  3. Everything Else. Once you've got the collision detection/response finished, its a matter of implementing everything else you want in the engine. This can include friction, contact forces, joints, along with whatever else you can think of.

  1. 碰撞检测。即使您不处理 3D 世界或网络模拟,碰撞检测也可能是一个难题。对于 2D 物理,您肯定要使用分离轴定理。一旦你实施了 SAT,你就完成了引擎的动力学部分的制作。

  2. 运动学/动力学。Chris Hecker 写了一个很好的在线资源,它引导我一步一步地完成碰撞响应。

  3. 其他一切。一旦您完成了碰撞检测/响应,就需要在引擎中实现您想要的所有其他内容。这可以包括摩擦力、接触力、关节以及您能想到的任何其他因素。

Have fun! Creating your own physics simulation is an incredibly rewarding experience.

玩得开心!创建自己的物理模拟是一种非常有益的体验。