X-Git-Url: http://git.mutantstargoat.com?p=demo;a=blobdiff_plain;f=src%2Fterrain.cc;h=92dce567c51eaa41640475577d3da023f08e574a;hp=bdd787fdd4e3b44eb2181997f79f54488e36d75a;hb=47982b199010496e34eefb95044275fb231cba18;hpb=243eb502c5dc70e586a9e81815234069bf623480 diff --git a/src/terrain.cc b/src/terrain.cc index bdd787f..92dce56 100644 --- a/src/terrain.cc +++ b/src/terrain.cc @@ -32,6 +32,12 @@ void Terrain::destroy() delete vis_scene; } +struct GenData { + const TerrainParams *tp; + float xoffs; + float yoffs; +}; + bool Terrain::generate(const TerrainParams ¶ms) { tiles.clear(); @@ -44,11 +50,22 @@ bool Terrain::generate(const TerrainParams ¶ms) TerrainTile tile; tile.mesh = gfx_create_mesh(); + GenData data; + data.tp = ¶ms; + data.xoffs = (float)j / (float)params.xtiles; + data.yoffs = (float)i / (float)params.ytiles; + gen_heightfield(tile.mesh, txsz, tysz, params.max_height, params.tile_usub, params.tile_vsub, calc_height, - (void*)¶ms); + (void*)&data); + + float xoffs = j * txsz - params.xsz / 2.0 + txsz / 2.0; + float yoffs = i * tysz - params.ysz / 2.0 + tysz / 2.0; + + Mat4 offmat; + offmat.translation(xoffs, 0, yoffs); + tile.mesh->transform(offmat); - tile.mesh->update_vertex_data(); tiles.push_back(tile); /* @@ -78,7 +95,15 @@ static float calc_height(float u, float v, void *ptr) return 0; } - TerrainParams *tp = (TerrainParams*)ptr; + GenData *data = (GenData*)ptr; + const TerrainParams *tp = data->tp; + + // float ufreq = tp->noise_freq / tp->xtiles; + // float vfreq = tp->noise_freq / tp->ytiles; + + u = u / tp->xtiles + data->xoffs; + v = v / tp->ytiles + data->yoffs; + float sn = gph::fbm(u * tp->noise_freq, v * tp->noise_freq, tp->num_octaves); /* todo use the image later */ return sn;