diff options
Diffstat (limited to 'scene/resources/concave_polygon_shape_2d.cpp')
-rw-r--r-- | scene/resources/concave_polygon_shape_2d.cpp | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp index 0287d79dc6..01b7531f14 100644 --- a/scene/resources/concave_polygon_shape_2d.cpp +++ b/scene/resources/concave_polygon_shape_2d.cpp @@ -29,11 +29,12 @@ #include "concave_polygon_shape_2d.h" #include "servers/physics_2d_server.h" - +#include "servers/visual_server.h" void ConcavePolygonShape2D::set_segments(const DVector<Vector2>& p_segments) { Physics2DServer::get_singleton()->shape_set_data(get_rid(),p_segments); + emit_changed(); } DVector<Vector2> ConcavePolygonShape2D::get_segments() const { @@ -41,6 +42,43 @@ DVector<Vector2> ConcavePolygonShape2D::get_segments() const { return Physics2DServer::get_singleton()->shape_get_data(get_rid()); } +void ConcavePolygonShape2D::draw(const RID& p_to_rid,const Color& p_color) { + + + DVector<Vector2> s = get_segments(); + int len=s.size(); + if (len==0 || (len%2)==1) + return; + + DVector<Vector2>::Read r = s.read(); + for(int i=0;i<len;i+=2) { + VisualServer::get_singleton()->canvas_item_add_line(p_to_rid,r[i],r[i+1],p_color,2); + } + +} + +Rect2 ConcavePolygonShape2D::get_rect() const { + + + DVector<Vector2> s = get_segments(); + int len=s.size(); + if (len==0) + return Rect2(); + + Rect2 rect; + + DVector<Vector2>::Read r = s.read(); + for(int i=0;i<len;i++) { + if (i==0) + rect.pos=r[i]; + else + rect.expand_to(r[i]); + } + + return rect; + +} + void ConcavePolygonShape2D::_bind_methods() { |