]> git.lizzy.rs Git - dragonfireclient.git/blob - src/util/pointedthing.h
Update embedded jsoncpp from unk version to 0.10.6 + move libs to lib/ instead of...
[dragonfireclient.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 #ifndef UTIL_POINTEDTHING_HEADER
21 #define UTIL_POINTEDTHING_HEADER
22
23 #include "../irrlichttypes.h"
24 #include "../irr_v3d.h"
25 #include <iostream>
26 #include <string>
27
28 enum PointedThingType
29 {
30         POINTEDTHING_NOTHING,
31         POINTEDTHING_NODE,
32         POINTEDTHING_OBJECT
33 };
34
35 //! An active object or node which is selected by a ray on the map.
36 struct PointedThing
37 {
38         //! The type of the pointed object.
39         PointedThingType type;
40         /*!
41          * Only valid if type is POINTEDTHING_NODE.
42          * The coordinates of the node which owns the
43          * nodebox that the ray hits first.
44          * This may differ from node_real_undersurface if
45          * a nodebox exceeds the limits of its node.
46          */
47         v3s16 node_undersurface;
48         /*!
49          * Only valid if type is POINTEDTHING_NODE.
50          * The coordinates of the last node the ray intersects
51          * before node_undersurface. Same as node_undersurface
52          * if the ray starts in a nodebox.
53          */
54         v3s16 node_abovesurface;
55         /*!
56          * Only valid if type is POINTEDTHING_NODE.
57          * The coordinates of the node which contains the
58          * point of the collision and the nodebox of the node.
59          */
60         v3s16 node_real_undersurface;
61         /*!
62          * Only valid if type isn't POINTEDTHING_NONE.
63          * First intersection point of the ray and the nodebox.
64          */
65         v3f intersection_point;
66         /*!
67          * Only valid if type isn't POINTEDTHING_NONE.
68          * Normal vector of the intersection.
69          * This is perpendicular to the face the ray hits,
70          * points outside of the box and it's length is 1.
71          */
72         v3s16 intersection_normal;
73         /*!
74          * Only valid if type is POINTEDTHING_OBJECT.
75          * The ID of the object the ray hit.
76          */
77         s16 object_id;
78
79         PointedThing();
80         std::string dump() const;
81         void serialize(std::ostream &os) const;
82         void deSerialize(std::istream &is);
83         /*!
84          * This function ignores the intersection point and normal.
85          */
86         bool operator==(const PointedThing &pt2) const;
87         bool operator!=(const PointedThing &pt2) const;
88 };
89
90 #endif
91