Octree traversal now works perfectly, edge cases worked out
This commit is contained in:
@@ -95,6 +95,12 @@ public:
|
||||
0x1F, 0x3F, 0x7F, 0xFF
|
||||
};
|
||||
|
||||
//uint8_t count_mask_8[8]{
|
||||
// 0xFF, 0x7F, 0x3F, 0x1F,
|
||||
// 0xF, 0x7, 0x3, 0x1
|
||||
//};
|
||||
|
||||
|
||||
// With a position and the head of the stack. Traverse down the voxel hierarchy to find
|
||||
// the IDX and stack position of the highest resolution (maybe set resolution?) oct
|
||||
bool get_voxel(sf::Vector3i position) {
|
||||
@@ -195,7 +201,16 @@ public:
|
||||
// We also need to traverse to the correct child pointer
|
||||
|
||||
// Count the number of non-leaf octs that come before and add it to the index to get the position
|
||||
int count = count_bits((uint8_t)(head >> 24) ^ count_mask_8[mask_index]);
|
||||
int i1 = count_bits((uint8_t)(head >> 16) & count_mask_8[0]);
|
||||
int i2 = count_bits((uint8_t)(head >> 16) & count_mask_8[1]);
|
||||
int i3 = count_bits((uint8_t)(head >> 16) & count_mask_8[2]);
|
||||
int i4 = count_bits((uint8_t)(head >> 16) & count_mask_8[3]);
|
||||
int i5 = count_bits((uint8_t)(head >> 16) & count_mask_8[4]);
|
||||
int i6 = count_bits((uint8_t)(head >> 16) & count_mask_8[5]);
|
||||
int i7 = count_bits((uint8_t)(head >> 16) & count_mask_8[6]);
|
||||
int i8 = count_bits((uint8_t)(head >> 16) & count_mask_8[7]);
|
||||
|
||||
int count = count_bits((uint8_t)(head >> 16) & count_mask_8[mask_index]);
|
||||
|
||||
// Because we are getting the position at the first child we need to back up one
|
||||
// Or maybe it's because my count bits function is wrong...
|
||||
@@ -208,7 +223,7 @@ public:
|
||||
|
||||
} else {
|
||||
// If the oct was not valid, then no CP's exists any further
|
||||
|
||||
// This implicitly says that if it's non-valid then it must be a leaf!!
|
||||
|
||||
// It appears that the traversal is now working but I need
|
||||
// to focus on how to now take care of the end condition.
|
||||
|
||||
25
src/Map.cpp
25
src/Map.cpp
@@ -68,18 +68,27 @@ bool IsLeaf(const uint64_t descriptor) {
|
||||
|
||||
Map::Map(sf::Vector3i position) {
|
||||
|
||||
srand(time(NULL));
|
||||
//srand(time(NULL));
|
||||
|
||||
load_unload(position);
|
||||
//load_unload(position);
|
||||
|
||||
for (int i = 0; i < OCT_DIM * OCT_DIM * OCT_DIM; i++) {
|
||||
if (rand() % 2 == 1)
|
||||
voxel_data[i] = 0;
|
||||
if (rand() % 25 > 1)
|
||||
voxel_data[i] = 1;
|
||||
else
|
||||
voxel_data[i] = 1;
|
||||
}
|
||||
|
||||
voxel_data[0 + OCT_DIM * (0 + OCT_DIM * 0)] = 1;
|
||||
|
||||
//voxel_data[1 + OCT_DIM * (0 + OCT_DIM * 0)] = 0;
|
||||
//voxel_data[1 + OCT_DIM * (1 + OCT_DIM * 0)] = 0;
|
||||
//voxel_data[1 + OCT_DIM * (0 + OCT_DIM * 1)] = 0;
|
||||
//voxel_data[1 + OCT_DIM * (1 + OCT_DIM * 1)] = 0;
|
||||
|
||||
//voxel_data[0 + OCT_DIM * (0 + OCT_DIM * 0)] = 0;
|
||||
//voxel_data[0 + OCT_DIM * (1 + OCT_DIM * 0)] = 0;
|
||||
//voxel_data[0 + OCT_DIM * (0 + OCT_DIM * 1)] = 0;
|
||||
//voxel_data[0 + OCT_DIM * (1 + OCT_DIM * 1)] = 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -136,11 +145,13 @@ uint64_t Map::generate_children(sf::Vector3i pos, int voxel_scale) {
|
||||
output_stream << " " << voxel_scale << " " << counter++ << std::endl;
|
||||
|
||||
if (IsLeaf(child)) {
|
||||
if (CheckLeafSign(child))
|
||||
if (CheckLeafSign(child)) {
|
||||
SetBit(i + 16, &tmp);
|
||||
|
||||
children.push_back(child);
|
||||
} else {
|
||||
SetBit(i + 16 + 8, &tmp);
|
||||
}
|
||||
}
|
||||
|
||||
else {
|
||||
SetBit(i + 16, &tmp);
|
||||
|
||||
@@ -95,8 +95,8 @@ int main() {
|
||||
// =============================
|
||||
Map _map(sf::Vector3i(0, 0, 0));
|
||||
_map.generate_octree();
|
||||
std::cout << _map.a.get_voxel(sf::Vector3i(5, 5, 0));
|
||||
std::cout << _map.getVoxel(sf::Vector3i(5, 5, 0));
|
||||
std::cout << _map.a.get_voxel(sf::Vector3i(1, 1, 0));
|
||||
std::cout << _map.getVoxel(sf::Vector3i(1, 1, 0));
|
||||
_map.test_map();
|
||||
std::cin.get();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user