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 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'scene/2d/navigation2d.cpp') 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); } -- cgit v1.2.3 From 21939ce08b042b8cfcff16da780a4595aac500cd Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 30 Apr 2015 10:06:18 -0300 Subject: -some cleanups -added tesselation function to curve and curve2d --- scene/2d/navigation2d.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'scene/2d/navigation2d.cpp') diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp index e4d10cad12..d427bf4bc3 100644 --- a/scene/2d/navigation2d.cpp +++ b/scene/2d/navigation2d.cpp @@ -516,7 +516,8 @@ Vector Navigation2D::get_simple_path(const Vector2& p_start, const Vect apex_poly=p; portal_left=apex_point; portal_right=apex_point; - path.push_back(apex_point); + if (path[path.size()-1].distance_to(apex_point)>CMP_EPSILON) + path.push_back(apex_point); skip=true; } } @@ -536,7 +537,8 @@ Vector Navigation2D::get_simple_path(const Vector2& p_start, const Vect apex_poly=p; portal_right=apex_point; portal_left=apex_point; - path.push_back(apex_point); + if (path[path.size()-1].distance_to(apex_point)>CMP_EPSILON) + path.push_back(apex_point); } } @@ -547,7 +549,7 @@ Vector Navigation2D::get_simple_path(const Vector2& p_start, const Vect } - if (path[path.size()-1]!=begin_point) + if (path[path.size()-1].distance_to(begin_point)>CMP_EPSILON) path.push_back(begin_point); path.invert(); -- cgit v1.2.3 From 2296b0508e0e2d2ed51bc6cb892fa8a8abb55ff7 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 2 May 2015 16:35:43 -0300 Subject: 2D pathfinder fixes, should now always find the best path. --- scene/2d/navigation2d.cpp | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'scene/2d/navigation2d.cpp') diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp index d427bf4bc3..5a02501816 100644 --- a/scene/2d/navigation2d.cpp +++ b/scene/2d/navigation2d.cpp @@ -32,6 +32,7 @@ void Navigation2D::_navpoly_link(int p_id) { p.edges.resize(plen); Vector2 center; + float sum=0; for(int j=0;j=len) { + valid=false; + break; + } + + Vector2 epn = nm.xform.xform(r[idxn]); + + sum+=(epn.x-ep.x)*(epn.y+ep.y); + + } + p.clockwise=sum>0; + if (!valid) { nm.polygons.pop_back(); ERR_CONTINUE(!valid); @@ -493,17 +509,30 @@ Vector Navigation2D::get_simple_path(const Vector2& p_start, const Vect left = _get_vertex(p->edges[prev].point); right = _get_vertex(p->edges[prev_n].point); - if (CLOCK_TANGENT(apex_point,left,(left+right)*0.5) < 0){ + if (p->clockwise) { SWAP(left,right); } + /*if (CLOCK_TANGENT(apex_point,left,(left+right)*0.5) < 0){ + SWAP(left,right); + }*/ } bool skip=false; + /* print_line("-----\nAPEX: "+(apex_point-end_point)); + print_line("LEFT:"); + print_line("\tPortal: "+(portal_left-end_point)); + print_line("\tPoint: "+(left-end_point)); + print_line("\tFree: "+itos(CLOCK_TANGENT(apex_point,portal_left,left) >= 0)); + print_line("RIGHT:"); + print_line("\tPortal: "+(portal_right-end_point)); + print_line("\tPoint: "+(right-end_point)); + print_line("\tFree: "+itos(CLOCK_TANGENT(apex_point,portal_right,right) <= 0)); +*/ if (CLOCK_TANGENT(apex_point,portal_left,left) >= 0){ //process - if (portal_left==apex_point || CLOCK_TANGENT(apex_point,left,portal_right) > 0) { + if (portal_left.distance_squared_to(apex_point) 0) { left_poly=p; portal_left=left; } else { @@ -519,12 +548,13 @@ Vector Navigation2D::get_simple_path(const Vector2& p_start, const Vect if (path[path.size()-1].distance_to(apex_point)>CMP_EPSILON) path.push_back(apex_point); skip=true; + //print_line("addpoint left"); } } if (!skip && CLOCK_TANGENT(apex_point,portal_right,right) <= 0){ //process - if (portal_right==apex_point || CLOCK_TANGENT(apex_point,right,portal_left) < 0) { + if (portal_right.distance_squared_to(apex_point) Navigation2D::get_simple_path(const Vector2& p_start, const Vect portal_left=apex_point; if (path[path.size()-1].distance_to(apex_point)>CMP_EPSILON) path.push_back(apex_point); + //print_line("addpoint right"); + } } -- cgit v1.2.3 From ab99671bb835a5fe24a092ec34afe1ad862ac254 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 1 Jun 2015 19:42:34 -0300 Subject: -fixes to navigation, so edge-merging is more flexible on conflict -add tab support to richtextlabel -some click fixes to audio stream resampled -ability to import largetextures (dialog) --- scene/2d/navigation2d.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'scene/2d/navigation2d.cpp') diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp index 5a02501816..5db0e0a9fc 100644 --- a/scene/2d/navigation2d.cpp +++ b/scene/2d/navigation2d.cpp @@ -91,9 +91,13 @@ void Navigation2D::_navpoly_link(int p_id) { } else { if (C->get().B!=NULL) { - print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b)); + ConnectionPending pending; + pending.polygon=&p; + pending.edge=j; + p.edges[j].P=C->get().pending.push_back(pending); + continue; + //print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b)); } - ERR_CONTINUE(C->get().B!=NULL); //wut C->get().B=&p; C->get().B_edge=j; @@ -133,7 +137,12 @@ void Navigation2D::_navpoly_unlink(int p_id) { EdgeKey ek(edges[i].point,edges[next].point); Map::Element *C=connections.find(ek); ERR_CONTINUE(!C); - if (C->get().B) { + + if (edges[i].P) { + C->get().pending.erase(edges[i].P); + edges[i].P=NULL; + + } else if (C->get().B) { //disconnect C->get().B->edges[C->get().B_edge].C=NULL; @@ -149,6 +158,20 @@ void Navigation2D::_navpoly_unlink(int p_id) { C->get().B=NULL; C->get().B_edge=-1; + if (C->get().pending.size()) { + //reconnect if something is pending + ConnectionPending cp = C->get().pending.front()->get(); + C->get().pending.pop_front(); + + C->get().B=cp.polygon; + C->get().B_edge=cp.edge; + C->get().A->edges[C->get().A_edge].C=cp.polygon; + C->get().A->edges[C->get().A_edge].C_edge=cp.edge; + cp.polygon->edges[cp.edge].C=C->get().A; + cp.polygon->edges[cp.edge].C_edge=C->get().A_edge; + cp.polygon->edges[cp.edge].P=NULL; + } + } else { connections.erase(C); //erase -- cgit v1.2.3