简体   繁体   English

Libnoise XNA翻译Perlin导致变形

[英]Libnoise XNA translate perlin causes distortion

I've been looking at libraries to generate noise in XNA. 我一直在寻找在XNA中产生噪声的库。 Libnoise seemed like the most logical choice. Libnoise似乎是最合乎逻辑的选择。 The library is pretty easy to work and produces some great results. 该库非常易于使用,并产生了一些不错的结果。 I'm having some trouble with generating additional sections though. 我在生成其他部分时遇到了一些麻烦。 The C++ documentation has a really nice function for this: 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

The XNA version doesn't work like this, and instead uses a translate function to "move" through the generated heightmap. XNA版本无法像这样工作,而是使用转换功能来“移动”生成的高度图。

Translate.cs 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;
    }

Usage 用法

        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);

Here is where the problem kicks in ; 这是问题的根源 ; while it does translate the heightmap, it also distorts it. 虽然它确实可以转换高度图,但也会扭曲高度图。 Which seems strange, because the perlin remains unmodified. 这似乎很奇怪,因为Perlin保持不变。 I could have imagined changing the Z would cause the heightmap to change, but I'm only altering the X axis. 我可以想象改变Z会导致高度图发生变化,但是我只改变X轴。

在此处输入图片说明

Any idea on this? 有什么想法吗?

It looks like the main issue is what dimensions the heightmap is using to produce the results. 看起来主要问题是高度图用于生成结果的尺寸。

So, it's very vague as to what dimensions the heightmap builder is using as the elevation, especially after applying a projection... 因此,高度图生成器将什么尺寸用作高程非常模糊,尤其是在应用投影之后...

It seems to me that X is controlling elevation (if you look at the ocean, it looks like you're literally raising the sea level). 在我看来,X正在控制海拔高度(如果您看着海洋,就好像您实际上是在抬高海平面)。 While this might not make much sense, it might be good to check the source and see what dimensions its actually using. 尽管这可能没有多大意义,但最好检查源并查看其实际使用的尺寸。 3D noise like this generally doesnt care which dimensions is which, as long as you make it cohere with your application. 只要使3D噪声与您的应用程序保持一致,这样的3D噪声通常不会在乎哪个尺寸。

I know this is an old thread, and I don't know what the translate is but I don't think you need it to generate different tiles. 我知道这是一个旧线程,我不知道翻译是什么,但我认为您不需要它来生成不同的图块。

Just use GeneratePlanar() function to offset the tile by X and Y units, and also make it relative to the zoom, so if you are zooming by 0.5, you move the offsets by factors of 0.5 for adjacent tiles 只需使用GeneratePlanar()函数将图块偏移X和Y单位,并使其相对于缩放即可,因此,如果按0.5缩放比例,则将相邻图块的偏移量移动0.5倍

public void GeneratePlanar(double left, double right, double top, double bottom, bool seamless) public void GeneratePlanar(左向左,右向右,双顶,双底,布尔无缝)

        // Initialize the noise map
        this.m_noiseMap = new Noise2D(resolution, resolution, moduleBase);
        this.m_noiseMap.GeneratePlanar(
        offsetX + 0 * 1/zoom, 
        offsetX + 1 * 1/zoom, 
        offsetY + 0 * 1/zoom,
        offsetY + 1 * 1/zoom);

I don't know about libnoise xna, but normal libnoise uses X and Z for the 2d height map. 我不了解libnoise xna,但普通的libnoise将X和Z用于2d高度图。 So you should translate X and Z instead of X and Y. 因此,您应该翻译X和Z而不是X和Y。

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

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