Octree traversal now works perfectly, edge cases worked out

master
MitchellHansen 8 years ago
parent 30959128e4
commit d1b9ecd3e5

@ -95,6 +95,12 @@ public:
0x1F, 0x3F, 0x7F, 0xFF 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 // 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 // the IDX and stack position of the highest resolution (maybe set resolution?) oct
bool get_voxel(sf::Vector3i position) { bool get_voxel(sf::Vector3i position) {
@ -195,7 +201,16 @@ public:
// We also need to traverse to the correct child pointer // 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 // 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 // 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... // Or maybe it's because my count bits function is wrong...
@ -208,7 +223,7 @@ public:
} else { } else {
// If the oct was not valid, then no CP's exists any further // 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 // It appears that the traversal is now working but I need
// to focus on how to now take care of the end condition. // to focus on how to now take care of the end condition.

@ -68,18 +68,27 @@ bool IsLeaf(const uint64_t descriptor) {
Map::Map(sf::Vector3i position) { 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++) { for (int i = 0; i < OCT_DIM * OCT_DIM * OCT_DIM; i++) {
if (rand() % 2 == 1) if (rand() % 25 > 1)
voxel_data[i] = 0; voxel_data[i] = 1;
else else
voxel_data[i] = 1; 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,10 +145,12 @@ uint64_t Map::generate_children(sf::Vector3i pos, int voxel_scale) {
output_stream << " " << voxel_scale << " " << counter++ << std::endl; output_stream << " " << voxel_scale << " " << counter++ << std::endl;
if (IsLeaf(child)) { if (IsLeaf(child)) {
if (CheckLeafSign(child)) if (CheckLeafSign(child)) {
SetBit(i + 16, &tmp); SetBit(i + 16, &tmp);
children.push_back(child);
SetBit(i + 16 + 8, &tmp); } else {
SetBit(i + 16 + 8, &tmp);
}
} }
else { else {

@ -95,8 +95,8 @@ int main() {
// ============================= // =============================
Map _map(sf::Vector3i(0, 0, 0)); Map _map(sf::Vector3i(0, 0, 0));
_map.generate_octree(); _map.generate_octree();
std::cout << _map.a.get_voxel(sf::Vector3i(5, 5, 0)); std::cout << _map.a.get_voxel(sf::Vector3i(1, 1, 0));
std::cout << _map.getVoxel(sf::Vector3i(5, 5, 0)); std::cout << _map.getVoxel(sf::Vector3i(1, 1, 0));
_map.test_map(); _map.test_map();
std::cin.get(); std::cin.get();
return 0; return 0;

Loading…
Cancel
Save