Added lookat function. Fixed various coordinate missmatches and issues. Fixed camera movement. Added some input functions. I need some way to log fps and find those hitches
This commit is contained in:
@@ -18,9 +18,13 @@ public:
|
||||
int add_relative_impulse(DIRECTION direction, float speed);
|
||||
|
||||
int slew_camera(sf::Vector2f input);
|
||||
void set_camera(sf::Vector2f input);
|
||||
void set_camera(sf::Vector3f input);
|
||||
|
||||
int update(double delta_time);
|
||||
|
||||
void look_at_center();
|
||||
|
||||
sf::Vector2f* get_direction_pointer();
|
||||
sf::Vector3f* get_position_pointer();
|
||||
sf::Vector3f* get_movement_pointer();
|
||||
|
||||
@@ -19,36 +19,28 @@
|
||||
#define CHUNK_DIM 32
|
||||
#define OCT_DIM 64
|
||||
|
||||
struct KeyHasher {
|
||||
struct XYZHasher {
|
||||
std::size_t operator()(const sf::Vector3i& k) const {
|
||||
|
||||
return ((std::hash<int>()(k.x)
|
||||
^ (std::hash<int>()(k.y) << 1)) >> 1)
|
||||
^ (std::hash<int>()(k.z) << 1);
|
||||
}
|
||||
};
|
||||
|
||||
struct Chunk {
|
||||
Chunk(int type) { voxel_data = new int[CHUNK_DIM * CHUNK_DIM * CHUNK_DIM]; set(type); };
|
||||
Chunk() { };
|
||||
void set(int type);
|
||||
~Chunk() { voxel_data = nullptr; };
|
||||
int* voxel_data;
|
||||
};
|
||||
|
||||
class Octree {
|
||||
|
||||
public:
|
||||
Octree() {
|
||||
dat = new uint64_t[(int)pow(2, 15)];
|
||||
for (int i = 0; i < (int)pow(2, 15); i++) {
|
||||
dat[i] = 0;
|
||||
|
||||
// initialize the first stack block
|
||||
stack.push_back(new uint64_t[0x8000]);
|
||||
for (int i = 0; i < 0x8000; i++) {
|
||||
stack.back() = 0;
|
||||
}
|
||||
};
|
||||
|
||||
~Octree() {};
|
||||
|
||||
uint64_t *dat;
|
||||
std::list<uint64_t*> stack;
|
||||
uint64_t stack_pos = 0x8000;
|
||||
uint64_t global_pos = 0;
|
||||
|
||||
@@ -65,7 +57,7 @@ public:
|
||||
|
||||
// Check for the far bit
|
||||
|
||||
memcpy(&dat[stack_pos + global_pos], children.data(), children.size() * sizeof(uint64_t));
|
||||
memcpy(&stack.front()[stack_pos + global_pos], children.data(), children.size() * sizeof(uint64_t));
|
||||
|
||||
// Return the bitmask encoding the index of that value
|
||||
// If we tripped the far bit, allocate a far index to the stack and place
|
||||
@@ -76,6 +68,17 @@ public:
|
||||
return stack_pos;
|
||||
};
|
||||
|
||||
void print_block(int block_pos) {
|
||||
std::stringstream sss;
|
||||
for (int i = 0; i < (int)pow(2, 15); i++) {
|
||||
PrettyPrintUINT64(stack.front()[i], &sss);
|
||||
sss << "\n";
|
||||
}
|
||||
DumpLog(&sss, "raw_data.txt");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
@@ -84,6 +87,7 @@ public:
|
||||
class Map {
|
||||
public:
|
||||
|
||||
|
||||
Map(sf::Vector3i dim);
|
||||
void generate_octree();
|
||||
|
||||
@@ -118,7 +122,7 @@ private:
|
||||
char getVoxel(sf::Vector3i pos);
|
||||
char* voxel_data = new char[OCT_DIM * OCT_DIM * OCT_DIM];
|
||||
|
||||
std::unordered_map<sf::Vector3i, Chunk, KeyHasher> chunk_map;
|
||||
//std::unordered_map<sf::Vector3i, Chunk, XYZHasher> chunk_map;
|
||||
|
||||
double* height_map;
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include "Vector4.hpp"
|
||||
#include <bitset>
|
||||
#include <string>
|
||||
#include <math.h>
|
||||
#include <iterator>
|
||||
|
||||
|
||||
const double PI = 3.141592653589793238463;
|
||||
const float PI_F = 3.14159265358979f;
|
||||
@@ -125,6 +128,20 @@ inline sf::Vector3f CartToSphere(sf::Vector3f in) {
|
||||
return r;
|
||||
};
|
||||
|
||||
inline sf::Vector2f CartToNormalizedSphere(sf::Vector3f in) {
|
||||
|
||||
auto r = sf::Vector2f(
|
||||
atan2(sqrt(in.x * in.x + in.y * in.y), in.z),
|
||||
atan2(in.y, in.x)
|
||||
);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
inline sf::Vector3f FixOrigin(sf::Vector3f base, sf::Vector3f head) {
|
||||
return head - base;
|
||||
}
|
||||
|
||||
|
||||
inline sf::Vector3f Normalize(sf::Vector3f in) {
|
||||
|
||||
@@ -202,4 +219,59 @@ inline void DumpLog(std::stringstream* ss, std::string file_name) {
|
||||
|
||||
log_file.close();
|
||||
|
||||
}
|
||||
|
||||
inline std::string sfml_get_input(sf::RenderWindow *window) {
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
sf::Event event;
|
||||
while (window->pollEvent(event)) {
|
||||
if (event.type == sf::Event::TextEntered) {
|
||||
ss << event.text.unicode;
|
||||
}
|
||||
|
||||
else if (event.type == sf::Event::KeyPressed) {
|
||||
if (event.key.code == sf::Keyboard::Return) {
|
||||
return ss.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline std::vector<float> sfml_get_float_input(sf::RenderWindow *window) {
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
sf::Event event;
|
||||
while (true) {
|
||||
|
||||
if (window->pollEvent(event)) {
|
||||
|
||||
if (event.type == sf::Event::TextEntered) {
|
||||
if (event.text.unicode > 47 && event.text.unicode < 58 || event.text.unicode == 32)
|
||||
ss << static_cast<char>(event.text.unicode);
|
||||
}
|
||||
|
||||
else if (event.type == sf::Event::KeyPressed) {
|
||||
|
||||
if (event.key.code == sf::Keyboard::Return) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::istream_iterator<std::string> begin(ss);
|
||||
std::istream_iterator<std::string> end;
|
||||
std::vector<std::string> vstrings(begin, end);
|
||||
|
||||
std::vector<float> ret;
|
||||
|
||||
for (auto i: vstrings) {
|
||||
ret.push_back(std::stof(i));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user