gpt4 book ai didi

c++ - 使用 Libnoise 生成高度图

转载 作者:行者123 更新时间:2023-11-30 03:56:00 26 4
gpt4 key购买 nike

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

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

一切似乎都工作正常,构建成功,程序运行完成,但无论我做什么输出位图文件,“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");
}

最佳答案

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

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

但是您实际上从未调用过writer 的函数来写入图像数据。我实际上无法从他们的文档中找到该类或函数名称应该是什么。但我很确定您可以轻松解决这个问题。

关于c++ - 使用 Libnoise 生成高度图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28723220/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com