From 45b52f6d5a7c8389da8f4cb5c5294a430255a248 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Fri, 26 Oct 2018 19:23:33 +0200 Subject: Ease selection of entities behind nodes (#7739) --- src/raycast.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/raycast.cpp') 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 -- cgit v1.2.3