本文整理汇总了C#中PathNode.addLast方法的典型用法代码示例。如果您正苦于以下问题:C# PathNode.addLast方法的具体用法?C# PathNode.addLast怎么用?C# PathNode.addLast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PathNode
的用法示例。
在下文中一共展示了PathNode.addLast方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PathFinder
/// <summary>Creates a new instance of PathFinder.</summary>
/// <param name="numRows">The number of rows in the grid.</param>
/// <param name="numCols">The number of columns in the grid.</param>
/// <param name="inWorld">The world that contains this path finder.</param>
public PathFinder(int numRows, int numCols, World inWorld)
{
clear();
InWorld = inWorld;
Grid = new PathNode[numRows, numCols];
Nodes = new PathNode[numRows * numCols];
NodeSpacing = (VectorD)inWorld.Size / new VectorD((double)numCols, (double)numRows);
// build grid
PathNode node = null; // temporary variable
// initialize each node in the grid
for (int row = 0; row < numRows; row++)
{
for (int col = 0; col < numCols; col++)
{
node = new PathNode();
node.Index = row * NumCols + col;
node.Position = new VectorD((double)col * NodeSpacing.X, (double)row * NodeSpacing.Y);
Grid[row, col] = node;
Nodes[node.Index] = node;
}
}
// connect nodes to each other, if not blocked
for (int row = 0; row < numRows; row++)
{
for (int col = 0; col < numCols; col++)
{
// use collision detection to rule out connections (only geos can block)
node = Grid[row, col];
PathNode destNode = null;
VectorF nodePos = (VectorF)node.Position;
if (col < numCols - 1)
{
// upper-right
if (row > 0)
{
destNode = Grid[row - 1, col + 1];
if (!inWorld.Collision.segCollision(nodePos, (VectorF)destNode.Position, null, null, false, false, true))
{
node.addLast(new PathEdge(this, node.Index, destNode.Index));
destNode.addLast(new PathEdge(this, destNode.Index, node.Index));
}
}
// right
destNode = Grid[row, col + 1];
if (!inWorld.Collision.segCollision(nodePos, (VectorF)destNode.Position, null, null, false, false, true))
{
node.addLast(new PathEdge(this, node.Index, destNode.Index));
destNode.addLast(new PathEdge(this, destNode.Index, node.Index));
}
// lower right
if (row < numRows - 1)
{
destNode = Grid[row + 1, col + 1];
if (!inWorld.Collision.segCollision(nodePos, (VectorF)destNode.Position, null, null, false, false, true))
{
node.addLast(new PathEdge(this, node.Index, destNode.Index));
destNode.addLast(new PathEdge(this, destNode.Index, node.Index));
}
}
}
// bottom
if (row < numRows - 1)
{
destNode = Grid[row + 1, col];
if (!inWorld.Collision.segCollision(nodePos, (VectorF)destNode.Position, null, null, false, false, true))
{
node.addLast(new PathEdge(this, node.Index, destNode.Index));
destNode.addLast(new PathEdge(this, destNode.Index, node.Index));
}
}
}
}
}