我一直在寻找在 XNA 中产生噪音的库。Libnoise 似乎是最合乎逻辑的选择。该库非常易于使用并产生了一些很好的结果。不过,我在生成其他部分时遇到了一些麻烦。C++ 文档对此有一个非常好的功能:
utils::NoiseMap heightMap;
utils::NoiseMapBuilderPlane heightMapBuilder;
heightMapBuilder.SetSourceModule (myModule);
heightMapBuilder.SetDestNoiseMap (heightMap);
heightMapBuilder.SetDestSize (256, 256);
heightMapBuilder.SetBounds (6.0, 10.0, 1.0, 5.0); //this one!
heightMapBuilder.Build ();
//http://libnoise.sourceforge.net/tutorials/tutorial3.html
XNA 版本不是这样工作的,而是使用 translate 函数在生成的高度图中“移动”。
翻译.cs
/// <summary>
/// Initializes a new instance of Translate.
/// </summary>
/// <param name="x">The translation on the x-axis.</param>
/// <param name="y">The translation on the y-axis.</param>
/// <param name="z">The translation on the z-axis.</param>
/// <param name="input">The input module.</param>
public Translate(double x, double y, double z, ModuleBase input)
: base(1)
{
this.m_modules[0] = input;
this.X = x;
this.Y = y;
this.Z = z;
}
用法
perlin = new Perlin(zoom, 4, 0.2, 4, 1, QualityMode.Medium);
Translate translate = new Translate(location.X, location.Y, 0, perlin);
this.m_noiseMap = new Noise2D(200, 200, translate);
this.m_noiseMap.GeneratePlanar(-1 * zoom, 1 * zoom, -1 * zoom, 1 * zoom, true);
这就是问题所在;虽然它确实翻译了高度图,但它也扭曲了它。这看起来很奇怪,因为 perlin 保持不变。我可以想象改变 Z 会导致高度图改变,但我只是改变 X 轴。
对此有任何想法吗?