fix rotated aabb blocking check & refactor PlayerController

This commit is contained in:
MihailRis 2024-11-05 03:15:11 +03:00
parent 4b63bedde4
commit d15624cd47
3 changed files with 6 additions and 7 deletions

View File

@ -41,6 +41,7 @@ std::unique_ptr<Content> ContentBuilder::build() {
def.rt.hitboxes[i].reserve(def.hitboxes.size()); def.rt.hitboxes[i].reserve(def.hitboxes.size());
for (AABB aabb : def.hitboxes) { for (AABB aabb : def.hitboxes) {
def.rotations.variants[i].transform(aabb); def.rotations.variants[i].transform(aabb);
aabb.fix();
def.rt.hitboxes[i].push_back(aabb); def.rt.hitboxes[i].push_back(aabb);
} }
} }

View File

@ -429,7 +429,7 @@ void PlayerController::processRightClick(const Block& def, const Block& target)
return; return;
} }
} }
auto coord = selection.actualPosition; glm::ivec3 coord = selection.actualPosition;
if (!target.replaceable) { if (!target.replaceable) {
coord += selection.normal; coord += selection.normal;
} else if (def.rotations.name == BlockRotProfile::PIPE_NAME) { } else if (def.rotations.name == BlockRotProfile::PIPE_NAME) {
@ -437,12 +437,10 @@ void PlayerController::processRightClick(const Block& def, const Block& target)
} }
blockid_t chosenBlock = def.rt.id; blockid_t chosenBlock = def.rt.id;
if (def.obstacle) { if (def.obstacle) {
std::vector<AABB> hitboxes = def.rotatable ? def.rt.hitboxes[state.rotation] : def.hitboxes; const auto& hitboxes = def.rt.hitboxes[state.rotation];
for (AABB blockAABB : hitboxes) { for (const AABB& blockAABB : hitboxes) {
bool blocked = level->entities->hasBlockingInside(blockAABB.move(coord)); if (level->entities->hasBlockingInside(blockAABB.translated(coord))) {
if (blocked) {
return; return;
} }
} }

View File

@ -34,7 +34,7 @@ struct AABB {
return (a + b) * 0.5f; return (a + b) * 0.5f;
} }
inline AABB move(glm::vec3 pos) const { inline AABB translated(const glm::vec3& pos) const {
return AABB(a + pos, b + pos); return AABB(a + pos, b + pos);
} }