mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 05:21:49 +00:00
blocks hitboxes physics
This commit is contained in:
parent
693ad6d9a7
commit
efacb041b5
3 changed files with 62 additions and 42 deletions
|
|
@ -64,11 +64,24 @@ voxel* Chunks::get(int x, int y, int z){
|
|||
return &chunk->voxels[(ly * CHUNK_D + lz) * CHUNK_W + lx];
|
||||
}
|
||||
|
||||
bool Chunks::isObstacle(int x, int y, int z){
|
||||
voxel* v = get(x,y,z);
|
||||
const AABB* Chunks::isObstacle(float x, float y, float z){
|
||||
int ix = floor(x);
|
||||
int iy = floor(y);
|
||||
int iz = floor(z);
|
||||
voxel* v = get(ix,iy,iz);
|
||||
if (v == nullptr)
|
||||
return true; // void - is obstacle
|
||||
return contentIds->getBlockDef(v->id)->obstacle;
|
||||
return nullptr;
|
||||
const Block* def = contentIds->getBlockDef(v->id);
|
||||
if (def->obstacle) {
|
||||
if (def->rt.solid) {
|
||||
return &def->hitbox;
|
||||
} else {
|
||||
if (def->hitbox.inside({x - ix, y - iy, z - iz}))
|
||||
return &def->hitbox;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ubyte Chunks::getLight(int x, int y, int z, int channel){
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
class VoxelRenderer;
|
||||
|
||||
class AABB;
|
||||
class Content;
|
||||
class ContentIndices;
|
||||
class Chunk;
|
||||
|
|
@ -50,7 +51,7 @@ public:
|
|||
glm::vec3& norm,
|
||||
glm::vec3& iend);
|
||||
|
||||
bool isObstacle(int x, int y, int z);
|
||||
const AABB* isObstacle(float x, float y, float z);
|
||||
|
||||
// does not move chunks inside
|
||||
void _setOffset(int x, int z);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue