1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-17 17:08:39 +00:00

Allow rotating entity selectionboxes (#12379)

This commit is contained in:
Lars Müller 2022-10-30 16:53:14 +01:00 committed by GitHub
parent b829231992
commit 077627181e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 271 additions and 58 deletions

View file

@ -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,