使用Libnoise生成高度图

时间:2015-02-25 15:42:16

标签: c++ eclipse terrain perlin-noise

我正在尝试实现libnoise库并生成一个高度图,然后我可以将其导入L3DT以使用Perlin噪声算法渲染基本的3D地形。这是我作为计算机科学本科的最后一年项目。该主题主要是针对地形生成的程序内容生成。

我已正确设置Eclipse CDT并链接所有必需的头文件和库。该程序与libnoise教程系列中描述的完全相同,特别是我将在此处链接的第三个教程: http://libnoise.sourceforge.net/tutorials/tutorial3.html

一切似乎工作正常,构建成功,程序运行完成,但无论我做什么输出Bitmap文件,“output.bmp”都不会呈现在可执行文件的目录中。

我在这里缺少什么?输出文件是否放在默认目录中的其他位置?

以下是进一步澄清的代码:

  /*
  * 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");
}

1 个答案:

答案 0 :(得分:2)

在以下代码行中,您使用图像数据和文件名设置了utils::WriterBMP实例

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

但是你实际上从未调用writer函数来编写图像数据。我实际上无法从他们的文档中找到该类或函数名称。但我很确定你能轻易解决这个问题。