简体   繁体   English

使用Libnoise生成高度图

[英]Using Libnoise to generate a heightmap

I am attempting to implement the libnoise libraries and generate a heightmap which I can then import into L3DT to render a basic 3D terrain using the Perlin noise algorithm. 我试图实现libnoise库并生成一个高度图,然后可以将其导入L3DT以使用Perlin噪声算法来渲染基本3D地形。 This is my final year project as an undergrad in computer science. 这是我作为计算机科学本科生的最后一年的项目。 The topic is essentially Procedural Content Generation focusing on Terrain Generation. 主题本质上是关注地形生成的过程内容生成。

I've set up my Eclipse CDT properly and linked all the necessary header files and libraries. 我已经正确设置了Eclipse CDT,并链接了所有必需的头文件和库。 The program is exactly as described on the libnoise tutorial series, in particular the third tutorial which I shall link here: http://libnoise.sourceforge.net/tutorials/tutorial3.html 该程序与libnoise教程系列完全相同,特别是我将在此处链接的第三个教程: http : //libnoise.sourceforge.net/tutorials/tutorial3.html

Everything seems to be working fine, the build is successful, the program runs to completion, but no matter what I do the output Bitmap file, "output.bmp" is not rendered in the directory of the executable. 一切似乎都工作正常,构建成功,程序运行完成,但是无论我做什么输出位图文件,“ output.bmp”都不会呈现在可执行文件的目录中。

What am I missing here? 我在这里想念什么? Is the output file placed somewhere else in a default directory? 输出文件是否放置在默认目录中的其他位置?

Here is the code for further clarification: 以下是进一步说明的代码:

  /*
  * Noise.cpp
  *
  *  Created on: 23-Feb-2015
  *    
  */

  #include <iostream>
  #include <stdio.h>
  #include <noise.h>
  #include <noiseutils.h>

  using namespace noise; // Sets reference for usage of the the noise class objects
  using namespace std;
  void main()
  {
        // CREATION OF THE NOISE MAP

        module::Perlin Module; // Instantiates the Perlin class object to be used as the source for the noise generation.
        utils::NoiseMap heightMap; // Creation of the 2D empty noise map.
        utils::NoiseMapBuilderPlane heightMapBuilder; // Used to fill the noise map with the noise values taken from an (x,y) plane.

        heightMapBuilder.SetSourceModule (Module); // Sets the Perlin module as the source for noise generation.
        heightMapBuilder.SetDestNoiseMap (heightMap); // Sets the empty noise map as the target for the output of the planar noise map builder.

        heightMapBuilder.SetDestSize(256,256); // Sets the size of the output noise map.

        heightMapBuilder.SetBounds (2.0, 6.0, 1.0, 5.0); // Defines the vertices of the bounding rectangle from which the noise values are produced. lower x, upper x, lower y, upper y.

        heightMapBuilder.Build (); // Builds the noise map.

// RENDERING THE TERRAIN HEIGHT MAP

        utils::RendererImage renderer;
        utils::Image image;
        renderer.SetSourceNoiseMap(heightMap);
        renderer.SetDestImage(image);
        renderer.Render();
// WRITING THE HEIGHT MAP IMAGE TO AN OUTPUT FILE

        utils::WriterBMP writer;
        writer.SetSourceImage(image);
        writer.SetDestFilename("output.bmp");

        system("pause");
}

In the following lines of code you setup a utils::WriterBMP instance with the image data and a file name 在以下代码行中,设置带有图像数据和文件名的utils::WriterBMP实例

    utils::WriterBMP writer;
    writer.SetSourceImage(image);
    writer.SetDestFilename("output.bmp");

But you never actually call a function of writer to write the image data. 但是,您实际上从未调用过writer函数来写入图像数据。 I can't actually find that class or what the function name should be from their documentation. 我实际上不能从他们的文档中找到该类或函数名称。 But I'm pretty sure you can figure this out easily. 但我敢肯定,您可以轻松解决此问题。

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

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