pointedthing.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "irrlichttypes.h"
  18. #include "irr_v3d.h"
  19. #include <iostream>
  20. #include <string>
  21. enum PointedThingType
  22. {
  23. POINTEDTHING_NOTHING,
  24. POINTEDTHING_NODE,
  25. POINTEDTHING_OBJECT
  26. };
  27. //! An active object or node which is selected by a ray on the map.
  28. struct PointedThing
  29. {
  30. //! The type of the pointed object.
  31. PointedThingType type = POINTEDTHING_NOTHING;
  32. /*!
  33. * Only valid if type is POINTEDTHING_NODE.
  34. * The coordinates of the node which owns the
  35. * nodebox that the ray hits first.
  36. * This may differ from node_real_undersurface if
  37. * a nodebox exceeds the limits of its node.
  38. */
  39. v3s16 node_undersurface;
  40. /*!
  41. * Only valid if type is POINTEDTHING_NODE.
  42. * The coordinates of the last node the ray intersects
  43. * before node_undersurface. Same as node_undersurface
  44. * if the ray starts in a nodebox.
  45. */
  46. v3s16 node_abovesurface;
  47. /*!
  48. * Only valid if type is POINTEDTHING_NODE.
  49. * The coordinates of the node which contains the
  50. * point of the collision and the nodebox of the node.
  51. */
  52. v3s16 node_real_undersurface;
  53. /*!
  54. * Only valid if type is POINTEDTHING_OBJECT.
  55. * The ID of the object the ray hit.
  56. */
  57. s16 object_id = -1;
  58. /*!
  59. * Only valid if type isn't POINTEDTHING_NONE.
  60. * First intersection point of the ray and the nodebox.
  61. */
  62. v3f intersection_point;
  63. /*!
  64. * Only valid if type isn't POINTEDTHING_NONE.
  65. * Normal vector of the intersection.
  66. * This is perpendicular to the face the ray hits,
  67. * points outside of the box and it's length is 1.
  68. */
  69. v3s16 intersection_normal;
  70. /*!
  71. * Square of the distance between the pointing
  72. * ray's start point and the intersection point.
  73. */
  74. f32 distanceSq = 0;
  75. //! Constructor for POINTEDTHING_NOTHING
  76. PointedThing() = default;
  77. //! Constructor for POINTEDTHING_NODE
  78. PointedThing(const v3s16 &under, const v3s16 &above,
  79. const v3s16 &real_under, const v3f &point, const v3s16 &normal,
  80. f32 distSq);
  81. //! Constructor for POINTEDTHING_OBJECT
  82. PointedThing(s16 id, const v3f &point, const v3s16 &normal, f32 distSq);
  83. std::string dump() const;
  84. void serialize(std::ostream &os) const;
  85. void deSerialize(std::istream &is);
  86. /*!
  87. * This function ignores the intersection point and normal.
  88. */
  89. bool operator==(const PointedThing &pt2) const;
  90. bool operator!=(const PointedThing &pt2) const;
  91. };