1 #include <gmath/gmath.h>
12 static float calc_height(float u, float v, void *ptr);
25 vis_scene = new Scene;
30 void Terrain::destroy()
35 bool Terrain::generate(const TerrainParams ¶ms)
39 float txsz = params.xsz / params.xtiles;
40 float tysz = params.ysz / params.ytiles;
42 for(int i=0; i<params.ytiles; i++) {
43 for(int j=0; j<params.xtiles; j++) {
45 tile.mesh = gfx_create_mesh();
47 gen_heightfield(tile.mesh, txsz, tysz, params.max_height,
48 params.tile_usub, params.tile_vsub, calc_height,
51 tile.mesh->update_vertex_data();
52 tiles.push_back(tile);
55 the terrain scene stores objects only
56 no need to fill the mat, mesh std::vectors
58 Object *o = new Object;
60 o->material = &material;
61 o->transform = Mat4::identity;
63 vis_scene->objects.push_back(o);
69 Scene *Terrain::get_visible(const Camera *camera) const
74 static float calc_height(float u, float v, void *ptr)
77 fprintf(stderr, "Terrain parameters not found.\n");
81 TerrainParams *tp = (TerrainParams*)ptr;
82 float sn = gph::fbm(u * tp->noise_freq, v * tp->noise_freq, tp->num_octaves);
83 /* todo use the image later */