From f0eb6a7b101afba52f33c5286e15a862ee68c64e Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 7 May 2011 16:06:08 +0200 Subject: Replace static heightmap with perlin noise using libnoise and noiseutils. --- terrain.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 terrain.h (limited to 'terrain.h') diff --git a/terrain.h b/terrain.h new file mode 100644 index 0000000..88b2277 --- /dev/null +++ b/terrain.h @@ -0,0 +1,9 @@ +#ifndef TERRAIN_H +#define TERRAIN_H + +class Terrain { + public: + static float *generate_heights(int x, int y, int width, int height); +}; + +#endif -- cgit v1.2.3 From 7d5c1adf8e581599848b3fec54e0af88eb469046 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 8 May 2011 15:02:30 +0200 Subject: Working dynamic generation of terrain. --- terrain.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'terrain.h') diff --git a/terrain.h b/terrain.h index 88b2277..3ce4402 100644 --- a/terrain.h +++ b/terrain.h @@ -1,9 +1,15 @@ #ifndef TERRAIN_H #define TERRAIN_H +#include + class Terrain { + private: + std::set > chunk_indices; public: - static float *generate_heights(int x, int y, int width, int height); + 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); }; #endif -- cgit v1.2.3 From 595ac4744b75688f7ca61993c42ea9eedab3a6b7 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 8 May 2011 15:52:41 +0200 Subject: Merged Quadtree and friends into Terrain. --- terrain.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'terrain.h') 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 #include class Terrain { private: std::set > 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 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 -- cgit v1.2.3 From 4597c723c8dc1ab83fe23d7b330cd2ce974cba5d Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 8 May 2011 20:57:24 +0200 Subject: Halve triangles/vertices per node, assume width and height is always 1. --- terrain.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'terrain.h') diff --git a/terrain.h b/terrain.h index 79a615e..b391f94 100644 --- a/terrain.h +++ b/terrain.h @@ -15,15 +15,14 @@ class Terrain { struct Node { Chunk *chunk; - float x, y, width, height; - float vertex_array[15]; + float x, y; + float vertex_array[12]; - Node(Chunk *chunk, float x, float y, float width, float height); + 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); -- cgit v1.2.3 From a820c852d14f466f3d9096c7efcd571d3bf006eb Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 9 May 2011 22:43:20 +0200 Subject: Fixed chunk border bugginess. --- terrain.h | 1 + 1 file changed, 1 insertion(+) (limited to 'terrain.h') diff --git a/terrain.h b/terrain.h index b391f94..b50c5e5 100644 --- a/terrain.h +++ b/terrain.h @@ -33,6 +33,7 @@ class Terrain { Terrain *terrain; Node **nodes; float x, y, width, height; + int h_width, h_height; float *heights; Vector3 *normals; size_t buf_size; -- cgit v1.2.3 From 0073f833c88f4a25dadc777495639069ba9d7bed Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 9 May 2011 23:47:45 +0200 Subject: Simple flat file-based saving and loading of chunks. --- terrain.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'terrain.h') diff --git a/terrain.h b/terrain.h index b50c5e5..736b719 100644 --- a/terrain.h +++ b/terrain.h @@ -60,10 +60,13 @@ class 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); }; -- cgit v1.2.3