-
Notifications
You must be signed in to change notification settings - Fork 0
/
TerrainNode.h
155 lines (106 loc) · 2.55 KB
/
TerrainNode.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* TerrainNode.h
*
* Created on: 2011-03-12
* Author: zapo
*/
#ifndef TERRAINNODE_H_
#define TERRAINNODE_H_
#include <SFML/Graphics.hpp>
#include "Vertex3D.h"
namespace Bomber {
class Terrain;
class TerrainNode {
public:
enum Type {
NW = 0, NE = 1, SW = 2, SE = 3, NONE = 4
};
enum Border {
BOTTOM = 0, LEFT = 1, TOP = 2, RIGHT = 3
};
TerrainNode(const sf::Vector2f & center, float size, Terrain & t, TerrainNode * parent, Type position);
virtual ~TerrainNode();
float GetSize() const {
return size;
}
TerrainNode * GetNeighbor(Border border) {
return neighbors[border];
}
void Disable(){
for(unsigned int i=0; i < 9; i++) {
vertices[i]->enabled = false;
}
}
void Enable(){
for(unsigned int i=0; i < 9; i++) {
vertices[i]->enabled = true;
}
}
void SetSize(float _size) {
size = _size;
}
sf::Vector2f & GetCenter() {
return center;
}
void SetCenter(const sf::Vector2f & _center) {
center = _center;
}
void SetVertex(Vertex::Location loc, Vertex3D * vertex) {
vertices[loc] = vertex;
}
Vertex3D * GetVertex(Vertex::Location loc) {
return vertices[loc];
}
void SetChild(Type type, TerrainNode * node) {
children[type] = node;
}
TerrainNode * GetChild(Type type) {
return children[type];
}
sf::FloatRect & GetBoundBox() {
return boundBox;
}
void SetColor(sf::Vector3f color) {
for(unsigned int i=0; i<9; i++) {
vertices[i]->col = color;
}
}
void SetLocalNeighbors();
void SetGlobalNeighbors();
static const unsigned int direction_map[4][2];
static const unsigned int inverse_direction_map[4][2];
static const unsigned int oposite_direction[4];
static const unsigned int local_directions[4][2];
std::vector<TerrainNode *> GetBorderNodes(Border border);
std::vector<TerrainNode *> GetAjacentNodes(Border border);
inline unsigned int GetLod() const {
return lod;
}
inline Type GetOpositePosition(Border border) const {
if(position == direction_map[border][0]) {
return (TerrainNode::Type)inverse_direction_map[border][0];
} else {
return (TerrainNode::Type)inverse_direction_map[border][1];
}
}
inline bool IsBro(TerrainNode & node) {
return node.parent == parent;
}
void Render();
static const float MIN_SIZE;
bool isLeaf;
std::vector<unsigned int> indexes_ref;
TerrainNode * neighbors[4]; // border neighbors
private :
Type position;
TerrainNode * parent;
Terrain * terrain;
sf::Vector2f center;
float size;
Vertex3D * vertices[9];
TerrainNode * children[4];
unsigned int lod;
sf::FloatRect boundBox;
};
}
#endif /* TERRAINNODE_H_ */