Shuffling the map stuff around to make more sense structurally. Also shrunk the scope of the demos wayyyy down to facilitate easier debugging in my next planned steps

This commit is contained in:
MitchellHansen
2017-10-17 23:59:15 -07:00
parent 242aaaa485
commit c35f867c76
14 changed files with 638 additions and 771 deletions

35
include/map/ArrayMap.h Normal file
View File

@@ -0,0 +1,35 @@
#pragma once
#include<SFML/Graphics.hpp>
#include <algorithm>
#include "util.hpp"
#include <random>
#include <functional>
class ArrayMap {
public:
ArrayMap(sf::Vector3i dimensions);
~ArrayMap();
char getVoxel(sf::Vector3i position);
void setVoxel(sf::Vector3i position, char value);
sf::Vector3i getDimensions();
// =========== DEBUG =========== //
char* getDataPtr();
std::vector<std::tuple<sf::Vector3i, char>> ArrayMap::CastRayCharArray(
char* map,
sf::Vector3i* map_dim,
sf::Vector2f* cam_dir,
sf::Vector3f* cam_pos
);
private:
char *voxel_data;
sf::Vector3i dimensions;
};

View File

@@ -7,16 +7,35 @@
#include "util.hpp"
#include "map/Octree.h"
#include <time.h>
#include "map/Old_Map.h"
#include "map/ArrayMap.h"
#define _USE_MATH_DEFINES
#include <math.h>
// MonolithicMap
// Octree
// Map
// Player
// Camera
// Movement interface
// Subscription to joystick events?
// Player needs to have some way to query the map
// Map could return collision result
// Could handle multiple collision types, aabb, ray
// player could query map and generate collision
// Wouldn't need to make map more complex
class Map {
public:
// Currently takes a
Map(uint32_t dimensions, Old_Map* array_map);
Map(uint32_t dimensions);
// Sets a voxel in the 3D char dataset
void setVoxel(sf::Vector3i position, int val);
@@ -24,37 +43,37 @@ public:
// Gets a voxel at the 3D position in the octree
char getVoxel(sf::Vector3i pos);
std::vector<std::tuple<sf::Vector3i, char>> CastRayOctree(
Octree *octree,
sf::Vector3i* map_dim,
sf::Vector2f* cam_dir,
sf::Vector3f* cam_pos
);
std::vector<std::tuple<sf::Vector3i, char>> CastRayCharArray(
char *map,
sf::Vector3i* map_dim,
sf::Vector2f* cam_dir,
sf::Vector3f* cam_pos
);
// Return the position at which a generalized ray hits a voxel
sf::Vector3f LongRayIntersection(sf::Vector3f origin, sf::Vector3f magnitude);
// Return the voxels that a box intersects / contains
std::vector<sf::Vector3i> BoxIntersection(sf::Vector3f origin, sf::Vector3f magnitude);
// Return a normalized ray opposite of the intersected normals
sf::Vector3f ShortRayIntersection(sf::Vector3f origin, sf::Vector3f magnitude);
sf::Image GenerateHeightBitmap(sf::Vector3i dimensions);
void ApplyHeightmap(sf::Image bitmap);
// Octree handles all basic octree operations
Octree octree;
ArrayMap array_map;
private:
bool test_oct_arr_traversal(sf::Vector3i dimensions);
// ======= 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;
sf::Vector3i dimensions;
// =========================
double Sample(int x, int y, double *height_map);
void SetSample(int x, int y, double value, double *height_map);
void SampleSquare(int x, int y, int size, double value, double *height_map);
void SampleDiamond(int x, int y, int size, double value, double *height_map);
};
// Might possibly use this struct for hashing XYZ chunk values into a dict for storage and loading

View File

@@ -91,6 +91,13 @@ public:
static const uint64_t contour_pointer_mask = 0xFFFFFF00000000;
static const uint64_t contour_mask = 0xFF00000000000000;
std::vector<std::tuple<sf::Vector3i, char>> Octree::CastRayOctree(
Octree *octree,
sf::Vector3i* map_dim,
sf::Vector2f* cam_dir,
sf::Vector3f* cam_pos
);
private:
unsigned int oct_dimensions = 1;

View File

@@ -1,42 +0,0 @@
#pragma once
#include <SFML/System/Vector3.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Color.hpp>
#include <random>
#include <iostream>
#include <functional>
#include <cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#include <deque>
class Old_Map {
public:
Old_Map(sf::Vector3i dim);
~Old_Map();
void generate_terrain();
sf::Vector3i getDimensions();
char* get_voxel_data();
protected:
private:
double* height_map;
char *voxel_data;
sf::Vector3i dimensions;
void set_voxel(sf::Vector3i position, int val);
double sample(int x, int y);
void set_sample(int x, int y, double value);
void sample_square(int x, int y, int size, double value);
void sample_diamond(int x, int y, int size, double value);
void diamond_square(int stepsize, double scale);
};