从像素到米的比率是多少?
我使用以下比率进行像素到米的转换,
PTM_RATIO=32;
v3BodyDef.position.Set(2848/PTM_RATIO, 102/PTM_RATIO);
这会在屏幕上多次产生奇怪的输出,所以设置位置(v3BodyDef.position.Set)是否采用浮点变量我不知道,但我认为这个转换带来麻烦。
请帮我解决这个问题。 谢谢。
I'm using following ratio for pixel to meter conversion,
PTM_RATIO=32;
v3BodyDef.position.Set(2848/PTM_RATIO, 102/PTM_RATIO);
This this produce weird output many times on the screen, so does setting position(v3BodyDef.position.Set) take floating point variable or not I don't know, but I think this conversion making trouble.
Please help me with this.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有一个值得推荐的比例(尽管有些人会尝试说服您存在)。
物理引擎中对象的比例应取决于动态对象的平均比例。我的意思是,如果您的玩家与许多比自身“稍大”和“稍小”的对象进行交互,那么最好使玩家的平均大小处于最佳范围内(例如,Box2D 针对介于大小为 0.1m 和 10m,因此将播放器设置为 1m,或 1.5m)。
至于像素大小,这完全取决于您希望屏幕上的世界有多大。
如果您希望英雄的高度为屏幕的 1/10,距离摄像机 2 米,那么请计算一下:-p 其他人可能希望他们的高度为屏幕的 1/8,或 1/12。这实际上取决于游戏最终的样子。如果相机放大,像素与物理的比率将会改变。如果屏幕分辨率发生变化(如视网膜显示屏),您的像素与物理比率将必须相应改变。
所以在实践中:没有设定值。这实际上取决于游戏,并且取决于您所使用的硬件的最佳感觉。
There isn't a recommendable ratio for that (though some will try and convince you there is).
The scale of objects in your physics engine should depend on the average scale of your dynamic objects. What I mean is, that if your player interacts with a lot of objects "slightly larger" and "slightly smaller" than itself, it's probably best to make player an average size in the optimal range (for example, Box2D is optimized for objects between 0.1m and 10m in size, so make player 1m, or 1.5m).
As for your pixel size, that all depends on how large you want your world to be on the screen.
If you want your hero to be 1/10th of the screen in height, and 2 meters away from the camera, then do the math :-p Others may want their here to be 1/8th of screen height, or 1/12th.. that really depends on how the game will look in the end. If the camera zooms in, the pixel to physics ratio would change. If the screen resolution changes (like a retina display), your pixel to physics ratio will have to change accordingly.
So in practice: there is no set value. It really depends on the game, and depends on what feels best for the hardware you're on.
这很可能是整数除法问题,请将 PTM_RATIO 更改为浮点数(或者如果您要定义它,请使用
#define PTM_RATIO 16.0f
)It's most likely an integer division problem, change PTM_RATIO to a float (or if you are defining it, use
#define PTM_RATIO 16.0f
)