AABB blocks rotation support (WIP part 3)
This commit is contained in:
parent
7f9e87cea2
commit
64f6f17386
@ -27,20 +27,14 @@ Content* ContentBuilder::build() {
|
|||||||
// Generating runtime info
|
// Generating runtime info
|
||||||
def->rt.id = blockDefsIndices.size();
|
def->rt.id = blockDefsIndices.size();
|
||||||
def->rt.emissive = *((uint32_t*)def->emission);
|
def->rt.emissive = *((uint32_t*)def->emission);
|
||||||
|
def->rt.solid = def->model == BlockModel::block;
|
||||||
|
|
||||||
// building hitbox grid 3d for raycasts
|
if (def->rotatable) {
|
||||||
const AABB& hitbox = def->hitbox;
|
const AABB& hitbox = def->hitbox;
|
||||||
for (uint gy = 0; gy < BLOCK_AABB_GRID; gy++) {
|
for (uint i = 0; i < BlockRotProfile::MAX_COUNT; i++) {
|
||||||
for (uint gz = 0; gz < BLOCK_AABB_GRID; gz++) {
|
AABB aabb = hitbox;
|
||||||
for (uint gx = 0; gx < BLOCK_AABB_GRID; gx++) {
|
def->rotations.variants[i].transform(aabb);
|
||||||
float x = gx / float(BLOCK_AABB_GRID);
|
def->rt.hitboxes[i] = aabb;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +42,8 @@ Content* ContentBuilder::build() {
|
|||||||
if (groups->find(def->drawGroup) == groups->end()) {
|
if (groups->find(def->drawGroup) == groups->end()) {
|
||||||
groups->insert(def->drawGroup);
|
groups->insert(def->drawGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
ContentIndices* indices = new ContentIndices(blockDefsIndices);
|
ContentIndices* indices = new ContentIndices(blockDefsIndices);
|
||||||
return new Content(indices, groups, blockDefs);
|
return new Content(indices, groups, blockDefs);
|
||||||
|
|||||||
@ -372,7 +372,6 @@ vec4 BlocksRenderer::pickSoftLight(float x, float y, float z,
|
|||||||
return pickSoftLight({int(round(x)), int(round(y)), int(round(z))}, right, up);
|
return pickSoftLight({int(round(x)), int(round(y)), int(round(z))}, right, up);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
void BlocksRenderer::render(const voxel* voxels) {
|
void BlocksRenderer::render(const voxel* voxels) {
|
||||||
int begin = chunk->bottom * (CHUNK_W * CHUNK_D);
|
int begin = chunk->bottom * (CHUNK_W * CHUNK_D);
|
||||||
int end = chunk->top * (CHUNK_W * CHUNK_D);
|
int end = chunk->top * (CHUNK_W * CHUNK_D);
|
||||||
@ -410,14 +409,9 @@ void BlocksRenderer::render(const voxel* voxels) {
|
|||||||
AABB hitbox = def.hitbox;
|
AABB hitbox = def.hitbox;
|
||||||
hitbox.a = vec3(1.0f)-hitbox.a;
|
hitbox.a = vec3(1.0f)-hitbox.a;
|
||||||
hitbox.b = vec3(1.0f)-hitbox.b;
|
hitbox.b = vec3(1.0f)-hitbox.b;
|
||||||
std::cout << hitbox.a.x << " " << hitbox.a.y << " " << hitbox.a.z << " --- ";
|
|
||||||
std::cout << hitbox.b.x << " " << hitbox.b.y << " " << hitbox.b.z << std::endl;
|
|
||||||
|
|
||||||
vec3 size = hitbox.size();
|
vec3 size = hitbox.size();
|
||||||
|
|
||||||
std::cout << "s " << size.x << " " << size.y << " " << size.z << std::endl;
|
|
||||||
vec3 off = hitbox.min();
|
vec3 off = hitbox.min();
|
||||||
std::cout << "m " << off.x << " " << off.y << " " << off.z << std::endl;
|
|
||||||
blockCubeShaded(ivec3(x,y,z), off, size, texfaces, &def, vox.states);
|
blockCubeShaded(ivec3(x,y,z), off, size, texfaces, &def, vox.states);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,4 +30,5 @@ Block::Block(std::string name)
|
|||||||
|
|
||||||
Block::Block(std::string name, std::string texture) : name(name),
|
Block::Block(std::string name, std::string texture) : name(name),
|
||||||
textureFaces{texture,texture,texture,texture,texture,texture} {
|
textureFaces{texture,texture,texture,texture,texture,texture} {
|
||||||
|
rotations = BlockRotProfile::PIPE;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,7 +28,8 @@ struct CoordSystem {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct BlockRotProfile {
|
struct BlockRotProfile {
|
||||||
CoordSystem variants[16];
|
static const int MAX_COUNT = 16;
|
||||||
|
CoordSystem variants[MAX_COUNT];
|
||||||
|
|
||||||
/* Wood logs, pillars, pipes
|
/* Wood logs, pillars, pipes
|
||||||
3 orientations supported
|
3 orientations supported
|
||||||
@ -65,7 +66,7 @@ public:
|
|||||||
blockid_t id;
|
blockid_t id;
|
||||||
bool solid = true;
|
bool solid = true;
|
||||||
bool emissive = false;
|
bool emissive = false;
|
||||||
bool hitboxGrid[BLOCK_AABB_GRID][BLOCK_AABB_GRID][BLOCK_AABB_GRID];
|
AABB hitboxes[BlockRotProfile::MAX_COUNT];
|
||||||
} rt;
|
} rt;
|
||||||
|
|
||||||
Block(std::string name);
|
Block(std::string name);
|
||||||
|
|||||||
@ -73,11 +73,14 @@ const AABB* Chunks::isObstacle(float x, float y, float z){
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
const Block* def = contentIds->getBlockDef(v->id);
|
const Block* def = contentIds->getBlockDef(v->id);
|
||||||
if (def->obstacle) {
|
if (def->obstacle) {
|
||||||
|
const AABB& hitbox = def->rotatable
|
||||||
|
? def->rt.hitboxes[v->states & BLOCK_ROT_MASK]
|
||||||
|
: def->hitbox;
|
||||||
if (def->rt.solid) {
|
if (def->rt.solid) {
|
||||||
return &def->hitbox;
|
return &hitbox;
|
||||||
} else {
|
} else {
|
||||||
if (def->hitbox.inside({x - ix, y - iy, z - iz}))
|
if (hitbox.inside({x - ix, y - iy, z - iz}))
|
||||||
return &def->hitbox;
|
return &hitbox;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,7 +225,7 @@ voxel* Chunks::rayCast(vec3 start,
|
|||||||
// TODO: replace this dumb solution with something better
|
// TODO: replace this dumb solution with something better
|
||||||
if (def && !def->rt.solid) {
|
if (def && !def->rt.solid) {
|
||||||
const int gridSize = BLOCK_AABB_GRID * 2;
|
const int gridSize = BLOCK_AABB_GRID * 2;
|
||||||
const AABB& box = def->hitbox;
|
const AABB& box = def->rotatable ? def->rt.hitboxes[voxel->states & BLOCK_ROT_MASK] : def->hitbox;
|
||||||
const int subs = gridSize;
|
const int subs = gridSize;
|
||||||
iend = vec3(ix, iy, iz);
|
iend = vec3(ix, iy, iz);
|
||||||
end -= iend;
|
end -= iend;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user