Feb 19, 2012 at 4:15 PM
Edited Feb 19, 2012 at 4:24 PM

Hello yufeih. How correctly implement wrappathfinding for spherical map using your engine ? In my RTS project I build a planet and currently use hard manipulations for accept pathfinder wrapping.
Can you help me somehow ?


Coordinator
Feb 20, 2012 at 2:16 AM

There is a GetEdges method in PathGraph, you can modify that to support wrapping. Also update the GeHeuristicsValue method to return a correct distance when positions are wrapped.


Feb 20, 2012 at 4:19 AM
Edited Feb 20, 2012 at 4:24 AM

yufeih wrote:
There is a GetEdges method in PathGraph, you can modify that to support wrapping. Also update the GeHeuristicsValue method to return a correct distance when positions are wrapped.
I dont understand what i can modify in these methods. It looks very hard for me :((
Please explain me  I dont find any other source about this stuff.
/// <summary>
/// Gets all the adjacent edges of the specified node.
/// </summary>
public int GetEdges(int node, GraphEdge[] edges, int startIndex)
{
int count = 0;
int x = node % SegmentCountX;
int y = node / SegmentCountX;
GraphEdge edge;
edge.From = node;
if (x > bounds.Left && data[x  1 + y * SegmentCountX] == 0)
{
edge.To = y * SegmentCountX + x  1;
edge.Cost = 1.0f;
edges[startIndex++] = edge;
count++;
}
if (x < bounds.Right  1 && data[x + 1 + y * SegmentCountX] == 0)
{
edge.To = y * SegmentCountX + x + 1;
edge.Cost = 1.0f;
edges[startIndex++] = edge;
count++;
}
if (y > bounds.Top && data[x + (y  1) * SegmentCountX] == 0)
{
edge.To = (y  1) * SegmentCountX + x;
edge.Cost = 1.0f;
edges[startIndex++] = edge;
count++;
}
if (y < bounds.Bottom  1 && data[x + (y + 1) * SegmentCountX] == 0)
{
edge.To = (y + 1) * SegmentCountX + x;
edge.Cost = 1.0f;
edges[startIndex++] = edge;
count++;
}
if (x > bounds.Left && y > bounds.Top && data[x  1 + (y  1) * SegmentCountX] == 0)
{
edge.To = (y  1) * SegmentCountX + x  1;
edge.Cost = 1.4142135f;
edges[startIndex++] = edge;
count++;
}
if (x > bounds.Left && y < bounds.Bottom  1 && data[x  1 + (y + 1) * SegmentCountX] == 0)
{
edge.To = (y + 1) * SegmentCountX + x  1;
edge.Cost = 1.4142135f;
edges[startIndex++] = edge;
count++;
}
if (x < bounds.Right  1 && y > bounds.Top && data[x + 1 + (y  1) * SegmentCountX] == 0)
{
edge.To = (y  1) * SegmentCountX + x + 1;
edge.Cost = 1.4142135f;
edges[startIndex++] = edge;
count++;
}
if (x < bounds.Right  1 && y < bounds.Bottom  1 && data[x + 1 + (y + 1) * SegmentCountX] == 0)
{
edge.To = (y + 1) * SegmentCountX + x + 1;
edge.Cost = 1.4142135f;
edges[startIndex++] = edge;
count++;
}
return count;
}
/// <summary>
/// Gets the heuristic value used by A star search.
/// </summary>
public float GetHeuristicValue(int current, int end)
{
int xx = current % SegmentCountX  end % SegmentCountX;
int yy = current / SegmentCountX  end / SegmentCountX;
return (float)Math.Sqrt(xx * xx + yy * yy);
}



I get answer here.
http://gamedev.stackexchange.com/questions/24221/howtocreatewraparoundpathfinding

