diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-02-20 08:45:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-20 08:45:28 +0100 |
commit | bb13ec98f33af90232d6222c96bdb1a6a44fcfc6 (patch) | |
tree | 3c395bb4f816bb957c18904aaa0a8fbfa974f769 /scene/resources/rectangle_shape_2d.cpp | |
parent | dc1ae065578baee102d461353c757ebf2cc5cf8c (diff) | |
parent | 23a1f616fd6c1cdb60b06d4f6e2411ad8ea0f7c2 (diff) |
Merge pull request #34923 from Calinou/debug-collision-shapes-draw-outline
Draw an outline for 2D debug collision shapes
Diffstat (limited to 'scene/resources/rectangle_shape_2d.cpp')
-rw-r--r-- | scene/resources/rectangle_shape_2d.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/scene/resources/rectangle_shape_2d.cpp b/scene/resources/rectangle_shape_2d.cpp index a5b909c9a7..0fd65d8c72 100644 --- a/scene/resources/rectangle_shape_2d.cpp +++ b/scene/resources/rectangle_shape_2d.cpp @@ -33,7 +33,7 @@ #include "servers/physics_server_2d.h" #include "servers/rendering_server.h" void RectangleShape2D::_update_shape() { - PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), size / 2); + PhysicsServer2D::get_singleton()->shape_set_data(get_rid(), size * 0.5); emit_changed(); } @@ -47,11 +47,27 @@ Vector2 RectangleShape2D::get_size() const { } void RectangleShape2D::draw(const RID &p_to_rid, const Color &p_color) { - RenderingServer::get_singleton()->canvas_item_add_rect(p_to_rid, Rect2(-size / 2, size), p_color); + // Draw an outlined rectangle to make individual shapes easier to distinguish. + Vector<Vector2> stroke_points; + stroke_points.resize(5); + stroke_points.write[0] = -size * 0.5; + stroke_points.write[1] = Vector2(size.x, -size.y) * 0.5; + stroke_points.write[2] = size * 0.5; + stroke_points.write[3] = Vector2(-size.x, size.y) * 0.5; + stroke_points.write[4] = -size * 0.5; + + Vector<Color> stroke_colors; + stroke_colors.resize(5); + for (int i = 0; i < 5; i++) { + stroke_colors.write[i] = (p_color); + } + + RenderingServer::get_singleton()->canvas_item_add_rect(p_to_rid, Rect2(-size * 0.5, size), p_color); + RenderingServer::get_singleton()->canvas_item_add_polyline(p_to_rid, stroke_points, stroke_colors); } Rect2 RectangleShape2D::get_rect() const { - return Rect2(-size / 2, size); + return Rect2(-size * 0.5, size); } real_t RectangleShape2D::get_enclosing_radius() const { |