aboutsummaryrefslogtreecommitdiff
path: root/src/environment.cpp
diff options
context:
space:
mode:
authorLars Müller <34514239+appgurueu@users.noreply.github.com>2022-10-30 16:53:14 +0100
committerGitHub <noreply@github.com>2022-10-30 16:53:14 +0100
commit077627181ee2eac3c0dacc3d8dc49825837e474c (patch)
treea8a6298198738f2edb30bd7e733a7a0d2005affa /src/environment.cpp
parentb8292319924994352d56d6111faa73fe315d149a (diff)
downloadminetest-077627181ee2eac3c0dacc3d8dc49825837e474c.tar.xz
Allow rotating entity selectionboxes (#12379)
Diffstat (limited to 'src/environment.cpp')
-rw-r--r--src/environment.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index b04f77557..514b15d01 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -202,21 +202,21 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result)
// ID of the current box (loop counter)
u16 id = 0;
+ // Do calculations relative to the node center
+ // to translate the ray rather than the boxes
v3f npf = intToFloat(np, BS);
- // This loop translates the boxes to their in-world place.
+ v3f rel_start = state->m_shootline.start - npf;
for (aabb3f &box : boxes) {
- box.MinEdge += npf;
- box.MaxEdge += npf;
-
v3f intersection_point;
- v3s16 intersection_normal;
- if (!boxLineCollision(box, state->m_shootline.start,
+ v3f intersection_normal;
+ if (!boxLineCollision(box, rel_start,
state->m_shootline.getVector(), &intersection_point,
&intersection_normal)) {
++id;
continue;
}
+ intersection_point += npf; // translate back to world coords
f32 distanceSq = (intersection_point
- state->m_shootline.start).getLengthSQ();
// If this is the nearest collision, save it
@@ -259,7 +259,7 @@ void Environment::continueRaycast(RaycastState *state, PointedThing *result)
result.node_real_undersurface = floatToInt(
fake_intersection, BS);
result.node_abovesurface = result.node_real_undersurface
- + result.intersection_normal;
+ + floatToInt(result.intersection_normal, 1.0f);
// Push found PointedThing
state->m_found.push(result);
// If this is nearer than the old nearest object,