still puzzling over how to do the voxel traversal

master
MitchellHansen 8 years ago
parent 91e9de347e
commit 0f786b8647

@ -70,9 +70,16 @@ public:
return stack_pos; return stack_pos;
}; };
int get_idx(sf::Vector3i voxel_pos) {
return 1;
}
// This might need to be a recursive function. But it needs to be easily ported to // This might need to be a recursive function. But it needs to be easily ported to
// OpenCL C. Might spend some time thinking about how to do this in a linear algorithm // OpenCL C. Might spend some time thinking about how to do this in a linear algorithm
bool get_voxel(sf::Vector2i position) { bool get_voxel(sf::Vector3i position) {
std::queue<uint64_t> parent_stack; std::queue<uint64_t> parent_stack;
@ -101,10 +108,13 @@ public:
private: private:
uint64_t cp_to_index(uint64_t descriptor) { uint64_t cp_to_index(uint64_t descriptor) {
return descriptor >> 64 - 15;
const uint64_t cp_mask = 0x0000000000007fff;
return descriptor & cp_mask;
}; };
uint64_t is_leaf(uint64_t descriptor, ) //uint64_t is_leaf(uint64_t descriptor, )
}; };
@ -126,6 +136,8 @@ public:
void setVoxel(sf::Vector3i position, int val); void setVoxel(sf::Vector3i position, int val);
char getVoxelFromOctree(sf::Vector3i position);
void moveLight(sf::Vector2f in); void moveLight(sf::Vector2f in);
sf::Vector3f global_light; sf::Vector3f global_light;

@ -122,9 +122,6 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
} }
else { else {
// 2339 is the iterative anomoly
// 30454 is the stack anomoly
uint64_t tmp = 0; uint64_t tmp = 0;
uint64_t child = 0; uint64_t child = 0;
@ -171,12 +168,33 @@ uint64_t Map::generate_children(sf::Vector3i pos, int dim) {
void Map::generate_octree() { void Map::generate_octree() {
generate_children(sf::Vector3i(0, 0, 0), OCT_DIM/2); // Launch the recursive generator at (0,0,0) as the first point
// and the octree dimension as the initial block size
uint64_t root_node = generate_children(sf::Vector3i(0, 0, 0), OCT_DIM/2);
uint64_t tmp = 0;
PrettyPrintUINT64(root_node, &ss);
ss << " " << OCT_DIM << " " << counter++ << std::endl;
if (IsLeaf(root_node)) {
if (CheckLeafSign(root_node))
SetBit(0 + 16, &tmp);
SetBit(0 + 16 + 8, &tmp);
}
else {
SetBit(0 + 16, &tmp);
}
tmp |= a.copy_to_stack(std::vector<uint64_t>{root_node});
DumpLog(&ss, "raw_output.txt"); DumpLog(&ss, "raw_output.txt");
a.print_block(0); a.print_block(0);
a.get_voxel(sf::Vector2i(0, 0)); //a.get_voxel(sf::Vector2i(0, 0));
} }
void Map::load_unload(sf::Vector3i world_position) { void Map::load_unload(sf::Vector3i world_position) {
@ -229,6 +247,11 @@ void Map::setVoxel(sf::Vector3i world_position, int val) {
} }
char Map::getVoxelFromOctree(sf::Vector3i position)
{
return a.get_voxel(position);
}
char Map::getVoxel(sf::Vector3i pos){ char Map::getVoxel(sf::Vector3i pos){
return voxel_data[pos.x + OCT_DIM * (pos.y + OCT_DIM * pos.z)]; return voxel_data[pos.x + OCT_DIM * (pos.y + OCT_DIM * pos.z)];

@ -89,9 +89,11 @@ 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));
// ============================= // =============================
return 0; //return 0;
/*GL_Testing t; /*GL_Testing t;
t.compile_shader("../shaders/passthrough.frag", GL_Testing::Shader_Type::FRAGMENT); t.compile_shader("../shaders/passthrough.frag", GL_Testing::Shader_Type::FRAGMENT);

Loading…
Cancel
Save