先知米/像素比 [英] Farseer Meter/Pixel Ratio

查看:206
本文介绍了先知米/像素比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了很多在C ++ Box2D的,和我给C#一试。它看起来像先知代替的Box2D的一般使用(我知道Box2DXNA,但它似乎有点过时了。)所以,先知是我一直使用的是什么。当我使用C ++和Box2D的,大家总是建议不要使用1pixel /米比(什么原因,我也不知道,),通常采用左右30pixels /米的地方建议。正如我一直在研究先知,我已经看到了很多相互矛盾的陈述。有人说用1pixel /米,有人说用一个尺度,别人说用ConvertUnits.ToSimUnits和ConvertUnits.ToDisplayUnits等。

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.

所以,我应该怎么用?现在,我使用ConvertUnits,但一切都在奇怪的地方呈现。是否有一个事实上的标准或任何东西,我应该去的?先谢谢了。

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.

推荐答案

先知3.x的是基于Box2D的。和Box2D的常见问题解答说

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

Box2D中被调整为米 - 千克 - 秒(MKS)。您的移动物体应为0.1之间 - 米10。不要使用像素为单位!你会得到一个非常敏感的模拟。

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.

在换句话说,假设一个正常的物理世界,你应该有 1物理单位=1米。但是,这将导致大部分的移动物体的是在0.1到10个单位范围内的任何规模应该没问题。

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.

这是通常做的方法是在使用摄像头或查看矩阵(在渲染时间标准的世界/视点/投影系统)。这两个地方,你可以做到这一点是 BasicEffect.View MSDN ),或者转换矩阵参数 SpriteBatch.Begin MSDN ,的又见的)。

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).

海事组织,先知 ConvertUnits 类是处理转换非常丑陋的方式。

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

这篇关于先知米/像素比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆