This repository was archived by the owner on Aug 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.h
More file actions
61 lines (47 loc) · 1.28 KB
/
tree.h
File metadata and controls
61 lines (47 loc) · 1.28 KB
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
#pragma once
class Tree {
public:
// Tree Attributes
int type = 0;
int treeHeight;
int leavesWidth;
int leavesHeight;
std::vector<glm::vec3> leavesPoints;
std::vector<glm::vec3> logPoints;
glm::vec3 pos;
Tree(glm::vec3 position, int height, int leaves_width, int leaves_height) {
pos = position;
treeHeight = height;
leavesHeight = leaves_height;
leavesWidth = leaves_width;
std::cout << "Generating tree in: " << position.x << " " << position.z << std::endl;
};
void generate() {
int startX = pos.x;
int startZ = pos.z;
int startY = pos.y;
bool center = true;
for (int y = startY + (treeHeight - leavesHeight); y < treeHeight + startY + 1; y++) {
for (int i = -leavesWidth; i < leavesWidth + 1; i++) { // Z
for (int i2 = -leavesWidth; i2 < leavesWidth + 1; i2++) { // X
if (i == 0 && i2 == 0) if (!center) continue;
leavesPoints.push_back(glm::vec3(startX + i2, y , startZ + i));
}
}
// center = false;
}
for (int i = 0; i <= treeHeight - 1; i++) {
logPoints.push_back(glm::vec3(startX, startY + i, startZ));
}
std::cout << "Tree generated" << std::endl;
}
glm::vec3 getPosition() {
return pos;
}
std::vector<glm::vec3> getLeaves() {
return leavesPoints;
}
std::vector<glm::vec3> getLogs() {
return logPoints;
}
};