Skip to content

Commit

Permalink
getting started ond experimental walkable area rescue method
Browse files Browse the repository at this point in the history
  • Loading branch information
Henning Hasemann committed Jul 8, 2012
1 parent 0924225 commit fcb99c6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/dependencies.txt
Expand Up @@ -9,4 +9,5 @@ Development versions of the following are required for compiling:
* libpng
* alure
source: http://www.kcat.strangesoft.net/alure.html
* alut

59 changes: 54 additions & 5 deletions lib/ground.cc
Expand Up @@ -159,17 +159,60 @@ VirtualPosition Ground::findBoundaryPoint(VirtualPosition source, VirtualPositio
}
}
}
double ll = 10.0 / (source - target).length();
return nearestPoint + (source - target) * ll;

VirtualPosition p = nearestPoint; //findInnerPoint(nearestPoint, poly);

cdbg << "-------- found boundary point. " << " p=" << p <<
" orig=" << nearestPoint << " inpoly=" << poly.hasPoint(p) << "\n";

return p;

//double ll = 10.0 / (source - target).length();
//return nearestPoint + (source - target) * ll;

}

VirtualPosition Ground::findInnerPoint(VirtualPosition source, const Ground::Component::polygon_t& poly) {
int tries = 0;
int r = 1;
VirtualPosition p = source;
while(!poly.hasPoint(p) && (r <= 100)) {
for(int sx = -1; sx <= 1; sx += 2) {
for(int y = -r; y <= r; y++) {
tries++;
p = source + VirtualPosition(r * sx, y);
if(poly.hasPoint(p)) { break; }
}
if(poly.hasPoint(p)) { break; }
}

for(int sy = -1; sy <= 1; sy += 2) {
for(int x = -r + 1; x < r; x++) {
tries++;
p = source + VirtualPosition(x, r * sy);
if(poly.hasPoint(p)) { break; }
}
if(poly.hasPoint(p)) { break; }
}

r++;
}

cdbg << "rescue from point " << source << " -> " << p << " in " << tries << " tries r=" << r << ".\n";

return p;
}


void Ground::getPath(VirtualPosition source, VirtualPosition target, Path& path) {

cdbg << "Ground::getPath(" << source << ", " << target << ")\n";

// find innermost walkable component that contains source
// (root component is walkable, holes of holes of walkable components are
// walkable)

Component *island = rootComponent, *c;
Component *island = rootComponent, *c = 0;
do {
c = island;
island = 0;
Expand All @@ -188,6 +231,12 @@ void Ground::getPath(VirtualPosition source, VirtualPosition target, Path& path)
}
} while(island);

if(!c) {
cdbg << "Ground::getPath: no WA component that contains source found! --> aborting pathfinding!\n";
return;
}

source = findInnerPoint(source, c->getOuterBoundary());

// if target not in the component -> target := nearest polygon node
// to target
Expand All @@ -204,7 +253,7 @@ void Ground::getPath(VirtualPosition source, VirtualPosition target, Path& path)
}
else {
nearTarget = findBoundaryPoint(source, target, c->getOuterBoundary());
cdbg << "----------------- nearTarget=" << nearTarget << "\n";
cdbg << "Ground::getPath: nearTarget=" << nearTarget << "\n";
nearTarget_ = nearTarget;
}

Expand All @@ -214,7 +263,7 @@ void Ground::getPath(VirtualPosition source, VirtualPosition target, Path& path)

// compute path

cdbg << "sourceWP: " << sourceWP << " " << sourceWP->getPosition()
cdbg << "Ground::getPath: sourceWP: " << sourceWP << " " << sourceWP->getPosition()
<< " neighbor count: " << sourceWP->neighbours.size() << "\n";

getPath(*sourceWP, *targetWP, path);
Expand Down
1 change: 1 addition & 0 deletions lib/ground.h
Expand Up @@ -247,6 +247,7 @@ class Ground {
#endif

VirtualPosition findBoundaryPoint(VirtualPosition source, VirtualPosition target, const Component::polygon_t& poly);
VirtualPosition findInnerPoint(VirtualPosition p, const Ground::Component::polygon_t& poly);

public:
Component *rootComponent;
Expand Down

0 comments on commit fcb99c6

Please sign in to comment.