Unity3d 浮点精度限制 [英] Unity3d floating point precision limitations

查看:255
本文介绍了Unity3d 浮点精度限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到来自 Unity3D Pro 的警告,我不太明白.我在 GUI 中将我的玩家的 Transform.position.x 设置为 1000000,它给了我这个警告:

I got a warning from Unity3D Pro that I don't quite understand. I set my player's Transform.position.x to 1000000 in the GUI and it gave me this warning:

由于浮点精度限制,建议将GameObject的世界坐标缩小到一个较小的范围内."

"Due to floating-point precision limitations, it is recommended to bring the world coordinates of the GameObject within a smaller range."

这是否意味着我的单个场景必须小于 1000000*1000000*1000000.这被认为足够大吗?如果我想要更大的世界,我需要多个场景吗?加载新场景时,我的播放器位置会重置吗?如何管理位置数据,使其不超出范围?

Does that mean that my single scene has to be smaller than 1000000*1000000*1000000. Is this considered big enough? I will need multiple scenes if I want a larger world? When a new scene gets loaded, will my player's position be reseted? How do I manage the position data so that it doesn't go out of range?

推荐答案

对于数量级为 1,000,000 的数字,IEEE-754 32 位二进制浮点数的步长为 1/16 (.0625).所以下一个可表示的 1,000,000 以上的数字是 1,000,000.0625.

For numbers of magnitude 1,000,000, the step size of IEEE-754 32-bit binary floating-point is 1/16 (.0625). So the next number above 1,000,000 that is representable is 1,000,000.0625.

如果您的视图中肉眼看不到 0.0625 的变化,那可能没问题.如果您的世界中物体的比例使得 0.0625 比任何物体特征都小得多,并且视图永远不会放大到人眼可以注意到的 0.0625 差异,那么可能没有问题.(但是,您可能需要更多的余地.即使该大小的对象特征不可见,某些数学计算也可能会受到影响,因为速度、位置等的任何计算都不能使用小于 0.0625 的增量,而您正在对数量级为 1,000,000 的数字进行 32 位算术运算.)

That might be fine if you have a view where changes of .0625 are not visible to the eye. If the scale of the objects in your world is such that .0625 is much smaller than any object feature, and the view will never zoom in to where differences of .0625 are noticeable to the human eye, then there may be no problem. (However, you may want a little more leeway. Even if object features of that size are not visible, some of the math may be affected, since any calculations of velocity, position, et cetera, cannot use increments smaller than .0625 while you are doing 32-bit arithmetic on numbers of magnitude 1,000,000.)

将其与原点附近的数字进行比较,例如数量级为 100 的数字.在 100 处,步长为 1/131072 (.00000762939453125).如果您正在绘制利用这种精细分辨率的对象,只要它们靠近原点,它们就会看起来很好.但是,当它们在您的场景中移动到坐标具有较大量级的位置时,它们会失去分辨率.

Compare that to numbers near the origin, say numbers of magnitude 100. At 100, the step size is 1/131072 (.00000762939453125). If you are drawing objects that take advantage of this fine resolution, they will look fine as long as they are near the origin. However, when they move through your scene to places where the coordinates have larger magnitude, they lose resolution.

这里的基本问题是场景的大小与场景中细节的大小之间的比例.这就是有限的.只要对象特征也很大,您就可以拥有大坐标.但是当坐标很大时,你无法保持精细的对象特征.

The basic problem here is the ratio between the size of the scene and the size of the details in the scene. That is what is limited. You can have large coordinates as long as the object features are also large. But you cannot maintain fine object features while the coordinates are large.

这篇关于Unity3d 浮点精度限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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