summaryrefslogtreecommitdiff
path: root/scene/resources/concave_polygon_shape_2d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/concave_polygon_shape_2d.cpp')
-rw-r--r--scene/resources/concave_polygon_shape_2d.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp
index 0287d79dc6..923e2817ef 100644
--- a/scene/resources/concave_polygon_shape_2d.cpp
+++ b/scene/resources/concave_polygon_shape_2d.cpp
@@ -29,7 +29,7 @@
#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) {
@@ -41,6 +41,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() {