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