blob: a44d0d327aaeacf9870a604877011ed85f89067e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include "terrain.h"
#include <noise/noise.h>
#include "noiseutils/noiseutils.h"
#include <iostream>
using namespace noise;
float *Terrain::generate_heights(int x, int y, int width, int height) {
module::Perlin mod;
mod.SetSeed(0);
utils::NoiseMap heightmap;
utils::NoiseMapBuilderPlane heightmap_builder;
heightmap_builder.SetSourceModule(mod);
heightmap_builder.SetDestNoiseMap(heightmap);
heightmap_builder.SetDestSize(width, height);
heightmap_builder.SetBounds(x / 100, (x+width) / 100, y / 100, (y+height) / 100);
heightmap_builder.Build();
float *heights = new float[width*height];
for(int i = 0; i < width; i++) {
for(int j = 0; j < height; j++) {
heights[i*height + j] = 10*(1+heightmap.GetValue(i, j));
}
}
return heights;
}
|