forked from Zylann/godot_voxel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube_tables.cpp
202 lines (178 loc) · 4.3 KB
/
cube_tables.cpp
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "cube_tables.h"
namespace Cube {
// The following tables respect the following conventions
//
// 7-------6
// /| /|
// / | / | Corners
// 4-------5 |
// | 3----|--2
// | / | / y z
// |/ |/ |/ OpenGL axis convention
// 0-------1 x--o
//
//
// o---10----o
// /| /|
// 11 7 9 6 Edges
// / | / |
// o----8----o |
// | o---2-|---o
// 4 / 5 /
// | 3 | 1
// |/ |/
// o----0----o
//
// Sides are ordered according to the Voxel::Side enum.
// Edges are ordered according to the Voxel::Edge enum (only g_edge_inormals!).
//
// Ordered as per the cube corners diagram
const Vector3 g_corner_position[CORNER_COUNT] = {
Vector3(1, 0, 0),
Vector3(0, 0, 0),
Vector3(0, 0, 1),
Vector3(1, 0, 1),
Vector3(1, 1, 0),
Vector3(0, 1, 0),
Vector3(0, 1, 1),
Vector3(1, 1, 1)
};
const int g_side_quad_triangles[SIDE_COUNT][6] = {
{ 0, 2, 1, 0, 3, 2 }, // LEFT (+x)
{ 0, 2, 1, 0, 3, 2 }, // RIGHT (-x)
{ 0, 2, 1, 0, 3, 2 }, // BOTTOM (-y)
{ 0, 2, 1, 0, 3, 2 }, // TOP (+y)
{ 0, 2, 1, 0, 3, 2 }, // BACK (-z)
{ 0, 2, 1, 0, 3, 2 }, // FRONT (+z)
};
//const unsigned int g_side_coord[SIDE_COUNT] = { 0, 0, 1, 1, 2, 2 };
//const unsigned int g_side_sign[SIDE_COUNT] = { 0, 1, 0, 1, 0, 1 };
const Vector3i g_side_normals[SIDE_COUNT] = {
// TODO Wrong! Left should be -X
Vector3i(1, 0, 0), // LEFT
Vector3i(-1, 0, 0), // RIGHT
Vector3i(0, -1, 0), // BOTTOM
Vector3i(0, 1, 0), // TOP
// TODO Wrong! Front should be -Z
Vector3i(0, 0, -1), // BACK
Vector3i(0, 0, 1), // FRONT
};
// Corners have same winding, relative to the face's normal
const unsigned int g_side_corners[SIDE_COUNT][4] = {
{ 3, 0, 4, 7 },
{ 1, 2, 6, 5 },
{ 1, 0, 3, 2 },
{ 4, 5, 6, 7 },
{ 0, 1, 5, 4 },
{ 2, 3, 7, 6 }
};
const unsigned int g_side_edges[SIDE_COUNT][4] = {
{ 3, 7, 11, 4 },
{ 1, 6, 9, 5 },
{ 0, 1, 2, 3 },
{ 8, 9, 10, 11 },
{ 0, 5, 8, 4 },
{ 2, 6, 10, 7 }
};
// 3---2
// | / | {0,1,2,0,2,3}
// 0---1
//static const unsigned int g_vertex_to_corner[Voxel::SIDE_COUNT][6] = {
// { 0, 3, 7, 0, 7, 4 },
// { 2, 1, 5, 2, 5, 6 },
// { 0, 1, 2, 0, 2, 3 },
// { 7, 6, 5, 7, 5, 4 },
// { 1, 0, 4 ,1, 4, 5 },
// { 3, 2, 6, 3, 6, 7 }
//};
const Vector3i g_corner_inormals[CORNER_COUNT] = {
Vector3i(1, -1, -1),
Vector3i(-1, -1, -1),
Vector3i(-1, -1, 1),
Vector3i(1, -1, 1),
Vector3i(1, 1, -1),
Vector3i(-1, 1, -1),
Vector3i(-1, 1, 1),
Vector3i(1, 1, 1)
};
const Vector3i g_edge_inormals[EDGE_COUNT] = {
Vector3i(0, -1, -1),
Vector3i(-1, -1, 0),
Vector3i(0, -1, 1),
Vector3i(1, -1, 0),
Vector3i(1, 0, -1),
Vector3i(-1, 0, -1),
Vector3i(-1, 0, 1),
Vector3i(1, 0, 1),
Vector3i(0, 1, -1),
Vector3i(-1, 1, 0),
Vector3i(0, 1, 1),
Vector3i(1, 1, 0)
};
const unsigned int g_edge_corners[EDGE_COUNT][2] = {
{ 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 },
{ 0, 4 }, { 1, 5 }, { 2, 6 }, { 3, 7 },
{ 4, 5 }, { 5, 6 }, { 6, 7 }, { 7, 4 }
};
// Order is irrelevant
const Vector3i g_moore_neighboring_3d[MOORE_NEIGHBORING_3D_COUNT] = {
Vector3i(-1, -1, -1),
Vector3i(0, -1, -1),
Vector3i(1, -1, -1),
Vector3i(-1, -1, 0),
Vector3i(0, -1, 0),
Vector3i(1, -1, 0),
Vector3i(-1, -1, 1),
Vector3i(0, -1, 1),
Vector3i(1, -1, 1),
Vector3i(-1, 0, -1),
Vector3i(0, 0, -1),
Vector3i(1, 0, -1),
Vector3i(-1, 0, 0),
//Vector3i(0,0,0),
Vector3i(1, 0, 0),
Vector3i(-1, 0, 1),
Vector3i(0, 0, 1),
Vector3i(1, 0, 1),
Vector3i(-1, 1, -1),
Vector3i(0, 1, -1),
Vector3i(1, 1, -1),
Vector3i(-1, 1, 0),
Vector3i(0, 1, 0),
Vector3i(1, 1, 0),
Vector3i(-1, 1, 1),
Vector3i(0, 1, 1),
Vector3i(1, 1, 1),
};
// Order is IMPORTANT:
// This is used in multithread context, in which we may iterate blocks in XYZ order, to avoid deadlocks.
const Vector3i g_ordered_moore_area_3d[MOORE_AREA_3D_COUNT] = {
Vector3i(-1, -1, -1),
Vector3i(0, -1, -1),
Vector3i(1, -1, -1),
Vector3i(-1, 0, -1),
Vector3i(0, 0, -1),
Vector3i(1, 0, -1),
Vector3i(-1, 1, -1),
Vector3i(0, 1, -1),
Vector3i(1, 1, -1),
Vector3i(-1, -1, 0),
Vector3i(0, -1, 0),
Vector3i(1, -1, 0),
Vector3i(-1, 0, 0),
Vector3i(0, 0, 0),
Vector3i(1, 0, 0),
Vector3i(-1, 1, 0),
Vector3i(0, 1, 0),
Vector3i(1, 1, 0),
Vector3i(-1, -1, 1),
Vector3i(0, -1, 1),
Vector3i(1, -1, 1),
Vector3i(-1, 0, 1),
Vector3i(0, 0, 1),
Vector3i(1, 0, 1),
Vector3i(-1, 1, 1),
Vector3i(0, 1, 1),
Vector3i(1, 1, 1)
};
} // namespace Cube