3 Copyright (C) 2016 juhdanad, Daniel Juhasz <juhdanad@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef SRC_RAYCAST_H_
21 #define SRC_RAYCAST_H_
23 #include "voxelalgorithms.h"
24 #include "util/pointedthing.h"
26 //! Sorts PointedThings based on their distance.
29 bool operator() (const PointedThing &pt1, const PointedThing &pt2) const;
32 //! Describes the state of a raycast.
38 * @param objects_pointable if false, only nodes will be found
39 * @param liquids pointable if false, liquid nodes won't be found
41 RaycastState(const core::line3d<f32> &shootline, bool objects_pointable,
42 bool liquids_pointable);
44 //! Shootline of the raycast.
45 core::line3d<f32> m_shootline;
46 //! Iterator to store the progress of the raycast.
47 voxalgo::VoxelLineIterator m_iterator;
48 //! Previous tested node during the raycast.
49 v3s16 m_previous_node;
52 * This priority queue stores the found pointed things
53 * waiting to be returned.
55 std::priority_queue<PointedThing, std::vector<PointedThing>, RaycastSort> m_found;
57 bool m_objects_pointable;
58 bool m_liquids_pointable;
60 //! The code needs to search these nodes around the center node.
61 core::aabbox3d<s16> m_search_range { 0, 0, 0, 0, 0, 0 };
63 //! If true, the Environment will initialize this state.
64 bool m_initialization_needed = true;
68 * Checks if a line and a box intersects.
69 * @param[in] box box to test collision
70 * @param[in] start starting point of the line
71 * @param[in] dir direction and length of the line
72 * @param[out] collision_point first point of the collision
73 * @param[out] collision_normal normal vector at the collision, points
74 * outwards of the surface. If start is in the box, zero vector.
75 * @returns true if a collision point was found
77 bool boxLineCollision(const aabb3f &box, const v3f &start, const v3f &dir,
78 v3f *collision_point, v3s16 *collision_normal);
81 #endif /* SRC_RAYCAST_H_ */