aboutsummaryrefslogtreecommitdiff
path: root/src/raycast.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/raycast.cpp')
-rw-r--r--src/raycast.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/raycast.cpp b/src/raycast.cpp
index 58102c993..42cc22587 100644
--- a/src/raycast.cpp
+++ b/src/raycast.cpp
@@ -17,11 +17,47 @@ 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;
+ } else 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);
+ else
+ 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);