]> git.lizzy.rs Git - minetest.git/blob - src/util/pointedthing.h
Fix Enter key after creating a new world (#12997)
[minetest.git] / src / util / pointedthing.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@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 "irrlichttypes.h"
23 #include "irr_v3d.h"
24 #include <iostream>
25 #include <string>
26
27 enum PointedThingType
28 {
29         POINTEDTHING_NOTHING,
30         POINTEDTHING_NODE,
31         POINTEDTHING_OBJECT
32 };
33
34 //! An active object or node which is selected by a ray on the map.
35 struct PointedThing
36 {
37         //! The type of the pointed object.
38         PointedThingType type = POINTEDTHING_NOTHING;
39         /*!
40          * Only valid if type is POINTEDTHING_NODE.
41          * The coordinates of the node which owns the
42          * nodebox that the ray hits first.
43          * This may differ from node_real_undersurface if
44          * a nodebox exceeds the limits of its node.
45          */
46         v3s16 node_undersurface;
47         /*!
48          * Only valid if type is POINTEDTHING_NODE.
49          * The coordinates of the last node the ray intersects
50          * before node_undersurface. Same as node_undersurface
51          * if the ray starts in a nodebox.
52          */
53         v3s16 node_abovesurface;
54         /*!
55          * Only valid if type is POINTEDTHING_NODE.
56          * The coordinates of the node which contains the
57          * point of the collision and the nodebox of the node.
58          */
59         v3s16 node_real_undersurface;
60         /*!
61          * Only valid if type is POINTEDTHING_OBJECT.
62          * The ID of the object the ray hit.
63          */
64         u16 object_id = 0;
65         /*!
66          * Only valid if type isn't POINTEDTHING_NONE.
67          * First intersection point of the ray and the nodebox in irrlicht
68          * coordinates.
69          */
70         v3f intersection_point;
71         /*!
72          * Only valid if type isn't POINTEDTHING_NONE.
73          * Normal vector of the intersection.
74          * This is perpendicular to the face the ray hits,
75          * points outside of the box and it's length is 1.
76          */
77         v3f intersection_normal;
78         /*!
79          * Only valid if type is POINTEDTHING_OBJECT.
80          * Raw normal vector of the intersection before applying rotation.
81          */
82         v3f raw_intersection_normal;
83         /*!
84          * Only valid if type isn't POINTEDTHING_NONE.
85          * Indicates which selection box is selected, if there are more of them.
86          */
87         u16 box_id = 0;
88         /*!
89          * Square of the distance between the pointing
90          * ray's start point and the intersection point in irrlicht coordinates.
91          */
92         f32 distanceSq = 0;
93
94         //! Constructor for POINTEDTHING_NOTHING
95         PointedThing() = default;
96         //! Constructor for POINTEDTHING_NODE
97         PointedThing(const v3s16 &under, const v3s16 &above,
98                 const v3s16 &real_under, const v3f &point, const v3f &normal,
99                 u16 box_id, f32 distSq);
100         //! Constructor for POINTEDTHING_OBJECT
101         PointedThing(u16 id, const v3f &point, const v3f &normal, const v3f &raw_normal, f32 distSq);
102         std::string dump() const;
103         void serialize(std::ostream &os) const;
104         void deSerialize(std::istream &is);
105         /*!
106          * This function ignores the intersection point and normal.
107          */
108         bool operator==(const PointedThing &pt2) const;
109         bool operator!=(const PointedThing &pt2) const;
110 };