AABB blocks rotation support (WIP part 3)
This commit is contained in:
@@ -30,4 +30,5 @@ Block::Block(std::string name)
|
||||
|
||||
Block::Block(std::string name, std::string texture) : name(name),
|
||||
textureFaces{texture,texture,texture,texture,texture,texture} {
|
||||
rotations = BlockRotProfile::PIPE;
|
||||
}
|
||||
|
||||
+3
-2
@@ -28,7 +28,8 @@ struct CoordSystem {
|
||||
};
|
||||
|
||||
struct BlockRotProfile {
|
||||
CoordSystem variants[16];
|
||||
static const int MAX_COUNT = 16;
|
||||
CoordSystem variants[MAX_COUNT];
|
||||
|
||||
/* Wood logs, pillars, pipes
|
||||
3 orientations supported
|
||||
@@ -65,7 +66,7 @@ public:
|
||||
blockid_t id;
|
||||
bool solid = true;
|
||||
bool emissive = false;
|
||||
bool hitboxGrid[BLOCK_AABB_GRID][BLOCK_AABB_GRID][BLOCK_AABB_GRID];
|
||||
AABB hitboxes[BlockRotProfile::MAX_COUNT];
|
||||
} rt;
|
||||
|
||||
Block(std::string name);
|
||||
|
||||
@@ -73,11 +73,14 @@ const AABB* Chunks::isObstacle(float x, float y, float z){
|
||||
return nullptr;
|
||||
const Block* def = contentIds->getBlockDef(v->id);
|
||||
if (def->obstacle) {
|
||||
const AABB& hitbox = def->rotatable
|
||||
? def->rt.hitboxes[v->states & BLOCK_ROT_MASK]
|
||||
: def->hitbox;
|
||||
if (def->rt.solid) {
|
||||
return &def->hitbox;
|
||||
return &hitbox;
|
||||
} else {
|
||||
if (def->hitbox.inside({x - ix, y - iy, z - iz}))
|
||||
return &def->hitbox;
|
||||
if (hitbox.inside({x - ix, y - iy, z - iz}))
|
||||
return &hitbox;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -222,7 +225,7 @@ voxel* Chunks::rayCast(vec3 start,
|
||||
// TODO: replace this dumb solution with something better
|
||||
if (def && !def->rt.solid) {
|
||||
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;
|
||||
iend = vec3(ix, iy, iz);
|
||||
end -= iend;
|
||||
|
||||
Reference in New Issue
Block a user