From 043eeecb803dc8bd89915097a4c78d6d08ca0c1c Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Wed, 22 Feb 2017 18:36:14 -0800 Subject: [PATCH] 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;