From 043eeecb803dc8bd89915097a4c78d6d08ca0c1c Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Wed, 22 Feb 2017 18:36:14 -0800 Subject: [PATCH 1/3] Initial traversal of the heirarchy --- include/Map.h | 35 +++++++++++++++++++++++++++-------- src/Map.cpp | 1 - src/main.cpp | 2 +- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/include/Map.h b/include/Map.h index 4dc7019..70691ca 100644 --- a/include/Map.h +++ b/include/Map.h @@ -42,6 +42,8 @@ public: for (int i = 0; i < 0x8000; i++) { block_stack.back()[i] = 0; } + + }; ~Octree() {}; @@ -91,7 +93,24 @@ public: parent_stack.push(head); - uint64_t index = cp_to_index(head); + uint64_t index = head & child_pointer_mask; + + int dimension = OCT_DIM; + sf::Vector3i quad_position(0, 0, 0); + + while (dimension > 1) { + + sf::Vector3i p; + if (position.x >= (dimension / 2) + quad_position.x) + quad_position.x += (dimension / 2); + if (position.y >= (dimension / 2) + quad_position.y) + quad_position.y += (dimension / 2); + if (position.z >= (dimension / 2) + quad_position.z) + quad_position.z += (dimension / 2); + + dimension /= 2; + + } uint64_t child1 = block_stack.front()[index]; uint64_t child2 = block_stack.front()[index+1]; @@ -114,14 +133,14 @@ public: private: - uint64_t cp_to_index(uint64_t descriptor) { - - const uint64_t cp_mask = 0x0000000000007fff; - return descriptor & cp_mask; + const uint64_t child_pointer_mask = 0x0000000000007fff; + const uint64_t far_bit_mask = 0x8000; + const uint64_t valid_mask = 0xFF0000; + const uint64_t leaf_mask = 0xFF000000; + const uint64_t contour_pointer_mask = 0xFFFFFF00000000; + const uint64_t contour_mask = 0xFF00000000000000; - }; - - //uint64_t is_leaf(uint64_t descriptor, ) + }; diff --git a/src/Map.cpp b/src/Map.cpp index 3432a74..48c40a5 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -189,7 +189,6 @@ void Map::generate_octree() { a.print_block(0); - //a.get_voxel(sf::Vector2i(0, 0)); } void Map::load_unload(sf::Vector3i world_position) { diff --git a/src/main.cpp b/src/main.cpp index 8f454ee..13c54f4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,7 +89,7 @@ int main() { Map _map(sf::Vector3i(0, 0, 0)); _map.generate_octree(); - _map.a.get_voxel(sf::Vector3i(0, 0, 0)); + _map.a.get_voxel(sf::Vector3i(5, 5, 0)); // ============================= return 0; From b0188909a308a0e5fb289c148f61e007be081bf1 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Fri, 24 Feb 2017 21:07:04 -0800 Subject: [PATCH 2/3] added the bitset idx tracking --- include/Map.h | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/include/Map.h b/include/Map.h index 70691ca..c448c42 100644 --- a/include/Map.h +++ b/include/Map.h @@ -83,33 +83,41 @@ public: } - // This might need to be a recursive function. But it needs to be easily ported to - // OpenCL C. Might spend some time thinking about how to do this in a linear algorithm + bool get_voxel(sf::Vector3i position) { + // Init the parent stack and push the head node std::queue parent_stack; - + uint64_t head = block_stack.front()[stack_pos]; - parent_stack.push(head); + // Get the index of the first child of the head node uint64_t index = head & child_pointer_mask; + // Init the idx stack + std::vector> scale_stack(log2(OCT_DIM)); + + // Set our initial dimension and the position we use to keep track what oct were in int dimension = OCT_DIM; sf::Vector3i quad_position(0, 0, 0); while (dimension > 1) { - sf::Vector3i p; - if (position.x >= (dimension / 2) + quad_position.x) + if (position.x >= (dimension / 2) + quad_position.x) { quad_position.x += (dimension / 2); - if (position.y >= (dimension / 2) + quad_position.y) + scale_stack.at(log2(OCT_DIM) - log2(dimension)).set(0); + } + if (position.y >= (dimension / 2) + quad_position.y) { quad_position.y += (dimension / 2); - if (position.z >= (dimension / 2) + quad_position.z) + scale_stack.at(log2(OCT_DIM) - log2(dimension)).set(1); + } + if (position.z >= (dimension / 2) + quad_position.z) { quad_position.z += (dimension / 2); + scale_stack.at(log2(OCT_DIM) - log2(dimension)).set(2); + } dimension /= 2; - } uint64_t child1 = block_stack.front()[index]; From 49253f4907f1b6017ad06dda2f148e028ef0bec6 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Fri, 24 Feb 2017 21:07:44 -0800 Subject: [PATCH 3/3] small tweak --- include/Map.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/Map.h b/include/Map.h index c448c42..cc75b52 100644 --- a/include/Map.h +++ b/include/Map.h @@ -104,6 +104,8 @@ public: while (dimension > 1) { + // Do the logic steps to find which sub oct we step down into + if (position.x >= (dimension / 2) + quad_position.x) { quad_position.x += (dimension / 2); scale_stack.at(log2(OCT_DIM) - log2(dimension)).set(0); @@ -117,7 +119,12 @@ public: scale_stack.at(log2(OCT_DIM) - log2(dimension)).set(2); } + // Set the new dimension dimension /= 2; + + + + } uint64_t child1 = block_stack.front()[index];