navigation_obstacle_2d.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**************************************************************************/
  2. /* navigation_obstacle_2d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 NAVIGATION_OBSTACLE_2D_H
  31. #define NAVIGATION_OBSTACLE_2D_H
  32. #include "scene/2d/node_2d.h"
  33. class NavigationObstacle2D : public Node2D {
  34. GDCLASS(NavigationObstacle2D, Node2D);
  35. RID obstacle;
  36. RID map_before_pause;
  37. RID map_override;
  38. RID map_current;
  39. real_t radius = 0.0;
  40. Vector<Vector2> vertices;
  41. bool vertices_are_clockwise = true;
  42. bool vertices_are_valid = true;
  43. bool avoidance_enabled = true;
  44. uint32_t avoidance_layers = 1;
  45. Transform2D previous_transform;
  46. Vector2 velocity;
  47. Vector2 previous_velocity;
  48. bool velocity_submitted = false;
  49. bool affect_navigation_mesh = false;
  50. bool carve_navigation_mesh = false;
  51. #ifdef DEBUG_ENABLED
  52. private:
  53. RID debug_canvas_item;
  54. RID debug_mesh_rid;
  55. void _update_fake_agent_radius_debug();
  56. void _update_static_obstacle_debug();
  57. #endif // DEBUG_ENABLED
  58. protected:
  59. static void _bind_methods();
  60. void _notification(int p_what);
  61. public:
  62. NavigationObstacle2D();
  63. virtual ~NavigationObstacle2D();
  64. RID get_rid() const { return obstacle; }
  65. void set_avoidance_enabled(bool p_enabled);
  66. bool get_avoidance_enabled() const;
  67. void set_navigation_map(RID p_navigation_map);
  68. RID get_navigation_map() const;
  69. void set_radius(real_t p_radius);
  70. real_t get_radius() const { return radius; }
  71. void set_vertices(const Vector<Vector2> &p_vertices);
  72. const Vector<Vector2> &get_vertices() const { return vertices; }
  73. bool are_vertices_clockwise() const { return vertices_are_clockwise; }
  74. bool are_vertices_valid() const { return vertices_are_valid; }
  75. void set_avoidance_layers(uint32_t p_layers);
  76. uint32_t get_avoidance_layers() const;
  77. void set_avoidance_mask(uint32_t p_mask);
  78. uint32_t get_avoidance_mask() const;
  79. void set_avoidance_layer_value(int p_layer_number, bool p_value);
  80. bool get_avoidance_layer_value(int p_layer_number) const;
  81. void set_velocity(const Vector2 p_velocity);
  82. Vector2 get_velocity() const { return velocity; }
  83. void _avoidance_done(Vector3 p_new_velocity); // Dummy
  84. void set_affect_navigation_mesh(bool p_enabled);
  85. bool get_affect_navigation_mesh() const;
  86. void set_carve_navigation_mesh(bool p_enabled);
  87. bool get_carve_navigation_mesh() const;
  88. PackedStringArray get_configuration_warnings() const override;
  89. private:
  90. void _update_map(RID p_map);
  91. void _update_position(const Vector2 p_position);
  92. void _update_transform();
  93. };
  94. #endif // NAVIGATION_OBSTACLE_2D_H