summaryrefslogtreecommitdiff
path: root/terrain.h
blob: 6fa39b319885380a2c6f8225d81d262dd6c1bda5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef TERRAIN_H
#define TERRAIN_H

#include "vector.h"
#include "terrain_cache.h"

#include <list>

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 {
			Terrain *terrain;
			Node **nodes;
			float x, y, width, height;
			int h_width, h_height;
			float *heights;
			TerrainCacheObject::p cache_obj;
			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;
		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