Farseer 仪表/像素比

发布于 2024-12-09 11:26:38 字数 377 浏览 0 评论 0原文

我在 C++ 中使用 box2d 做了很多工作,并且正在尝试 C#。看起来Farseer通常用来代替Box2D(我知道Box2DXNA,但它似乎有点过时了。)所以,Farseer是我一直在使用的。当我使用 C++ 和 Box2D 时,大家总是建议不要使用 1 像素/米的比例(出于什么原因,我不知道),通常建议使用 30 像素/米左右的比例。当我研究 Farseer 时,我看到了很多相互矛盾的说法。有人说使用 1pixel/meter,有人说使用比例,有人说使用 ConvertUnits.ToSimUnits 和 ConvertUnits.ToDisplayUnits 等。

那么我应该使用什么呢?现在,我正在使用 ConvertUnits,但所有内容都呈现在奇怪的地方。是否有事实上的标准或我应该遵循的标准?提前致谢。

I've done a lot with box2d in c++, and am giving C# a try. It looks like Farseer is generally used in place of Box2D (I'm aware of Box2DXNA, but it seems a little outdated.) So, Farseer is what I've been using. When I was using C++ and Box2D, everyone always advised against using a 1pixel/meter ratio (For what reason, I don't know,) and usually suggested using somewhere around 30pixels/meter. As I've been researching Farseer, I've seen a lot of conflicting statements. Some say to use 1pixel/meter, others say to use a scale, others say to use ConvertUnits.ToSimUnits and ConvertUnits.ToDisplayUnits, etc.

So what should I use? Right now, I'm using ConvertUnits, but everything renders in weird places. Is there a de-facto standard or anything that I should go by? Thanks in advance.

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

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

发布评论

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

评论(2

断爱 2024-12-16 11:26:38

Farseer 3.x 基于 Box2D。 Box2D 常见问题解答说明

Box2D 针对米-千克-秒 (MKS) 进行了调整。移动物体的距离应在 0.1 - 10 米之间。不要使用像素作为单位!您将得到一个令人紧张的模拟。

换句话说,假设有一个“正常”物理世界,您可能应该有 1 个物理单位 = 1m。但任何使大多数移动对象处于 0.1 到 10 单位范围内的比例都应该没问题。

假设您正在制作汽车模型。一个非常非常简单的模型,恰好是一个矩形。您可以使用以下内容创建它:

float width = 4.1f; // average car length in meters
float height = 1.4f; // average car height in meters
// Note: this method takes half-sizes:
var carVertices = PolygonTools.CreateRectangle(width / 2f, height / 2f);
// Then pass carVertices into PolygonShape, etc...

另一个问题是如何以正确的尺寸渲染您的世界。

通常完成此操作的方式是在渲染时使用相机或视图矩阵(在标准世界/视图/投影系统中)。您可以执行此操作的两个位置是 BasicEffect.View (MSDN),或 SpriteBatch.Begin 的变换矩阵参数 (MSDN另请参阅)。

在我看来,Farseer ConvertUnits 类是一种非常丑陋的处理转换的方式。

Farseer 3.x is based on Box2D. And the Box2D FAQ says:

Box2D is tuned for meters-kilograms-seconds (MKS). Your moving objects should be between 0.1 - 10 meters. Do not use pixels as units! You will get a jittery simulation.

In other words, assuming a "normal" physics world, you should probably have 1 physics unit = 1m. But any scale that causes the majority of your moving objects to be in the 0.1 to 10 unit range should be ok.

So, say you're making a model of a car. A really, really simple model that happens to be a rectangle. You'd create it using something like:

float width = 4.1f; // average car length in meters
float height = 1.4f; // average car height in meters
// Note: this method takes half-sizes:
var carVertices = PolygonTools.CreateRectangle(width / 2f, height / 2f);
// Then pass carVertices into PolygonShape, etc...

The separate problem is how to then render your world at the correct size.

The way this is generally done is at render time using a camera or view matrix (in the standard world/view/projection system). The two places you could do this are BasicEffect.View (MSDN), or the transformation matrix parameter to SpriteBatch.Begin (MSDN, see also).

IMO, the Farseer ConvertUnits class is a very ugly way of handling the conversion.

云仙小弟 2024-12-16 11:26:38

我使用 int MetersPixel = 64;对于我所有的基本计算。所以我有一些小敌人,他们的纹理是 16px 宽。因此,当使用 Farseer 创建它们的身体时,宽度为 0.25。

16 / 64 = 0.25

最重要的是,感觉、尺寸/比例和重量适合我当前的游戏,我不相信有任何黄金法则或理由为什么你应该为了让你的代码 10 = 1 等而跳圈。

到目前为止它对我来说工作得很好。我从来没有想过尝试将 10px 转换为 1m,但就我当前的游戏构建而言,我认为这没有用。

I use int MetersPixel = 64; for all my base calcs. So i have little enemys that their textures are 16px wide. So when creating their bodys with Farseer the width is 0.25.

16 / 64 = 0.25

Most importantly the feel, size / scale and weight is right for my current game, i dont believe there is any golden rule or reason why you should have to jump through hoops just to make your code 10 = 1 etc.

Its working perfectly for me so far. I never thought to try convert 10px to 1m but with my current game build i would not see that as useful.

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