Octree traversal now works perfectly, edge cases worked out

This commit is contained in:
MitchellHansen
2017-03-22 00:55:10 -07:00
parent 30959128e4
commit d1b9ecd3e5
3 changed files with 38 additions and 12 deletions

View File

@@ -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,10 +145,12 @@ 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);
SetBit(i + 16 + 8, &tmp);
children.push_back(child);
} else {
SetBit(i + 16 + 8, &tmp);
}
}
else {

View File

@@ -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;