From aa4d04d1a04b35de4c4b46cb376708b721397471 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sun, 20 Aug 2017 15:37:07 +0200 Subject: [PATCH] Moved moore neighboring to cube tables --- cube_tables.cpp | 33 +++++++++++++++++++++++++++++++++ cube_tables.h | 2 ++ voxel_map.cpp | 35 ++--------------------------------- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/cube_tables.cpp b/cube_tables.cpp index 2e2484e..bfcb976 100644 --- a/cube_tables.cpp +++ b/cube_tables.cpp @@ -137,5 +137,38 @@ const unsigned int g_edge_corners[EDGE_COUNT][2] = { { 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 diff --git a/cube_tables.h b/cube_tables.h index 88285b7..a7abc5c 100644 --- a/cube_tables.h +++ b/cube_tables.h @@ -28,6 +28,8 @@ extern const Vector3i g_edge_inormals[EDGE_COUNT]; extern const unsigned int g_edge_corners[EDGE_COUNT][2]; +extern const Vector3i g_moore_neighboring_3d[26]; + } // namespace CubeTables diff --git a/voxel_map.cpp b/voxel_map.cpp index 16b6dad..5b22a3e 100644 --- a/voxel_map.cpp +++ b/voxel_map.cpp @@ -1,5 +1,6 @@ #include "voxel_map.h" #include "core/os/os.h" +#include "cube_tables.h" //---------------------------------------------------------------------------- // 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); } -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 { 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)) { return false; }