Initial traversal of the heirarchy

master
MitchellHansen 8 years ago
parent 0c9ef2ae6a
commit 043eeecb80

@ -42,6 +42,8 @@ public:
for (int i = 0; i < 0x8000; i++) { for (int i = 0; i < 0x8000; i++) {
block_stack.back()[i] = 0; block_stack.back()[i] = 0;
} }
}; };
~Octree() {}; ~Octree() {};
@ -91,7 +93,24 @@ public:
parent_stack.push(head); 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 child1 = block_stack.front()[index];
uint64_t child2 = block_stack.front()[index+1]; uint64_t child2 = block_stack.front()[index+1];
@ -114,14 +133,14 @@ public:
private: private:
uint64_t cp_to_index(uint64_t descriptor) { 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;
const uint64_t cp_mask = 0x0000000000007fff;
return descriptor & cp_mask;
};
//uint64_t is_leaf(uint64_t descriptor, )
}; };

@ -189,7 +189,6 @@ void Map::generate_octree() {
a.print_block(0); a.print_block(0);
//a.get_voxel(sf::Vector2i(0, 0));
} }
void Map::load_unload(sf::Vector3i world_position) { void Map::load_unload(sf::Vector3i world_position) {

@ -89,7 +89,7 @@ int main() {
Map _map(sf::Vector3i(0, 0, 0)); Map _map(sf::Vector3i(0, 0, 0));
_map.generate_octree(); _map.generate_octree();
_map.a.get_voxel(sf::Vector3i(0, 0, 0)); _map.a.get_voxel(sf::Vector3i(5, 5, 0));
// ============================= // =============================
return 0; return 0;

Loading…
Cancel
Save