get height, camera + cow movement with keys
[demo] / src / terrain.h
index d6f4844..db9464d 100644 (file)
@@ -1,6 +1,55 @@
 #ifndef TERRAIN_H_
 #define TERRAIN_H_
 
+#include "image.h"
 
+class Camera;
+class Scene;
+
+// terrain 8a ftiaxnei skini k taisma renderer
+class TerrainTile {
+private:
+       Mesh *mesh;
+
+       friend class Terrain;
+};
+
+/* parameters needed in terrain generation */
+
+struct TerrainParams {
+       float xsz; /* terrain size in x axis */
+       float ysz; /* terrain size in y axis */
+       float max_height; /* max height of the heightfield */
+       int xtiles; /* number of tiles in x axis */
+       int ytiles; /* number of tiles in y axis */
+       int tile_usub;
+       int tile_vsub;
+       int num_octaves; /* Perlin noise sums */
+       float noise_freq; /* Perlin noise scaling factor */
+       Image coarse_heightmap; /* mask for low detail heightmap */
+};
+
+class Terrain {
+private:
+       TerrainParams params;
+       mutable Scene *vis_scene; /* set of visible tiles returned by get_visible */
+
+       std::vector<TerrainTile> tiles;
+       
+public:
+       Material material;
+
+       Terrain();
+       ~Terrain();
+
+       bool init();
+       void destroy();
+
+       bool generate(const TerrainParams &params);
+       Scene *get_visible(const Camera *camera) const;
+
+       float get_height(float u, float v) const;       
+       float get_height(const Vec3 &pos) const; /* world coordinates */ 
+};
 
 #endif // TERRAIN_H_
\ No newline at end of file