diff options
Diffstat (limited to 'src/raycast.cpp')
-rw-r--r-- | src/raycast.cpp | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/src/raycast.cpp b/src/raycast.cpp index a1993606f..bb13e6108 100644 --- a/src/raycast.cpp +++ b/src/raycast.cpp @@ -22,8 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irr_aabb3d.h" #include "constants.h" -bool RaycastSort::operator() (const PointedThing &pt1, - const PointedThing &pt2) const +bool RaycastSort::operator()(const PointedThing &pt1, const PointedThing &pt2) const { // "nothing" can not be sorted assert(pt1.type != POINTEDTHING_NOTHING); @@ -46,30 +45,27 @@ bool RaycastSort::operator() (const PointedThing &pt1, if (pt1_distSq == 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.object_id < pt2.object_id); - return (pt2.type == POINTEDTHING_OBJECT - || pt1.node_undersurface < pt2.node_undersurface); + 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, bool nodes_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), - m_nodes_pointable(nodes_pointable) +RaycastState::RaycastState(const core::line3d<f32> &shootline, bool objects_pointable, + bool liquids_pointable, bool nodes_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), m_nodes_pointable(nodes_pointable) { } - -bool boxLineCollision(const aabb3f &box, const v3f &start, - const v3f &dir, v3f *collision_point, v3s16 *collision_normal) +bool boxLineCollision(const aabb3f &box, const v3f &start, const v3f &dir, + v3f *collision_point, v3s16 *collision_normal) { if (box.isPointInside(start)) { *collision_point = start; @@ -87,10 +83,10 @@ bool boxLineCollision(const aabb3f &box, const v3f &start, if (m >= 0 && m <= 1) { *collision_point = start + dir * m; - if ((collision_point->Y >= box.MinEdge.Y) - && (collision_point->Y <= box.MaxEdge.Y) - && (collision_point->Z >= box.MinEdge.Z) - && (collision_point->Z <= box.MaxEdge.Z)) { + if ((collision_point->Y >= box.MinEdge.Y) && + (collision_point->Y <= box.MaxEdge.Y) && + (collision_point->Z >= box.MinEdge.Z) && + (collision_point->Z <= box.MaxEdge.Z)) { collision_normal->set((dir.X > 0) ? -1 : 1, 0, 0); return true; } @@ -106,10 +102,10 @@ bool boxLineCollision(const aabb3f &box, const v3f &start, if (m >= 0 && m <= 1) { *collision_point = start + dir * m; - if ((collision_point->X >= box.MinEdge.X) - && (collision_point->X <= box.MaxEdge.X) - && (collision_point->Z >= box.MinEdge.Z) - && (collision_point->Z <= box.MaxEdge.Z)) { + if ((collision_point->X >= box.MinEdge.X) && + (collision_point->X <= box.MaxEdge.X) && + (collision_point->Z >= box.MinEdge.Z) && + (collision_point->Z <= box.MaxEdge.Z)) { collision_normal->set(0, (dir.Y > 0) ? -1 : 1, 0); return true; } @@ -125,10 +121,10 @@ bool boxLineCollision(const aabb3f &box, const v3f &start, if (m >= 0 && m <= 1) { *collision_point = start + dir * m; - if ((collision_point->X >= box.MinEdge.X) - && (collision_point->X <= box.MaxEdge.X) - && (collision_point->Y >= box.MinEdge.Y) - && (collision_point->Y <= box.MaxEdge.Y)) { + if ((collision_point->X >= box.MinEdge.X) && + (collision_point->X <= box.MaxEdge.X) && + (collision_point->Y >= box.MinEdge.Y) && + (collision_point->Y <= box.MaxEdge.Y)) { collision_normal->set(0, 0, (dir.Z > 0) ? -1 : 1); return true; } |