summaryrefslogtreecommitdiff
path: root/terrain.h
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2011-05-08 15:52:41 +0200
committerJon Bergli Heier <snakebite@jvnv.net>2011-05-08 15:52:41 +0200
commit595ac4744b75688f7ca61993c42ea9eedab3a6b7 (patch)
tree89f7e10b47fb4e709d2896d5e366305ec3a3ced8 /terrain.h
parent7d5c1adf8e581599848b3fec54e0af88eb469046 (diff)
Merged Quadtree and friends into Terrain.
Diffstat (limited to 'terrain.h')
-rw-r--r--terrain.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/terrain.h b/terrain.h
index 3ce4402..79a615e 100644
--- a/terrain.h
+++ b/terrain.h
@@ -1,15 +1,70 @@
#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, width, height;
+ float vertex_array[15];
+
+ Node(Chunk *chunk, float x, float y, float width, float height);
+ 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 {
+ Terrain *terrain;
+ Node **nodes;
+ float x, y, width, 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 raise(float x, float z, float radius, float focus, float strength, bool up = true);
+
+ void update(float x, float z);
+ Node *find(float x, float y);
};
#endif