ray_cast.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*************************************************************************/
  2. /* ray_cast.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef RAY_CAST_H
  31. #define RAY_CAST_H
  32. #include "scene/3d/spatial.h"
  33. class RayCast : public Spatial {
  34. GDCLASS(RayCast, Spatial);
  35. bool enabled;
  36. bool collided;
  37. ObjectID against;
  38. int against_shape;
  39. Vector3 collision_point;
  40. Vector3 collision_normal;
  41. Vector3 cast_to;
  42. Set<RID> exclude;
  43. uint32_t collision_mask;
  44. bool exclude_parent_body;
  45. Node *debug_shape;
  46. Ref<Material> debug_material;
  47. Color debug_shape_custom_color = Color(0.0, 0.0, 0.0);
  48. int debug_shape_thickness = 2;
  49. Vector<Vector3> debug_shape_vertices;
  50. Vector<Vector3> debug_line_vertices;
  51. void _create_debug_shape();
  52. void _update_debug_shape();
  53. void _update_debug_shape_material(bool p_check_collision = false);
  54. void _update_debug_shape_vertices();
  55. void _clear_debug_shape();
  56. bool collide_with_areas;
  57. bool collide_with_bodies;
  58. protected:
  59. void _notification(int p_what);
  60. void _update_raycast_state();
  61. static void _bind_methods();
  62. public:
  63. void set_collide_with_areas(bool p_clip);
  64. bool is_collide_with_areas_enabled() const;
  65. void set_collide_with_bodies(bool p_clip);
  66. bool is_collide_with_bodies_enabled() const;
  67. void set_enabled(bool p_enabled);
  68. bool is_enabled() const;
  69. void set_cast_to(const Vector3 &p_point);
  70. Vector3 get_cast_to() const;
  71. void set_collision_mask(uint32_t p_mask);
  72. uint32_t get_collision_mask() const;
  73. void set_collision_mask_bit(int p_bit, bool p_value);
  74. bool get_collision_mask_bit(int p_bit) const;
  75. void set_exclude_parent_body(bool p_exclude_parent_body);
  76. bool get_exclude_parent_body() const;
  77. const Color &get_debug_shape_custom_color() const;
  78. void set_debug_shape_custom_color(const Color &p_color);
  79. const Vector<Vector3> &get_debug_shape_vertices() const;
  80. const Vector<Vector3> &get_debug_line_vertices() const;
  81. Ref<SpatialMaterial> get_debug_material();
  82. int get_debug_shape_thickness() const;
  83. void set_debug_shape_thickness(const int p_debug_thickness);
  84. void force_raycast_update();
  85. bool is_colliding() const;
  86. Object *get_collider() const;
  87. int get_collider_shape() const;
  88. Vector3 get_collision_point() const;
  89. Vector3 get_collision_normal() const;
  90. void add_exception_rid(const RID &p_rid);
  91. void add_exception(const Object *p_object);
  92. void remove_exception_rid(const RID &p_rid);
  93. void remove_exception(const Object *p_object);
  94. void clear_exceptions();
  95. RayCast();
  96. };
  97. #endif // RAY_CAST_H