简体   繁体   English

如何将Perlin杂讯功能(libnoise)映射到图块阵列?

[英]How do I map a perlin noise function (libnoise) to an array of tiles?

The Perlin.GetValue(x, y, z) method of libnoise (using the C# port) returns 0's if the input values are integers. 如果输入值是整数,则libnoise的Perlin.GetValue(x,y,z)方法(使用C#端口)将返回0。 How could I go about mapping a 2D array of tiles--as the indices of an array are integers--to the values of the noise? 我如何才能将2D瓦片数组(由于数组的索引是整数)映射到噪声值? This makes little sense to me as even 3D terrain eventually rests upon whole integer values. 这对我来说意义不大,因为即使3D地形最终也取决于整个整数值。 For those who are generating such 3D landscapes, are these positions in the terrain always restrained to being a value of 0? 对于生成此类3D风景的人来说,地形中的这些位置是否始终限制为0值?

EDIT: I should mention that I am using a chunk system, so I loop through each chunk's [32, 32] array of tiles to get the Perlin noise values. 编辑:我应该提到我正在使用一个块系统,因此我遍历每个块的[32,32]瓦片数组以获取Perlin噪声值。 I was hoping that by adding the offset of the chunk in world space to the [x, y] value of the tile in the array I could have continuous terrain. 我希望通过将世界空间中块的偏移量添加到数组中图块的[x,y]值中,可以得到连续的地形。 Regardless, I tried something like this and still got zero from the noise function: 无论如何,我尝试了类似的方法,但噪声函数仍然为零:

double temp = generator.GetValue((x + offsetX) / ChunkSize, (y + offsetY) / ChunkSize, 0);

EDIT 2: I output the values of the noise functions to 32x32 textures and put them next to each other. 编辑2:我将噪波函数的值输出为32x32纹理,并将它们彼此相邻放置。 Noise is being produced but it isn't continuous despite adjusting the input of the x and y values for the offset of the chunk. 产生了噪声,但尽管为块的偏移调整了x和y值的输入,但它不是连续的。

在此处输入图片说明

EDIT 3: Problem solved. 编辑3:问题解决了。 My offset values were set to pixel coordinates instead of tile/chunk coordinates. 我的偏移值设置为像素坐标,而不是平铺/块坐标。 I was multiplying the index of the chunk by the chunk size times the tile size instead of just the chunk size (which is in tiles). 我将块的索引乘以块大小乘以图块大小,而不仅仅是块大小(在图块中)。

Perlin.GetValue(x, y, z)的输入值是双精度值,并且在技术上不限于0.0-1.0范围,但是我建议您采用所有数组索引并将它们除以该维度中的数组长度,以便都落在0.0-1.0的范围内,您应该得到不错的噪声值,如果噪声太大,则可以通过缩放来调整噪声,例如,如果索引在0.0到2.0之间缩放可能会产生更平滑的噪声。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM