public static bool Reachable(Node from, Node to, Node[,] nodesArray) { if (from.InformerNode.IsObstacle) { return(false); } var pointsBetween = StraightLine.FindMiddlePoints(from, to); var destination = StraightLine.FindDestination(from, to); pointsBetween.Remove(new Point(from.X(), from.Y())); pointsBetween.Remove(new Point(to.X(), to.Y())); foreach (var point in pointsBetween) { if (destination == Destinations.UpRight && nodesArray[point.X, point.Y].NormMatrix[0, 2] == 0) { return(false); } if (destination == Destinations.UpLeft && nodesArray[point.X, point.Y].NormMatrix[0, 0] == 0) { return(false); } if (destination == Destinations.DownRight && nodesArray[point.X, point.Y].NormMatrix[2, 2] == 0) { return(false); } if (destination == Destinations.DownLeft && nodesArray[point.X, point.Y].NormMatrix[2, 0] == 0) { return(false); } if (nodesArray[point.X, point.Y].InformerNode.IsObstacle) { return(false); } } return(true); }
public void GoalBounding() { var controller = GetComponentInChildren <Controller>(); if (!controller.IsPrecomputed) { controller.PrecomputeMap(); } if (StartInformer != null && FinishInformer != null) { var startNode = controller.NodesArray[(int)StartInformer.transform.position.x / 3, (int)StartInformer.transform.position.z / 3]; var goalNode = controller.NodesArray[(int)FinishInformer.transform.position.x / 3, (int)FinishInformer.transform.position.z / 3]; var destination = StraightLine.FindDestination(startNode, goalNode); var minRow = startNode.GoalBounds[(int)destination - 1, 0]; var maxRow = startNode.GoalBounds[(int)destination - 1, 1]; var minCol = startNode.GoalBounds[(int)destination - 1, 2]; var maxCol = startNode.GoalBounds[(int)destination - 1, 3]; Debug.Log("Bounding Box: Destination = " + destination + " MinRow = " + minRow + " MaxRow = " + maxRow + " MinCol = " + minCol + " MaxCol = " + maxCol); for (var i = minRow; i < maxRow; ++i) { for (var j = minCol; j < maxCol; ++j) { var renderer = controller.NodesArray[i, j].InformerNode.GetComponent <Renderer>(); renderer.material.SetColor("_Color", Color.green); } } } else { Debug.LogError("Enter proper arguments"); } }