Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/2d/navigation/navigation_obstacle_2d.h
9904 views
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
31
#pragma once
32
33
#include "scene/2d/node_2d.h"
34
35
class NavigationPolygon;
36
class NavigationMeshSourceGeometryData2D;
37
38
class NavigationObstacle2D : public Node2D {
39
GDCLASS(NavigationObstacle2D, Node2D);
40
41
RID obstacle;
42
RID map_before_pause;
43
RID map_override;
44
RID map_current;
45
46
real_t radius = 0.0;
47
48
Vector<Vector2> vertices;
49
bool vertices_are_clockwise = true;
50
bool vertices_are_valid = true;
51
52
bool avoidance_enabled = true;
53
uint32_t avoidance_layers = 1;
54
55
Transform2D previous_transform;
56
57
Vector2 velocity;
58
Vector2 previous_velocity;
59
bool velocity_submitted = false;
60
61
bool affect_navigation_mesh = false;
62
bool carve_navigation_mesh = false;
63
64
#ifdef DEBUG_ENABLED
65
private:
66
RID debug_canvas_item;
67
RID debug_mesh_rid;
68
69
void _update_fake_agent_radius_debug();
70
void _update_static_obstacle_debug();
71
#endif // DEBUG_ENABLED
72
73
protected:
74
static void _bind_methods();
75
void _notification(int p_what);
76
77
public:
78
NavigationObstacle2D();
79
virtual ~NavigationObstacle2D();
80
81
RID get_rid() const { return obstacle; }
82
83
void set_avoidance_enabled(bool p_enabled);
84
bool get_avoidance_enabled() const;
85
86
void set_navigation_map(RID p_navigation_map);
87
RID get_navigation_map() const;
88
89
void set_radius(real_t p_radius);
90
real_t get_radius() const { return radius; }
91
92
void set_vertices(const Vector<Vector2> &p_vertices);
93
const Vector<Vector2> &get_vertices() const { return vertices; }
94
95
bool are_vertices_clockwise() const { return vertices_are_clockwise; }
96
bool are_vertices_valid() const { return vertices_are_valid; }
97
98
void set_avoidance_layers(uint32_t p_layers);
99
uint32_t get_avoidance_layers() const;
100
101
void set_avoidance_mask(uint32_t p_mask);
102
uint32_t get_avoidance_mask() const;
103
104
void set_avoidance_layer_value(int p_layer_number, bool p_value);
105
bool get_avoidance_layer_value(int p_layer_number) const;
106
107
void set_velocity(const Vector2 p_velocity);
108
Vector2 get_velocity() const { return velocity; }
109
110
void _avoidance_done(Vector3 p_new_velocity); // Dummy
111
112
void set_affect_navigation_mesh(bool p_enabled);
113
bool get_affect_navigation_mesh() const;
114
115
void set_carve_navigation_mesh(bool p_enabled);
116
bool get_carve_navigation_mesh() const;
117
118
PackedStringArray get_configuration_warnings() const override;
119
120
private:
121
static Callable _navmesh_source_geometry_parsing_callback;
122
static RID _navmesh_source_geometry_parser;
123
124
public:
125
static void navmesh_parse_init();
126
static void navmesh_parse_source_geometry(const Ref<NavigationPolygon> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry_data, Node *p_node);
127
128
private:
129
void _update_map(RID p_map);
130
void _update_position(const Vector2 p_position);
131
void _update_transform();
132
};
133
134