| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/2d/node_2d.h" |
| 34 |
|
| 35 |
class CollisionObject2D; |
| 36 |
|
| 37 |
class CollisionPolygon2D : public Node2D { |
| 38 |
GDCLASS(CollisionPolygon2D, Node2D); |
| 39 |
|
| 40 |
public: |
| 41 |
enum BuildMode { |
| 42 |
BUILD_SOLIDS, |
| 43 |
BUILD_SEGMENTS, |
| 44 |
}; |
| 45 |
|
| 46 |
protected: |
| 47 |
Rect2 aabb = Rect2(-10, -10, 20, 20); |
| 48 |
BuildMode build_mode = BUILD_SOLIDS; |
| 49 |
Vector<Point2> polygon; |
| 50 |
uint32_t owner_id = 0; |
| 51 |
CollisionObject2D *collision_object = nullptr; |
| 52 |
bool disabled = false; |
| 53 |
bool one_way_collision = false; |
| 54 |
real_t one_way_collision_margin = 1.0; |
| 55 |
|
| 56 |
Vector<Vector<Vector2>> _decompose_in_convex(); |
| 57 |
|
| 58 |
void _build_polygon(); |
| 59 |
|
| 60 |
void _update_in_shape_owner(bool p_xform_only = false); |
| 61 |
|
| 62 |
protected: |
| 63 |
void _notification(int p_what); |
| 64 |
static void _bind_methods(); |
| 65 |
|
| 66 |
public: |
| 67 |
#ifdef DEBUG_ENABLED |
| 68 |
virtual Rect2 _edit_get_rect() const override; |
| 69 |
virtual bool _edit_use_rect() const override; |
| 70 |
virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override; |
| 71 |
#endif |
| 72 |
|
| 73 |
void set_build_mode(BuildMode p_mode); |
| 74 |
BuildMode get_build_mode() const; |
| 75 |
|
| 76 |
void set_polygon(const Vector<Point2> &p_polygon); |
| 77 |
Vector<Point2> get_polygon() const; |
| 78 |
|
| 79 |
PackedStringArray get_configuration_warnings() const override; |
| 80 |
|
| 81 |
void set_disabled(bool p_disabled); |
| 82 |
bool is_disabled() const; |
| 83 |
|
| 84 |
void set_one_way_collision(bool p_enable); |
| 85 |
bool is_one_way_collision_enabled() const; |
| 86 |
|
| 87 |
void set_one_way_collision_margin(real_t p_margin); |
| 88 |
real_t get_one_way_collision_margin() const; |
| 89 |
|
| 90 |
CollisionPolygon2D(); |
| 91 |
}; |
| 92 |
|
| 93 |
VARIANT_ENUM_CAST(CollisionPolygon2D::BuildMode); |