navigation_obstacle_2d.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 avoidance_enabled = true;
  42. uint32_t avoidance_layers = 1;
  43. Transform2D previous_transform;
  44. Vector2 velocity;
  45. Vector2 previous_velocity;
  46. bool velocity_submitted = false;
  47. bool affect_navigation_mesh = false;
  48. bool carve_navigation_mesh = false;
  49. #ifdef DEBUG_ENABLED
  50. private:
  51. RID debug_canvas_item;
  52. void _update_fake_agent_radius_debug();
  53. void _update_static_obstacle_debug();
  54. #endif // DEBUG_ENABLED
  55. protected:
  56. static void _bind_methods();
  57. void _notification(int p_what);
  58. public:
  59. NavigationObstacle2D();
  60. virtual ~NavigationObstacle2D();
  61. RID get_rid() const { return obstacle; }
  62. void set_avoidance_enabled(bool p_enabled);
  63. bool get_avoidance_enabled() const;
  64. void set_navigation_map(RID p_navigation_map);
  65. RID get_navigation_map() const;
  66. void set_radius(real_t p_radius);
  67. real_t get_radius() const { return radius; }
  68. void set_vertices(const Vector<Vector2> &p_vertices);
  69. const Vector<Vector2> &get_vertices() const { return vertices; }
  70. void set_avoidance_layers(uint32_t p_layers);
  71. uint32_t get_avoidance_layers() const;
  72. void set_avoidance_mask(uint32_t p_mask);
  73. uint32_t get_avoidance_mask() const;
  74. void set_avoidance_layer_value(int p_layer_number, bool p_value);
  75. bool get_avoidance_layer_value(int p_layer_number) const;
  76. void set_velocity(const Vector2 p_velocity);
  77. Vector2 get_velocity() const { return velocity; }
  78. void _avoidance_done(Vector3 p_new_velocity); // Dummy
  79. void set_affect_navigation_mesh(bool p_enabled);
  80. bool get_affect_navigation_mesh() const;
  81. void set_carve_navigation_mesh(bool p_enabled);
  82. bool get_carve_navigation_mesh() const;
  83. PackedStringArray get_configuration_warnings() const override;
  84. private:
  85. void _update_map(RID p_map);
  86. void _update_position(const Vector2 p_position);
  87. void _update_transform();
  88. };
  89. #endif // NAVIGATION_OBSTACLE_2D_H