From 7648088fcacb1603ecfaab34903b605029810d8a Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 21 Apr 2015 16:47:49 -0300 Subject: ability to get closest owner to point, for navigation and navigation2d --- scene/2d/navigation2d.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++ scene/2d/navigation2d.h | 1 + 2 files changed, 58 insertions(+) (limited to 'scene/2d') diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp index 46af68444a..e4d10cad12 100644 --- a/scene/2d/navigation2d.cpp +++ b/scene/2d/navigation2d.cpp @@ -639,6 +639,62 @@ Vector2 Navigation2D::get_closest_point(const Vector2& p_point) { } +Object* Navigation2D::get_closest_point_owner(const Vector2& p_point) { + + Object *owner=NULL; + Vector2 closest_point=Vector2(); + float closest_point_d=1e20; + + for (Map::Element*E=navpoly_map.front();E;E=E->next()) { + + if (!E->get().linked) + continue; + for(List::Element *F=E->get().polygons.front();F;F=F->next()) { + + Polygon &p=F->get(); + for(int i=2;iget().owner; + } + + } + } + } + + for (Map::Element*E=navpoly_map.front();E;E=E->next()) { + + if (!E->get().linked) + continue; + for(List::Element *F=E->get().polygons.front();F;F=F->next()) { + + Polygon &p=F->get(); + int es = p.edges.size(); + for(int i=0;iget().owner; + } + } + } + } + + return owner; + +} + void Navigation2D::_bind_methods() { @@ -648,6 +704,7 @@ void Navigation2D::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_simple_path","start","end","optimize"),&Navigation2D::get_simple_path,DEFVAL(true)); ObjectTypeDB::bind_method(_MD("get_closest_point","to_point"),&Navigation2D::get_closest_point); + ObjectTypeDB::bind_method(_MD("get_closest_point_owner","to_point"),&Navigation2D::get_closest_point_owner); } diff --git a/scene/2d/navigation2d.h b/scene/2d/navigation2d.h index 7ff01bb442..7a33105b77 100644 --- a/scene/2d/navigation2d.h +++ b/scene/2d/navigation2d.h @@ -130,6 +130,7 @@ public: Vector get_simple_path(const Vector2& p_start, const Vector2& p_end,bool p_optimize=true); Vector2 get_closest_point(const Vector2& p_point); + Object* get_closest_point_owner(const Vector2& p_point); Navigation2D(); }; -- cgit v1.2.3