#ifndef TERRAIN_H #define TERRAIN_H #include "vector.h" #include "terrain_cache.h" #include "model.h" #include #include class Terrain { public: struct Chunk; struct Node { Chunk *chunk; float x, y; float vertex_array[12]; Node(Chunk *chunk, float x, float y); virtual ~Node(); float distance(float px, float pz); void fill(); void draw(); void draw_grid(); void draw_normal(); float get_height(float px, float py); Vector3 get_normal(int index); }; struct Chunk { typedef std::pair ObjectPair; typedef std::list ObjectList; Terrain *terrain; Node **nodes; float x, y; int width, height; int h_width, h_height; int n_width, n_height; float *heights; TerrainCacheObject::p cache_obj; Vector3 *normals; size_t buf_size; unsigned int vbo_object; unsigned int node_count; unsigned int vertices; ObjectList objects; Chunk(Terrain *tree, float x, float y); ~Chunk(); float distance(float px, float pz); void make_vbo(); Node *find(float x, float y); void calc_normals(); }; static const int chunk_size = 32; //! Chunk size with overhead. static const int chunk_size_total = chunk_size + 3; std::list chunks; TerrainCache *tc; Terrain(); virtual ~Terrain(); void raise(float x, float z, float radius, float focus, float strength, bool up = true); void update(float x, float z); Chunk *find_chunk(float x, float y); Node *find(float x, float y); }; #endif