#include "terrain.h" #include #include "noiseutils/noiseutils.h" #include 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((double)x / 100, (double)(x+width) / 100, (double)y / 100, (double)(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)); } } chunk_indices.insert(std::pair(x, y)); return heights; } float *Terrain::get_chunk(int x, int y, int width, int height) { return generate_heights(x, y, width, height); } bool Terrain::has_chunk(int x, int y) { return chunk_indices.find(std::pair(x, y)) != chunk_indices.end(); }