Debian Codegraph @

modules/navigation_3d/nav_agent_3d.h

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