Cleaned up and pulled out some code into Map.cpp in order to start working on the meat of the *Correct* voxel traversal method as explained in the paper.

This commit is contained in:
MitchellHansen
2017-07-12 00:09:19 -07:00
parent 1bfc54adf1
commit 316293a110
6 changed files with 333 additions and 98 deletions

View File

@@ -11,6 +11,49 @@
#define _USE_MATH_DEFINES
#include <math.h>
class Map {
public:
Map(uint32_t dimensions);
// Sets a voxel in the 3D char dataset
void setVoxel(sf::Vector3i position, int val);
// Gets a voxel at the 3D position in the octree
char getVoxel(sf::Vector3i pos);
std::vector<std::tuple<sf::Vector3i, char>> Map::CastRayOctree(
Octree *octree,
sf::Vector3i* map_dim,
sf::Vector2f* cam_dir,
sf::Vector3f* cam_pos
);
std::vector<std::tuple<sf::Vector3i, char>> Map::CastRayCharArray(
char *map,
sf::Vector3i* map_dim,
sf::Vector2f* cam_dir,
sf::Vector3f* cam_pos
);
// Octree handles all basic octree operations
Octree octree;
private:
// ======= DEBUG ===========
int counter = 0;
std::stringstream output_stream;
// The 3D char dataset that is generated at runtime. This will be replaced by two different interactions.
// The first a file loading function that loads binary octree data.
// The second being an import tool which will allow Any -> Octree transformation.
char* voxel_data;
// =========================
};
// Might possibly use this struct for hashing XYZ chunk values into a dict for storage and loading
struct XYZHasher {
std::size_t operator()(const sf::Vector3i& k) const {
return ((std::hash<int>()(k.x)
@@ -18,29 +61,3 @@ struct XYZHasher {
^ (std::hash<int>()(k.z) << 1);
}
};
class Map {
public:
Map(uint32_t dimensions);
void setVoxel(sf::Vector3i position, int val);
bool getVoxelFromOctree(sf::Vector3i position);
bool getVoxel(sf::Vector3i pos);
Octree octree;
bool test();
private:
// ======= DEBUG ===========
int counter = 0;
std::stringstream output_stream;
// =========================
char* voxel_data;
};

View File

@@ -6,7 +6,7 @@
#define OCT_DIM 32
struct oct_state {
struct OctState {
int parent_stack_position = 0;
uint64_t parent_stack[32] = { 0 };
@@ -16,6 +16,10 @@ struct oct_state {
uint64_t current_descriptor;
// ====== DEBUG =======
char found = 1;
};
@@ -27,11 +31,16 @@ public:
Octree();
~Octree() {};
// Generate an octree from 3D indexed array of char data
void Generate(char* data, sf::Vector3i dimensions);
// TODO: Load the octree from a serialized or whatever file
void Load(std::string octree_file_name);
uint64_t *trunk_buffer;
uint64_t trunk_buffer_position = buffer_size;
// I think the best way to transfer all of the data to the GPU. Each buffer will contain a set of blocks
// except for the trunk buffer. The paper indicates that the cutoff point for the trunk can vary,
// but since I'm going to do seperate buffers, I'm going to set a hard cutoff for the trunk so we
// know when to switch buffers
uint64_t *descriptor_buffer;
uint64_t descriptor_buffer_position = buffer_size;
@@ -46,16 +55,17 @@ public:
uint64_t root_index = 0;
int page_header_counter = 0x8000;
// Cheat and underflow to get the position
uint64_t current_info_section_position = ((uint64_t)0)-1;
uint64_t stack_pos = 0x8000;
uint64_t global_pos = buffer_size - 50;
uint64_t copy_to_stack(std::vector<uint64_t> children, unsigned int voxel_scale);
// 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 GetVoxel(sf::Vector3i position);
OctState GetVoxel(sf::Vector3i position);
void print_block(int block_pos);

View File

@@ -8,6 +8,9 @@
#include <string>
#include <imgui/imgui.h>
#include <cmath>
#include <SFML/Graphics/Texture.hpp>
#include <algorithm>
#include <tuple>
const double PI = 3.141592653589793238463;
const float PI_F = 3.14159265358979f;
@@ -250,8 +253,6 @@ inline bool CheckContiguousValid(const uint64_t c) {
return (c & bitmask) == bitmask;
}
inline bool IsLeaf(const uint64_t descriptor) {
uint64_t leaf_mask = 0xFF000000;