Are you loading the correct tiles? If it can't find the nearest poly that means the mesh doesn't actually have any information for the given coordinate. Verify that the start/from are actually in that tile.
Here is how I determine which tiles to load, then I call basically the same function you are using:
Code:
- (NSArray*)routeFrom:(Position*)startPos to:(Position*)endPos status:(dtStatus*)status{
PPNavmeshQuery *query = [[PPNavmeshQuery alloc] init];
NSString *meshPath = [[@"~/Dropbox/Meshes/Azeroth" stringByExpandingTildeInPath] stringByAppendingString:@"/"];
PPCoords *start = [[PPCoords alloc] initWithPosition:startPos];
PPCoords *end = [[PPCoords alloc] initWithPosition:endPos];
float NavMeshOri[3];
NavMeshOri[0] = -(32 * GRID_SIZE);
NavMeshOri[1] = -(32 * GRID_SIZE);
NavMeshOri[2] = -(32 * GRID_SIZE);
int startTileY = (int)(((-(start.pgX)) - (-(32 * GRID_SIZE))) / GRID_SIZE);
int startTileX = (int)(((-(start.pgY)) - (-(32 * GRID_SIZE))) / GRID_SIZE);
int endTileY = (int)(((-(end.pgX)) - (-(32 * GRID_SIZE))) / GRID_SIZE);
int endTileX = (int)(((-(end.pgY)) - (-(32 * GRID_SIZE))) / GRID_SIZE);
//NSLog( @"Start tile: (%d, %d)", startTileX, startTileY);
//NSLog( @"End tile: (%d, %d)", endTileX, endTileY);
int x1, x2, y1, y2;
if ( startTileX <= endTileX ){
x1 = startTileX;
x2 = endTileX;
}
else{
x1 = endTileX;
x2 = startTileX;
}
if ( startTileY <= endTileY ){
y1 = startTileY;
y2 = endTileY;
}
else{
y1 = endTileY;
y2 = startTileY;
}
// load a square for now (one tile behind each)
for (int x=x1-1; x<=x2+1; x++){
for (int y=y1-1; y<=y2+1; y++){
if ( ![query addTile:[NSString stringWithFormat:@"%@%d_%d.mesh", meshPath, x, y] andX:x andY:y] ){
NSLog(@" not found...");
continue;
}
}
}
NSArray *coords = [query routeFrom:start to:end status:status];
NSMutableArray *positions = [NSMutableArray array];
// convert and add
int index = 0;
for ( PPCoords *coord in coords ){
Position *pos = [Position positionWithX:coord.pgX Y:coord.pgY Z:coord.pgZ];
[positions addObject:pos];
NSLog(@"%i: %@", index++, pos);
}
return [[positions retain] autorelease];
}
Yes I know it looks weird, it's objective-C (I'm a mac developer), but it should still make sense.
PPCoords is just a class that lets me switch between the wow coordinate system and what detour uses.