Esempio n. 1
0
    public ArrayList findPath(Vector3 source, Vector3 dest, int numPoints, int dim)
    {
        rrTree  tree = new rrTree();
        rrtNode s    = new rrtNode(source, null);

        bool end = false;

        tree.addNode(s);
        rrtNode lastPoint = s;
        bool    doCheck   = true;

        for (int i = 0; i < numPoints && !end; i++)
        {
            if (doCheck)
            {
                if (freePath(lastPoint.point, dest))
                {
                    rrtNode d = new rrtNode(dest, lastPoint);
                    lastPoint.addConnection(d);
                    tree.addNode(d);
                    //Debug.Log ("Point: "+point.point);

                    end = true;
                }
            }

            if (!end)
            {
                //pick up a random point
                //Vector3 newPoint = new Vector3 (myRnd (-dim, dim), 0, myRnd (-dim, dim));
                //Vector3 newPoint = new Vector3 ( myRnd (s.point.x, 1, dim), y, myRnd (s.point.z, 1, dim));
                Vector3 newPoint = myRndVector(source, dest, dim, 30f, 0.3f);

                rrtNode point = tree.findClosestNode(newPoint);
                if (point != null && freePath(newPoint, point.point))
                {
                    //if it is possible to reach the point from the previous point
                    //add the connection
                    rrtNode p2 = new rrtNode(newPoint, point);
                    point.addConnection(p2);
                    tree.addNode(p2);

                    //from the next iteration consider the new point
                    lastPoint = p2;
                    createPoint(p2.point);
                    doCheck = true;
                }
                //else doCheck = false;
            }
        }

        return(tree.getPath());
    }
Esempio n. 2
0
    private bool addRandomNode(rrTree tree, int dim)
    {
        Vector3 newPoint = new Vector3(myRnd(dim), y, myRnd(dim));

        createPoint(newPoint);

        rrtNode point = tree.findClosestNode(newPoint);

        if (point != null && freePath(point.point, newPoint))
        {
            //if it is possible to reach the point from the previous point
            //add the connection
            rrtNode p2 = new rrtNode(newPoint, point);
            point.addConnection(p2);
            tree.addNode(p2);
            myDrawLine(point.point, newPoint, Color.blue);
            return(true);
        }
        return(true);
    }
Esempio n. 3
0
    private bool addRandomNode(rrTree tree, int dim)
    {
        Vector3 newPoint = new Vector3(myRnd(dim), y, myRnd(dim));

        createPoint(newPoint);

        rrtNode   point   = tree.findClosestNode(newPoint);
        ArrayList carPath = freePath(point.point, newPoint, point.forward);

        if (point != null && carPath.Count > 0)
        {
            //if it is possible to reach the point from the previous point
            //add the connection
            rrtNode p2 = new rrtNode(newPoint, point);
            p2.forward = ((Vector3)carPath[carPath.Count - 1] - (Vector3)carPath[carPath.Count - 2]).normalized;
            //point.addConnection(p2);
            tree.addNode(p2);
            myDrawLine(point.point, newPoint, Color.blue);
            return(true);
        }
        return(true);
    }
Esempio n. 4
0
    private bool addRandomNode(Vector3 source, Vector3 dest, rrTree tree, int dim)
    {
        //Vector3 newPoint = new Vector3 (myRnd (-dim, dim), 0, myRnd (-dim, dim));
        //Vector3 newPoint = new Vector3 ( myRnd (tree.source.point.x, 1, dim), y, myRnd (tree.source.point.z, 1, dim));
        Vector3 newPoint = myRndVector(source, dest, dim, 30f, 0.3f);

        createPoint(newPoint);

        Debug.Log("Rand point: " + newPoint);

        rrtNode point = tree.findClosestNode(newPoint);

        if (point != null)          // && freePath(newPoint, point.point) ) {
        //if it is possible to reach the point from the previous point
        //add the connection
        {
            rrtNode p2 = new rrtNode(newPoint, point);
            point.addConnection(p2);
            tree.addNode(p2);
            return(true);
        }
        return(true);
    }