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

查看:216
本文介绍了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.

如果您看不到.0625的变化,那可能很好.如果您的世界中的对象的比例大到.0625比任何对象特征都小得多,并且视图无法放大到人眼可察觉到的.0625的差异,那么可能没有问题. (但是,您可能需要更多的余地.即使看不到该大小的对象特征,某些数学也可能会受到影响,因为在计算速度,位置等时,任何计算都不能使用小于.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天全站免登陆