public List <Node> GetAllNodesInRange(Node sourceNode, int range)
    {
        List <Node> nodesInRange = new List <Node>();

        nodesInRange.Add(sourceNode);
        Queue <NodeAndDistance> bfsQueue = new Queue <NodeAndDistance>();

        bfsQueue.Enqueue(new NodeAndDistance(sourceNode, 0));
        while (bfsQueue.Count > 0)
        {
            NodeAndDistance actualNode = bfsQueue.Dequeue();
            if (actualNode.distance >= range)
            {
                continue;
            }

            foreach (Node neighbour in GetNeighbours(actualNode.node))
            {
                if (!nodesInRange.Contains(neighbour))
                {
                    nodesInRange.Add(neighbour);
                    bfsQueue.Enqueue(new NodeAndDistance(neighbour, actualNode.distance + 1));
                }
            }
        }
        return(nodesInRange);
    }
    private static void SortNodesByDistance(Node[] nodes, out NodeAndDistance[] nodeAndDistanceArray, Vector3 seekerPos)
    {
        int length = nodes.Length;

        nodeAndDistanceArray = new NodeAndDistance[nodes.Length];

        for (int i = 0; i < length; i++)
        {
            nodeAndDistanceArray[i].Node        = nodes[i];
            nodeAndDistanceArray[i].DistanceSqr = (nodes[i].position.ToVector3() - seekerPos).sqrMagnitude;
        }

        //сортировка по дальности от позиции искателя
        for (int i = 1; i < length; i++)
        {
            NodeAndDistance key = nodeAndDistanceArray[i];
            int             j   = i - 1;
            while (j >= 0 && nodeAndDistanceArray[j].DistanceSqr > key.DistanceSqr)
            {
                nodeAndDistanceArray[j + 1] = nodeAndDistanceArray[j];
                j--;
            }
            nodeAndDistanceArray[j + 1] = key;
        }
    }
Beispiel #3
0
    public override void ComputeNodeState(ref List <PointCloudLeafNode.NodeAndDistance> visibleLeafNodesAndDistances,
                                          Vector3 camPosition,
                                          float zFar)
    {
        float dist = EstimatedDistance(camPosition);

        if (dist <= zFar)
        {
            NodeAndDistance nodeAndDistance = new NodeAndDistance();
            nodeAndDistance.node = this;
            nodeAndDistance.estimatedDistanceToCamera = dist;
            visibleLeafNodesAndDistances.Add(nodeAndDistance);

            //Material
            //meshRenderer.materials = pointCloudManager.GetMaterialsForDistance(dist, boundsInModelSpace.MaxDistance(camPosition));
        }
    }
Beispiel #4
0
    private List <NodeAndDistance> GetListOfClosestNodes(Node[] nodeArray, int numRailsWeNeed, NodeSearchSettings searchSettings)
    {
        List <NodeAndDistance> closestNodes = new List <NodeAndDistance>();

        for (int i = 0; i < nodeArray.Length; i++)
        {
            if (IsNodeOkayToConnectTo(nodeArray[i], searchSettings))
            {
                float distance = Vector3.Distance(transform.position, nodeArray[i].transform.position);

                if (distance < _maxNodeDistance)
                {
                    if (closestNodes.Count < numRailsWeNeed)
                    {
                        closestNodes.Add(new NodeAndDistance(nodeArray[i], distance));
                        continue;
                    }
                    else
                    {
                        for (int j = 0; j < closestNodes.Count; j++)
                        {
                            // hmmm we can make this part better eventually by replacing the one that's furthest away instead of the first one we happen to find...
                            if (distance < closestNodes[j].distance)
                            {
                                closestNodes[j] = new NodeAndDistance(nodeArray[i], distance);
                                break;
                            }
                        }

                        continue;
                    }
                }
            }
        }

        return(closestNodes);
    }