diff options
| author | Marcus Elg <marcusaccounts@yahoo.se> | 2023-12-15 18:39:32 +0100 |
|---|---|---|
| committer | Marcus Elg <marcusaccounts@yahoo.se> | 2024-02-27 14:07:24 +0100 |
| commit | 8bed36e4bbefc4a0d37297e8ebbe0eb2ccc47898 (patch) | |
| tree | 96f6da0fd533c4fda01c6e1b5316f44262f5e13d | |
| parent | a586e860e5fc382dec4ad9a0bec72f7c6684f020 (diff) | |
| download | redot-engine-8bed36e4bbefc4a0d37297e8ebbe0eb2ccc47898.tar.gz | |
Improve visualisation of worldboundary2d editor
| -rw-r--r-- | scene/resources/2d/world_boundary_shape_2d.cpp | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/scene/resources/2d/world_boundary_shape_2d.cpp b/scene/resources/2d/world_boundary_shape_2d.cpp index 294653659a..574b10c448 100644 --- a/scene/resources/2d/world_boundary_shape_2d.cpp +++ b/scene/resources/2d/world_boundary_shape_2d.cpp @@ -86,10 +86,41 @@ void WorldBoundaryShape2D::draw(const RID &p_to_rid, const Color &p_color) { Vector2 point = distance * normal; real_t line_width = 3.0; - Vector2 l1[2] = { point - normal.orthogonal() * 100, point + normal.orthogonal() * 100 }; - RS::get_singleton()->canvas_item_add_line(p_to_rid, l1[0], l1[1], p_color, line_width); - Vector2 l2[2] = { point + normal.normalized() * (0.5 * line_width), point + normal * 30 }; - RS::get_singleton()->canvas_item_add_line(p_to_rid, l2[0], l2[1], p_color, line_width); + // Draw collision shape line. + PackedVector2Array line_points = { + point - normal.orthogonal() * 100, + point - normal.orthogonal() * 60, + point + normal.orthogonal() * 60, + point + normal.orthogonal() * 100 + }; + + Color transparent_color = Color(p_color, 0); + PackedColorArray line_colors = { + transparent_color, + p_color, + p_color, + transparent_color + }; + + RS::get_singleton()->canvas_item_add_polyline(p_to_rid, line_points, line_colors, line_width); + + // Draw arrow. + Color arrow_color = p_color.inverted(); + + Transform2D xf; + xf.rotate(normal.angle()); + + Vector<Vector2> arrow_points = { + xf.xform(Vector2(distance + line_width / 2, -2.5)), + xf.xform(Vector2(distance + 20, -2.5)), + xf.xform(Vector2(distance + 20, -10)), + xf.xform(Vector2(distance + 40, 0)), + xf.xform(Vector2(distance + 20, 10)), + xf.xform(Vector2(distance + 20, 2.5)), + xf.xform(Vector2(distance + line_width / 2, 2.5)), + }; + + RS::get_singleton()->canvas_item_add_polyline(p_to_rid, arrow_points, { arrow_color }, line_width / 2); } Rect2 WorldBoundaryShape2D::get_rect() const { |
