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:
@@ -23,13 +23,14 @@
|
||||
|
||||
#include "util.hpp"
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "map/Old_Map.h"
|
||||
#include "CLCaster.h"
|
||||
#include "Camera.h"
|
||||
#include "Input.h"
|
||||
#include "LightController.h"
|
||||
#include "LightHandle.h"
|
||||
#include "map/Map.h"
|
||||
#include <chrono>
|
||||
#include "imgui/imgui-SFML.h"
|
||||
|
||||
// Srsly people who macro error codes are the devil
|
||||
#undef ERROR
|
||||
@@ -41,9 +42,9 @@ public:
|
||||
const int WINDOW_X = 1600;
|
||||
const int WINDOW_Y = 900;
|
||||
|
||||
const int MAP_X = 256;
|
||||
const int MAP_Y = 256;
|
||||
const int MAP_Z = 256;
|
||||
const int MAP_X = 64;
|
||||
const int MAP_Y = 64;
|
||||
const int MAP_Z = 64;
|
||||
|
||||
Application();
|
||||
~Application();
|
||||
@@ -62,8 +63,7 @@ private:
|
||||
sf::Texture spritesheet;
|
||||
|
||||
std::shared_ptr<sf::RenderWindow> window;
|
||||
std::shared_ptr<Old_Map> map;
|
||||
std::shared_ptr<Map> octree;
|
||||
std::shared_ptr<Map> map;
|
||||
std::shared_ptr<Camera> camera;
|
||||
std::shared_ptr<CLCaster> raycaster;
|
||||
std::shared_ptr<LightHandle> light_handle;
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <map>
|
||||
#include <string.h>
|
||||
#include "LightController.h"
|
||||
#include "map/Old_Map.h"
|
||||
#include "Camera.h"
|
||||
#include <GL/glew.h>
|
||||
#include <unordered_map>
|
||||
@@ -115,11 +114,11 @@ public:
|
||||
bool assign_lights(std::vector<PackedData> *data) ;
|
||||
|
||||
// We take a ptr to the map and create the map, and map_dimensions buffer for the GPU
|
||||
bool assign_map(std::shared_ptr<Old_Map> map);
|
||||
bool assign_map(std::shared_ptr<Map> map);
|
||||
bool release_map();
|
||||
|
||||
// We take a ptr to the map and create the map, and map_dimensions buffer for the GPU
|
||||
bool assign_octree(std::shared_ptr<Map> octree);
|
||||
bool assign_octree(std::shared_ptr<Map> map);
|
||||
bool release_octree();
|
||||
|
||||
// We take a ptr to the camera and create a camera direction and position buffer
|
||||
@@ -287,8 +286,7 @@ private:
|
||||
sf::Vector2i viewport_resolution;
|
||||
|
||||
std::shared_ptr<Camera> camera;
|
||||
std::shared_ptr<Old_Map> map;
|
||||
std::shared_ptr<Map> octree;
|
||||
std::shared_ptr<Map> map;
|
||||
|
||||
std::vector<PackedData> *lights;
|
||||
int light_count = 0;
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
private:
|
||||
|
||||
float friction_coefficient = 0.1f;
|
||||
float default_impulse = 1.0f;
|
||||
float default_impulse = 0.3f;
|
||||
|
||||
// 3D vector
|
||||
sf::Vector3f movement;
|
||||
|
||||
35
include/map/ArrayMap.h
Normal file
35
include/map/ArrayMap.h
Normal 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;
|
||||
|
||||
};
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user