get height, camera + cow movement with keys
[demo] / src / terrain.h
1 #ifndef TERRAIN_H_
2 #define TERRAIN_H_
3
4 #include "image.h"
5
6 class Camera;
7 class Scene;
8
9 // terrain 8a ftiaxnei skini k taisma renderer
10 class TerrainTile {
11 private:
12         Mesh *mesh;
13
14         friend class Terrain;
15 };
16
17 /* parameters needed in terrain generation */
18
19 struct TerrainParams {
20         float xsz; /* terrain size in x axis */
21         float ysz; /* terrain size in y axis */
22         float max_height; /* max height of the heightfield */
23         int xtiles; /* number of tiles in x axis */
24         int ytiles; /* number of tiles in y axis */
25         int tile_usub;
26         int tile_vsub;
27         int num_octaves; /* Perlin noise sums */
28         float noise_freq; /* Perlin noise scaling factor */
29         Image coarse_heightmap; /* mask for low detail heightmap */
30 };
31
32 class Terrain {
33 private:
34         TerrainParams params;
35         mutable Scene *vis_scene; /* set of visible tiles returned by get_visible */
36
37         std::vector<TerrainTile> tiles;
38         
39 public:
40         Material material;
41
42         Terrain();
43         ~Terrain();
44
45         bool init();
46         void destroy();
47
48         bool generate(const TerrainParams &params);
49         Scene *get_visible(const Camera *camera) const;
50
51         float get_height(float u, float v) const;       
52         float get_height(const Vec3 &pos) const; /* world coordinates */ 
53 };
54
55 #endif // TERRAIN_H_