-
Notifications
You must be signed in to change notification settings - Fork 0
/
Block.d
108 lines (97 loc) · 4.12 KB
/
Block.d
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
module Block;
import Chunk;
import GlobalVariables;
class Block {
Chunk parent;
int[3] pos;
float[3] worldPos;
this(int[3] pos, Chunk parent)
{
this.parent = parent;
this.pos[0] = pos[0];
this.pos[1] = pos[1];
this.pos[2] = pos[2];
worldPos = [pos[0]*blockHeight,pos[1]*blockHeight,pos[2]*blockHeight];
}
bool blockAbove() {
return pos[1] < 127 && parent.blocks[pos[0]][pos[1]+1][pos[2]];
}
bool blockBelow() {
return pos[1] > 0 && parent.blocks[pos[0]][pos[1]-1][pos[2]];
}
bool blockRight() {
return pos[0] > 0 && parent.blocks[pos[0]-1][pos[1]][pos[2]];
}
bool blockLeft() {
return pos[0] < 15 && parent.blocks[pos[0]+1][pos[1]][pos[2]];
}
bool blockBack() {
return pos[2] > 0 && parent.blocks[pos[0]][pos[1]][pos[2]-1];
}
bool blockFront() {
return pos[2] < 15 && parent.blocks[pos[0]][pos[1]][pos[2]+1];
}
float[][2] getVertArray()
{
float[] vertices;
float[] textureCoords;
float modX = -parent.pos[0]*16*blockHeightInt-worldPos[0];
float modY = -parent.pos[1]*16*blockHeightInt-worldPos[1];
float modZ = -parent.pos[2]*16*blockHeightInt-worldPos[2];
if(!blockAbove) {
vertices ~= [modX-halfBlockHeight,modY-halfBlockHeight,modZ+halfBlockHeight];
vertices ~= [modX-halfBlockHeight,modY-halfBlockHeight,modZ-halfBlockHeight];
vertices ~= [modX+halfBlockHeight,modY-halfBlockHeight,modZ-halfBlockHeight];
vertices ~= [modX+halfBlockHeight,modY-halfBlockHeight,modZ+halfBlockHeight];
textureCoords ~= [0.0f, 0.0625f, 0.0625f, 0.0625f, 0.0625f, 0.0f, 0.0f, 0.0f];
}
if(!blockBelow) {
vertices ~= [modX+halfBlockHeight,modY+halfBlockHeight,modZ+halfBlockHeight];
vertices ~= [modX+halfBlockHeight,modY+halfBlockHeight,modZ-halfBlockHeight];
vertices ~= [modX-halfBlockHeight,modY+halfBlockHeight,modZ-halfBlockHeight];
vertices ~= [modX-halfBlockHeight,modY+halfBlockHeight,modZ+halfBlockHeight];
textureCoords ~= [0.125f, 0.0f, 0.125f, 0.0625f, 0.1875f, 0.0625f, 0.1875f, 0.0f];
}
if(!blockRight) {
vertices ~= [modX+halfBlockHeight,modY-halfBlockHeight,modZ-halfBlockHeight];
vertices ~= [modX+halfBlockHeight,modY+halfBlockHeight,modZ-halfBlockHeight];
vertices ~= [modX+halfBlockHeight,modY+halfBlockHeight,modZ+halfBlockHeight];
vertices ~= [modX+halfBlockHeight,modY-halfBlockHeight,modZ+halfBlockHeight];
if(blockAbove)
textureCoords ~= [0.125f, 0.0f, 0.125f, 0.0625f, 0.1875f, 0.0625f, 0.1875f, 0.0f];
else
textureCoords ~= [0.1875f, 0.0f, 0.1875f, 0.0625f, 0.25f, 0.0625f, 0.25f, 0.0f];
}
if(!blockLeft) {
vertices ~= [modX-halfBlockHeight,modY-halfBlockHeight,modZ+halfBlockHeight];
vertices ~= [modX-halfBlockHeight,modY+halfBlockHeight,modZ+halfBlockHeight];
vertices ~= [modX-halfBlockHeight,modY+halfBlockHeight,modZ-halfBlockHeight];
vertices ~= [modX-halfBlockHeight,modY-halfBlockHeight,modZ-halfBlockHeight];
if(blockAbove)
textureCoords ~= [0.125f, 0.0f, 0.125f, 0.0625f, 0.1875f, 0.0625f, 0.1875f, 0.0f];
else
textureCoords ~= [0.1875f, 0.0f, 0.1875f, 0.0625f, 0.25f, 0.0625f, 0.25f, 0.0f];
}
if(!blockBack) {
vertices ~= [modX+halfBlockHeight,modY-halfBlockHeight,modZ+halfBlockHeight];
vertices ~= [modX+halfBlockHeight,modY+halfBlockHeight,modZ+halfBlockHeight];
vertices ~= [modX-halfBlockHeight,modY+halfBlockHeight,modZ+halfBlockHeight];
vertices ~= [modX-halfBlockHeight,modY-halfBlockHeight,modZ+halfBlockHeight];
if(blockAbove)
textureCoords ~= [0.125f, 0.0f, 0.125f, 0.0625f, 0.1875f, 0.0625f, 0.1875f, 0.0f];
else
textureCoords ~= [0.1875f, 0.0f, 0.1875f, 0.0625f, 0.25f, 0.0625f, 0.25f, 0.0f];
}
if(!blockFront) {
vertices ~= [modX-halfBlockHeight,modY-halfBlockHeight,modZ-halfBlockHeight];
vertices ~= [modX-halfBlockHeight,modY+halfBlockHeight,modZ-halfBlockHeight];
vertices ~= [modX+halfBlockHeight,modY+halfBlockHeight,modZ-halfBlockHeight];
vertices ~= [modX+halfBlockHeight,modY-halfBlockHeight,modZ-halfBlockHeight];
if(blockAbove)
textureCoords ~= [0.125f, 0.0f, 0.125f, 0.0625f, 0.1875f, 0.0625f, 0.1875f, 0.0f];
else
textureCoords ~= [0.1875f, 0.0f, 0.1875f, 0.0625f, 0.25f, 0.0625f, 0.25f, 0.0f];
}
return [vertices, textureCoords];
}
}