]> git.lizzy.rs Git - dragonfireclient.git/blob - src/raycast.h
Merge pull request #59 from PrairieAstronomer/readme_irrlicht_change
[dragonfireclient.git] / src / raycast.h
1 /*
2 Minetest
3 Copyright (C) 2016 juhdanad, Daniel Juhasz <juhdanad@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #pragma once
21
22 #include "voxelalgorithms.h"
23 #include "util/pointedthing.h"
24
25 //! Sorts PointedThings based on their distance.
26 struct RaycastSort
27 {
28         bool operator() (const PointedThing &pt1, const PointedThing &pt2) const;
29 };
30
31 //! Describes the state of a raycast.
32 class RaycastState
33 {
34 public:
35         /*!
36          * Creates a raycast.
37          * @param objects_pointable if false, only nodes will be found
38          * @param liquids pointable if false, liquid nodes won't be found
39          */
40         RaycastState(const core::line3d<f32> &shootline, bool objects_pointable,
41                 bool liquids_pointable, bool nodes_pointable = true);
42
43         //! Shootline of the raycast.
44         core::line3d<f32> m_shootline;
45         //! Iterator to store the progress of the raycast.
46         voxalgo::VoxelLineIterator m_iterator;
47         //! Previous tested node during the raycast.
48         v3s16 m_previous_node;
49
50         /*!
51          * This priority queue stores the found pointed things
52          * waiting to be returned.
53          */
54         std::priority_queue<PointedThing, std::vector<PointedThing>, RaycastSort> m_found;
55
56         bool m_objects_pointable;
57         bool m_liquids_pointable;
58         bool m_nodes_pointable;
59
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 };
62
63         //! If true, the Environment will initialize this state.
64         bool m_initialization_needed = true;
65 };
66
67 /*!
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
76  */
77 bool boxLineCollision(const aabb3f &box, const v3f &start, const v3f &dir,
78         v3f *collision_point, v3s16 *collision_normal);