Moved moore neighboring to cube tables

This commit is contained in:
Marc Gilleron 2017-08-20 15:37:07 +02:00
parent cb548234fc
commit aa4d04d1a0
3 changed files with 37 additions and 33 deletions

View File

@ -137,5 +137,38 @@ const unsigned int g_edge_corners[EDGE_COUNT][2] = {
{ 4, 5 }, { 5, 6 }, { 6, 7 }, { 7, 4 } { 4, 5 }, { 5, 6 }, { 6, 7 }, { 7, 4 }
}; };
// Order is irrelevant
const Vector3i g_moore_neighboring_3d[26] = {
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),
};
} // namespace CubeTables } // namespace CubeTables

View File

@ -28,6 +28,8 @@ extern const Vector3i g_edge_inormals[EDGE_COUNT];
extern const unsigned int g_edge_corners[EDGE_COUNT][2]; extern const unsigned int g_edge_corners[EDGE_COUNT][2];
extern const Vector3i g_moore_neighboring_3d[26];
} // namespace CubeTables } // namespace CubeTables

View File

@ -1,5 +1,6 @@
#include "voxel_map.h" #include "voxel_map.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "cube_tables.h"
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// VoxelBlock // VoxelBlock
@ -134,41 +135,9 @@ bool VoxelMap::has_block(Vector3i pos) const {
return /*(_last_accessed_block != NULL && _last_accessed_block->pos == pos) ||*/ _blocks.has(pos); return /*(_last_accessed_block != NULL && _last_accessed_block->pos == pos) ||*/ _blocks.has(pos);
} }
Vector3i g_moore_neighboring_3d[26] = {
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),
};
bool VoxelMap::is_block_surrounded(Vector3i pos) const { bool VoxelMap::is_block_surrounded(Vector3i pos) const {
for (unsigned int i = 0; i < 26; ++i) { for (unsigned int i = 0; i < 26; ++i) {
Vector3i bpos = pos + g_moore_neighboring_3d[i]; Vector3i bpos = pos + CubeTables::g_moore_neighboring_3d[i];
if (!has_block(bpos)) { if (!has_block(bpos)) {
return false; return false;
} }