nav_agent.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /**************************************************************************/
  2. /* nav_agent.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 NAV_AGENT_H
  31. #define NAV_AGENT_H
  32. #include "nav_rid.h"
  33. #include "core/object/class_db.h"
  34. #include "core/templates/local_vector.h"
  35. #include <Agent2d.h>
  36. #include <Agent3d.h>
  37. class NavMap;
  38. class NavAgent : public NavRid {
  39. Vector3 position;
  40. Vector3 target_position;
  41. Vector3 velocity;
  42. Vector3 velocity_forced;
  43. real_t height = 1.0;
  44. real_t radius = 1.0;
  45. real_t max_speed = 1.0;
  46. real_t time_horizon_agents = 1.0;
  47. real_t time_horizon_obstacles = 0.0;
  48. int max_neighbors = 5;
  49. real_t neighbor_distance = 5.0;
  50. Vector3 safe_velocity;
  51. bool clamp_speed = true; // Experimental, clamps velocity to max_speed.
  52. NavMap *map = nullptr;
  53. RVO2D::Agent2D rvo_agent_2d;
  54. RVO3D::Agent3D rvo_agent_3d;
  55. bool use_3d_avoidance = false;
  56. bool avoidance_enabled = false;
  57. uint32_t avoidance_layers = 1;
  58. uint32_t avoidance_mask = 1;
  59. real_t avoidance_priority = 1.0;
  60. Callable avoidance_callback;
  61. bool agent_dirty = true;
  62. uint32_t last_map_iteration_id = 0;
  63. bool paused = false;
  64. public:
  65. NavAgent();
  66. void set_avoidance_enabled(bool p_enabled);
  67. bool is_avoidance_enabled() { return avoidance_enabled; }
  68. void set_use_3d_avoidance(bool p_enabled);
  69. bool get_use_3d_avoidance() { return use_3d_avoidance; }
  70. void set_map(NavMap *p_map);
  71. NavMap *get_map() { return map; }
  72. bool is_map_changed();
  73. RVO2D::Agent2D *get_rvo_agent_2d() { return &rvo_agent_2d; }
  74. RVO3D::Agent3D *get_rvo_agent_3d() { return &rvo_agent_3d; }
  75. void set_avoidance_callback(Callable p_callback);
  76. bool has_avoidance_callback() const;
  77. void dispatch_avoidance_callback();
  78. void set_neighbor_distance(real_t p_neighbor_distance);
  79. real_t get_neighbor_distance() const { return neighbor_distance; }
  80. void set_max_neighbors(int p_max_neighbors);
  81. int get_max_neighbors() const { return max_neighbors; }
  82. void set_time_horizon_agents(real_t p_time_horizon);
  83. real_t get_time_horizon_agents() const { return time_horizon_agents; }
  84. void set_time_horizon_obstacles(real_t p_time_horizon);
  85. real_t get_time_horizon_obstacles() const { return time_horizon_obstacles; }
  86. void set_radius(real_t p_radius);
  87. real_t get_radius() const { return radius; }
  88. void set_height(real_t p_height);
  89. real_t get_height() const { return height; }
  90. void set_max_speed(real_t p_max_speed);
  91. real_t get_max_speed() const { return max_speed; }
  92. void set_position(const Vector3 p_position);
  93. const Vector3 &get_position() const { return position; }
  94. void set_target_position(const Vector3 p_target_position);
  95. const Vector3 &get_target_position() const { return target_position; }
  96. void set_velocity(const Vector3 p_velocity);
  97. const Vector3 &get_velocity() const { return velocity; }
  98. void set_velocity_forced(const Vector3 p_velocity);
  99. const Vector3 &get_velocity_forced() const { return velocity_forced; }
  100. void set_avoidance_layers(uint32_t p_layers);
  101. uint32_t get_avoidance_layers() const { return avoidance_layers; }
  102. void set_avoidance_mask(uint32_t p_mask);
  103. uint32_t get_avoidance_mask() const { return avoidance_mask; }
  104. void set_avoidance_priority(real_t p_priority);
  105. real_t get_avoidance_priority() const { return avoidance_priority; }
  106. void set_paused(bool p_paused);
  107. bool get_paused() const;
  108. bool check_dirty();
  109. // Updates this agent with rvo data after the rvo simulation avoidance step.
  110. void update();
  111. // RVO debug data from the last frame update.
  112. const Dictionary get_avoidance_data() const;
  113. private:
  114. void _update_rvo_agent_properties();
  115. };
  116. #endif // NAV_AGENT_H