summaryrefslogtreecommitdiffstats
path: root/scene/resources/convex_polygon_shape_2d.cpp
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-12-14 09:06:53 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-12-14 09:06:53 -0300
commit1312df7fdcf9fceff63cf82bf97d6101c2c52215 (patch)
treea782230a3052dddcd709dd9dca25f7ab79ed8c3d /scene/resources/convex_polygon_shape_2d.cpp
parentf2183a5e09cc55a91b550f0d8f45b45a93d82b29 (diff)
downloadredot-engine-1312df7fdcf9fceff63cf82bf97d6101c2c52215.tar.gz
implement point cloud function using convex hull for ConvexPolygonShape2D, fixes #2848
Diffstat (limited to 'scene/resources/convex_polygon_shape_2d.cpp')
-rw-r--r--scene/resources/convex_polygon_shape_2d.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp
index a1137ba614..86cf818ac3 100644
--- a/scene/resources/convex_polygon_shape_2d.cpp
+++ b/scene/resources/convex_polygon_shape_2d.cpp
@@ -30,6 +30,8 @@
#include "servers/physics_2d_server.h"
#include "servers/visual_server.h"
+#include "geometry.h"
+
void ConvexPolygonShape2D::_update_shape() {
Physics2DServer::get_singleton()->shape_set_data(get_rid(),points);
@@ -40,7 +42,9 @@ void ConvexPolygonShape2D::_update_shape() {
void ConvexPolygonShape2D::set_point_cloud(const Vector<Vector2>& p_points) {
-
+ Vector<Point2> hull=Geometry::convex_hull_2d(p_points);
+ ERR_FAIL_COND(hull.size()<3);
+ set_points(hull);
}
void ConvexPolygonShape2D::set_points(const Vector<Vector2>& p_points) {