fix: extended blocks raycast fix

This commit is contained in:
MihailRis
2024-06-09 13:48:43 +03:00
parent c89d31ca20
commit b3ae8484a2
4 changed files with 104 additions and 83 deletions
+17 -5
View File
@@ -323,9 +323,9 @@ voxel* Chunks::rayCast(
end.x = px + t * dx;
end.y = py + t * dy;
end.z = pz + t * dz;
iend.x = ix;
iend.y = iy;
iend.z = iz;
iend.x = ix;
iend.y = iy;
iend.z = iz;
if (!def->rt.solid) {
const std::vector<AABB>& hitboxes = def->rotatable
@@ -337,7 +337,14 @@ voxel* Chunks::rayCast(
bool hit = false;
for (const auto& box : hitboxes) {
glm::vec3 offset {};
if (voxel->state.segment) {
offset = seekOrigin(iend, def, voxel->state) - iend;
}
for (auto box : hitboxes) {
box.a += offset;
box.b += offset;
scalar_t boxDistance;
glm::ivec3 boxNorm;
if (ray.intersectAABB(iend, box, maxDist, boxNorm, boxDistance) > RayRelation::None && boxDistance < distance) {
@@ -446,9 +453,14 @@ glm::vec3 Chunks::rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDis
glm::ivec3 norm;
Ray ray(start, dir);
glm::ivec3 offset {};
if (voxel->state.segment) {
offset = seekOrigin({ix, iy, iz}, def, voxel->state) - glm::ivec3(ix, iy, iz);
}
for (const auto& box : hitboxes) {
// norm is dummy now, can be inefficient
if (ray.intersectAABB(glm::ivec3(ix, iy, iz), box, maxDist, norm, distance) > RayRelation::None) {
if (ray.intersectAABB(glm::ivec3(ix, iy, iz)+offset, box, maxDist, norm, distance) > RayRelation::None) {
return start + (dir * glm::vec3(distance));
}
}