-
Notifications
You must be signed in to change notification settings - Fork 0
/
Terrain.h
141 lines (92 loc) · 2.27 KB
/
Terrain.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Terrain.h
*
* Created on: 2011-02-25
* Author: zapo
*/
#ifndef TERRAIN_H_
#define TERRAIN_H_
#include "Model.h"
#include "Vertex3D.h"
#include "VectorUtils.h"
#include <SFML/Graphics.hpp>
namespace Bomber {
struct vector_hash : std::unary_function<sf::Vector3f, std::size_t> {
inline std::size_t operator()(sf::Vector3f const& p) const
{
std::size_t seed = 0;
boost::hash_combine(seed, p.x);
boost::hash_combine(seed, p.z);
return seed;
}
};
class TerrainNode;
class Camera;
class VertexBuffer;
class Terrain : public Model {
public:
Terrain(const std::string & texturePath, Camera &);
virtual ~Terrain();
bool LoadHeightMap(const std::string & filename);
bool GenMap();
void UnloadHeightMap();
float GetHeightAt(unsigned int x, unsigned y) const;
void Update();
void Render();
sf::Uint32 & GetNbTriangles() {
return numbTriangles;
}
void SetScale(const sf::Vector3f & _scale) {
scale = _scale;
}
sf::Uint32 & GetNbNodes() {
return numbNodes;
}
sf::Uint32 GetVisibleNodes() const {
return numbNodes - numbCulledNodes;
}
Camera & GetCamera() {
return *camera;
}
const sf::Vector3f & GetScale() {
return scale;
}
const sf::Image & GetMainTexture() const {
return mainTexture;
}
void RefineNode(TerrainNode & node);
bool Subdivide(TerrainNode & node);
void SetMaxResolution(float res) {
maxResolution = res;
}
void SetMinResolution(float res) {
minResolution = res;
}
float GetMaxResolution() const {
return maxResolution;
}
float GetMinResolution() const {
return minResolution;
}
std::vector<TerrainNode *> nodes;
std::vector<TerrainNode *>::iterator nodes_it;
static const unsigned int direction_adjacent_vertices[4][3];
std::vector<Vertex3D *> vertices;
TerrainNode * root;
boost::unordered_map<sf::Vector3f, Vertex3D *, vector_hash> position_vertice;
boost::unordered_map<sf::Vector3f, Vertex3D *, vector_hash>::iterator pv_it;
private:
float GetRelHeightAt(unsigned int x, unsigned y) const;
sf::Vector3f scale;
sf::Uint8 precision;
sf::Image heightMap;
float * heights;
Camera * camera;
unsigned int size;
float framerate;
float maxResolution;
float minResolution;
unsigned int numbNodes, numbCulledNodes, numbTriangles, numbSkirts;
};
}
#endif /* TERRAIN_H_ */