summaryrefslogtreecommitdiff
path: root/src/raycast.cpp
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2018-10-26 19:23:33 +0200
committerGitHub <noreply@github.com>2018-10-26 19:23:33 +0200
commit45b52f6d5a7c8389da8f4cb5c5294a430255a248 (patch)
tree320f25f8727aa6d3cc40de9a2d06ddbd6a82b7bd /src/raycast.cpp
parent622e2235ee700cf92843d2e99a47e36fd4508cf0 (diff)
downloadminetest-45b52f6d5a7c8389da8f4cb5c5294a430255a248.tar.gz
minetest-45b52f6d5a7c8389da8f4cb5c5294a430255a248.tar.bz2
minetest-45b52f6d5a7c8389da8f4cb5c5294a430255a248.zip
Ease selection of entities behind nodes (#7739)
Diffstat (limited to 'src/raycast.cpp')
-rw-r--r--src/raycast.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/raycast.cpp b/src/raycast.cpp
index 2dbebd83b..ebc40235d 100644
--- a/src/raycast.cpp
+++ b/src/raycast.cpp
@@ -28,12 +28,22 @@ bool RaycastSort::operator() (const PointedThing &pt1,
// "nothing" can not be sorted
assert(pt1.type != POINTEDTHING_NOTHING);
assert(pt2.type != POINTEDTHING_NOTHING);
+ f32 pt1_distSq = pt1.distanceSq;
+
+ // Add some bonus when one of them is an object
+ if (pt1.type != pt2.type) {
+ if (pt1.type == POINTEDTHING_OBJECT)
+ pt1_distSq -= BS * BS;
+ else if (pt2.type == POINTEDTHING_OBJECT)
+ pt1_distSq += BS * BS;
+ }
+
// returns false if pt1 is nearer than pt2
- if (pt1.distanceSq < pt2.distanceSq) {
+ if (pt1_distSq < pt2.distanceSq) {
return false;
}
- if (pt1.distanceSq == pt2.distanceSq) {
+ if (pt1_distSq == pt2.distanceSq) {
// Sort them to allow only one order
if (pt1.type == POINTEDTHING_OBJECT)
return (pt2.type == POINTEDTHING_OBJECT