mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-10 21:41:50 +00:00
fix extended blocks collision detection
This commit is contained in:
parent
0a34f9b767
commit
c8e884009b
5 changed files with 40 additions and 26 deletions
|
|
@ -214,6 +214,6 @@ void GlobalChunks::putChunk(std::shared_ptr<Chunk> chunk) {
|
|||
chunksMap[keyfrom(chunk->x, chunk->z)] = std::move(chunk);
|
||||
}
|
||||
|
||||
const AABB* GlobalChunks::isObstacleAt(float x, float y, float z, const AABB& aabb) const {
|
||||
std::optional<AABB> GlobalChunks::isObstacleAt(float x, float y, float z, const AABB& aabb) const {
|
||||
return blocks_agent::is_obstacle_at(*this, x, y, z, aabb);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <unordered_map>
|
||||
|
||||
#define GLM_ENABLE_EXPERIMENTAL
|
||||
|
|
@ -57,7 +58,7 @@ public:
|
|||
|
||||
void putChunk(std::shared_ptr<Chunk> chunk);
|
||||
|
||||
const AABB* isObstacleAt(float x, float y, float z, const AABB& aabb) const;
|
||||
std::optional<AABB> isObstacleAt(float x, float y, float z, const AABB& aabb) const;
|
||||
|
||||
inline Chunk* getChunk(int cx, int cz) const {
|
||||
const auto& found = chunksMap.find(keyfrom(cx, cz));
|
||||
|
|
|
|||
|
|
@ -460,22 +460,21 @@ void get_voxels(const Chunks& chunks, VoxelsVolume* volume, bool backlight=false
|
|||
void get_voxels(const GlobalChunks& chunks, VoxelsVolume* volume, bool backlight=false);
|
||||
|
||||
template <class Storage>
|
||||
inline const AABB* is_obstacle_at(const Storage& chunks, float x, float y, float z, const AABB& aabb) {
|
||||
inline std::optional<AABB> is_obstacle_at(const Storage& chunks, float x, float y, float z, const AABB& aabb) {
|
||||
int ix = std::floor(x);
|
||||
int iy = std::floor(y);
|
||||
int iz = std::floor(z);
|
||||
voxel* v = get(chunks, ix, iy, iz);
|
||||
if (v == nullptr) {
|
||||
if (iy >= CHUNK_H) {
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
} else {
|
||||
static const AABB empty;
|
||||
return ∅
|
||||
return AABB();
|
||||
}
|
||||
}
|
||||
const auto& def = chunks.getContentIndices().blocks.require(v->id);
|
||||
if (!def.obstacle) {
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
glm::ivec3 offset {};
|
||||
if (v->state.segment) {
|
||||
|
|
@ -487,14 +486,14 @@ inline const AABB* is_obstacle_at(const Storage& chunks, float x, float y, float
|
|||
|
||||
for (const auto& hitbox : boxes) {
|
||||
if (hitbox.intersects(aabb - glm::ivec3(ix, iy, iz))) {
|
||||
return &hitbox;
|
||||
return hitbox + offset;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
template <class Storage>
|
||||
inline const AABB* is_obstacle_at(const Storage& chunks, float x, float y, float z) {
|
||||
inline std::optional<AABB> is_obstacle_at(const Storage& chunks, float x, float y, float z) {
|
||||
return is_obstacle_at(chunks, x, y, z, AABB({x, y, z}, {x + 1, y + 1, z + 1}));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue