diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2011-05-10 16:46:26 +0200 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2011-05-10 16:46:26 +0200 |
commit | d42ec5c0e89559abd276334b6c4804e1eaa5e9c7 (patch) | |
tree | c6afda3e3f51d4ac79ffcdabd2edfc6d36df4201 /terrain.h | |
parent | fa1216b691dc5be3429858dcff845239b1aec417 (diff) | |
parent | 7d93cab1eb1629b068858a68ac5e5840fe84a83a (diff) |
Merge branch 'master' into win32
Conflicts:
gui.h
quadtree.cpp
scene.cpp
scene.h
Diffstat (limited to 'terrain.h')
-rw-r--r-- | terrain.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/terrain.h b/terrain.h new file mode 100644 index 0000000..736b719 --- /dev/null +++ b/terrain.h @@ -0,0 +1,73 @@ +#ifndef TERRAIN_H +#define TERRAIN_H + +#include "vector.h" + +#include <list> +#include <set> + +class Terrain { + private: + std::set<std::pair<int, int> > chunk_indices; + + 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_grid(); + void draw_normal(); + float get_height(float px, float py); + Vector3 get_normal(int index); + }; + + struct Chunk { + Terrain *terrain; + Node **nodes; + float x, y, width, height; + int h_width, h_height; + float *heights; + Vector3 *normals; + size_t buf_size; + unsigned int vbo_object; + unsigned int node_count; + unsigned int vertices; + float init_time; + + Chunk(Terrain *tree, float x, float y, float width, float height); + ~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; + + std::list<Chunk*> chunks; + Terrain(); + virtual ~Terrain(); + + float *generate_heights(int x, int y, int width, int height); + float *get_chunk(int x, int y, int width, int height); + bool has_chunk(int x, int y); + void save_chunk(float *chunk, int x, int y, int width, int height); + float *load_chunk(int x, int y, int width, int height); + + 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 |