From 16022da18793823bf9d3530f1ae9a21501b4faec Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 14 Nov 2018 15:55:50 -0300 Subject: Ensure that array passed to physics is always counter clockwise, fixes #15361. --- core/math/geometry.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'core/math') diff --git a/core/math/geometry.h b/core/math/geometry.h index a813a90774..df63f0dabe 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -800,6 +800,21 @@ public: return Vector >(); } + static bool is_polygon_clockwise(const Vector &p_polygon) { + int c = p_polygon.size(); + if (c < 3) + return false; + const Vector2 *p = p_polygon.ptr(); + real_t sum = 0; + for (int i = 0; i < c; i++) { + const Vector2 &v1 = p[i]; + const Vector2 &v2 = p[(i + 1) % c]; + sum += (v2.x - v1.x) * (v2.y + v1.y); + } + + return sum > 0.0f; + } + static PoolVector > separate_objects(PoolVector p_array); static PoolVector wrap_geometry(PoolVector p_array, real_t *p_error = NULL); ///< create a "wrap" that encloses the given geometry -- cgit v1.2.3