]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/raycast.cpp
Code modernization: src/p*, src/q*, src/r*, src/s* (partial) (#6282)
[dragonfireclient.git] / src / raycast.cpp
index 58102c9936b850ac1771fd356f703425607faebf..2dbebd83b76a334313d62ade5f48492ad4d516fe 100644 (file)
@@ -17,11 +17,49 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include "raycast.h"
 #include "irr_v3d.h"
 #include "irr_aabb3d.h"
+#include "constants.h"
+
+bool RaycastSort::operator() (const PointedThing &pt1,
+       const PointedThing &pt2) const
+{
+       // "nothing" can not be sorted
+       assert(pt1.type != POINTEDTHING_NOTHING);
+       assert(pt2.type != POINTEDTHING_NOTHING);
+       // returns false if pt1 is nearer than pt2
+       if (pt1.distanceSq < pt2.distanceSq) {
+               return false;
+       }
+
+       if (pt1.distanceSq == pt2.distanceSq) {
+               // Sort them to allow only one order
+               if (pt1.type == POINTEDTHING_OBJECT)
+                       return (pt2.type == POINTEDTHING_OBJECT
+                               && pt1.object_id < pt2.object_id);
+
+               return (pt2.type == POINTEDTHING_OBJECT
+                               || pt1.node_undersurface < pt2.node_undersurface);
+       }
+       return true;
+}
+
+
+RaycastState::RaycastState(const core::line3d<f32> &shootline,
+       bool objects_pointable, bool liquids_pointable) :
+       m_shootline(shootline),
+       m_iterator(shootline.start / BS, shootline.getVector() / BS),
+       m_previous_node(m_iterator.m_current_node_pos),
+       m_objects_pointable(objects_pointable),
+       m_liquids_pointable(liquids_pointable)
+{
+}
+
 
 bool boxLineCollision(const aabb3f &box, const v3f &start,
-               const v3f &dir, v3f *collision_point, v3s16 *collision_normal) {
+       const v3f &dir, v3f *collision_point, v3s16 *collision_normal)
+{
        if (box.isPointInside(start)) {
                *collision_point = start;
                collision_normal->set(0, 0, 0);