AABB block hitboxes

This commit is contained in:
MihailRis
2023-11-29 16:36:00 +03:00
parent cad1f6a669
commit 91a6426efe
7 changed files with 86 additions and 17 deletions
+20
View File
@@ -1,9 +1,11 @@
#include "Content.h"
#include <stdexcept>
#include <glm/glm.hpp>
#include "../voxels/Block.h"
using glm::vec3;
using std::vector;
using std::string;
using std::unordered_map;
@@ -21,6 +23,24 @@ Content* ContentBuilder::build() {
for (const string& name : blockIds) {
Block* def = blockDefs[name];
def->id = blockDefsIndices.size();
def->rt.emissive = *((uint32_t*)def->emission);
// build hitbox grid 3d for raycasts
const AABB& hitbox = def->hitbox;
for (uint gy = 0; gy < BLOCK_AABB_GRID; gy++) {
for (uint gz = 0; gz < BLOCK_AABB_GRID; gz++) {
for (uint gx = 0; gx < BLOCK_AABB_GRID; gx++) {
float x = gx / float(BLOCK_AABB_GRID);
float y = gy / float(BLOCK_AABB_GRID);
float z = gz / float(BLOCK_AABB_GRID);
bool flag = hitbox.inside({x, y, z});
if (!flag)
def->rt.solid = false;
def->rt.hitboxGrid[gy][gz][gx] = flag;
}
}
}
blockDefsIndices.push_back(def);
}
ContentIndices* indices = new ContentIndices(blockDefsIndices);