Пример #1
0
    // Use this for initialization
    void Start()
    {
        map = new PolyMapLoader("T4Map/x", "T4Map/y", "T4Map/goalPosT4", "T4Map/startPosT4", "T4Map/Button");

        int agentCounter = 0;

        agents = new List <T4Agent2>();

        for (int i = 0; i < map.polyData.start.Count; i = i + 1)
        {
            Vector3  startNode = map.polyData.start[i];
            Vector3  endNode   = map.polyData.end[i];
            T4Agent2 newAgent  = new T4Agent2("Agent " + agentCounter, startNode, endNode);
            agents.Add(newAgent);
            agentCounter++;
        }

        Debug.Log("Agents size:" + agents.Count);


        /*
         * //Test
         * T4Agent2 temp = new T4Agent2 ("Test", new Vector3 (2, 1, 2), new Vector3(1,1,1));
         * T4Agent2 temp2 = new T4Agent2 ("Test2", new Vector3 (0, 1, 0), new Vector3 (2, 1, 2));
         * temp2.velocity = new Vector3 (1, 0, 1);
         * List<T4Agent2> tempList = new List<T4Agent2> ();
         * tempList.Add (temp);
         * tempList.Add (temp2);
         * float tempTime = temp2.calculateTimeToCollision (new Vector3 (1, 0, 1), tempList);
         * Debug.Log ("TempTime:" + tempTime);*/



        StartCoroutine("Move");
    }
Пример #2
0
    void OnDrawGizmos()
    {
        if (map == null)
        {
            map = new PolyMapLoader("T4Map/x", "T4Map/y", "T4Map/goalPosT4", "T4Map/startPosT4", "T4Map/Button");
        }

        if (map.polyData.nodes != null)
        {
            foreach (Vector3 node in map.polyData.nodes)
            {
                Gizmos.color = Color.blue;
                Gizmos.DrawCube(node, Vector3.one);
            }

            foreach (Line line in map.polyData.lines)
            {
                Gizmos.color = Color.black;

                Gizmos.DrawLine(line.point1, line.point2);
            }
        }

        Gizmos.color = Color.black;
        Gizmos.DrawLine(new Vector3(xLow, 1, zLow), new Vector3(xHigh, 1, zLow));
        Gizmos.DrawLine(new Vector3(xHigh, 1, zLow), new Vector3(xHigh, 1, zHigh));
        Gizmos.DrawLine(new Vector3(xHigh, 1, zHigh), new Vector3(xLow, 1, zHigh));
        Gizmos.DrawLine(new Vector3(xLow, 1, zHigh), new Vector3(xLow, 1, zLow));
    }
Пример #3
0
    void Start()
    {
        PolyMapLoader loader = new PolyMapLoader("x", "y", "goalPos", "startPos", "button");

        polyData      = loader.polyData;
        graph         = new VGraph();
        walkableLines = new List <Line> ();

        CreateObstacles();
        ConstructWalkableLines();
        //	CreateInterObstacleWalk ();
        //	print ("Walkable lines: " + walkableLines.Count);
//		graph.PrintGraph ();

        kinematic_vel = 20f;
        path          = pathFinder.AStarSearch(polyData.start, polyData.end, graph);
        //	print ("path length: " + path.Count);

        // Choose model
        transform.position = polyData.start;
        //model = gameObject.AddComponent<KinematicPointModel> ();
        //model = gameObject.AddComponent<DynamicPointModel> ();
        model = gameObject.AddComponent <DifferentialDriveModel> ();
        model.SetPath(path);
        model.StartCoroutineMove();
    }
Пример #4
0
    void OnDrawGizmos()
    {
        map = new PolyMapLoader("x", "y", "goalPos", "startPos", "button");

        if (map.polyData.nodes != null)
        {
            foreach (Vector3 node in map.polyData.nodes)
            {
                Gizmos.color = Color.blue;
                Gizmos.DrawCube(node, Vector3.one);
            }

            foreach (Line line in map.polyData.lines)
            {
                Gizmos.color = Color.black;

                Gizmos.DrawLine(line.point1, line.point2);
            }
        }


        Gizmos.color = Color.black;
        Gizmos.DrawLine(new Vector3(0, 1, 0), new Vector3(100, 1, 0));
        Gizmos.DrawLine(new Vector3(100, 1, 0), new Vector3(100, 1, 90));
        Gizmos.DrawLine(new Vector3(100, 1, 90), new Vector3(0, 1, 90));
        Gizmos.DrawLine(new Vector3(0, 1, 90), new Vector3(0, 1, 0));
    }
Пример #5
0
    void OnDrawGizmos()
    {
        if (map == null)
        {
            map = new PolyMapLoader("polygMap1/x", "polygMap1/y", "polygMap1/goalPos", "polygMap1/startPos",
                                    "polygMap1/button");
        }
        if (agentColors == null)
        {
            agentColors = new List <Color>();
            agentColors.Add(Color.black);
            agentColors.Add(Color.blue);
            agentColors.Add(Color.yellow);
            agentColors.Add(Color.cyan);
            agentColors.Add(Color.green);
        }

        if (map.polyData.nodes != null)
        {
            foreach (Vector3 node in map.polyData.nodes)
            {
                Gizmos.color = Color.blue;
                Gizmos.DrawCube(node, Vector3.one);
            }

            foreach (Line line in map.polyData.lines)
            {
                Gizmos.color = Color.black;

                Gizmos.DrawLine(line.point1, line.point2);
            }
        }

        for (int i = 0; i < map.polyData.start.Count; i = i + 1)
        {
            Vector3 startNode = map.polyData.start[i];
            Vector3 endNode   = map.polyData.end[i];
            Gizmos.color = Color.green;
            Gizmos.DrawCube(startNode, Vector3.one);
            Gizmos.color = Color.red;
            Gizmos.DrawCube(endNode, Vector3.one);
            Gizmos.color = agentColors[i];
            Gizmos.DrawLine(startNode, endNode);
        }


        Gizmos.color = Color.black;
        Gizmos.DrawLine(new Vector3(xLow, 1, zLow), new Vector3(xHigh, 1, zLow));
        Gizmos.DrawLine(new Vector3(xHigh, 1, zLow), new Vector3(xHigh, 1, zHigh));
        Gizmos.DrawLine(new Vector3(xHigh, 1, zHigh), new Vector3(xLow, 1, zHigh));
        Gizmos.DrawLine(new Vector3(xLow, 1, zHigh), new Vector3(xLow, 1, zLow));

        Gizmos.color = Color.red;
        Gizmos.DrawSphere(blackGoal, 5);
    }
Пример #6
0
    // Use this for initialization
    void Start()
    {
        Application.runInBackground = true;
        map = new PolyMapLoader("polygMap1/x", "polygMap1/y", "polygMap1/goalPos", "polygMap1/startPos",
                                "polygMap1/button");

        polyData      = map.polyData;
        graph         = new VGraph();
        walkableLines = new List <Line> ();

        //Create visibility graph
        CreateObstacles();
        ConstructWalkableLines();
        CreateInterObstacleWalk();


        agents      = new List <T5Agent>();
        agentColors = new List <Color>();
        agentColors.Add(Color.black);
        agentColors.Add(Color.blue);
        agentColors.Add(Color.yellow);
        agentColors.Add(Color.cyan);
        agentColors.Add(Color.green);


        paths           = new List <Vector3> [map.polyData.start.Count];
        agentAtWaypoint = new int[map.polyData.start.Count];

        int agentCounter = 0;

        for (int i = 0; i < map.polyData.start.Count; i = i + 1)
        {
            Vector3 startNode = map.polyData.start[i];
            Vector3 endNode   = map.polyData.end[i];
            T5Agent newAgent  = new T5Agent("Agent " + agentCounter, startNode, endNode, agentCounter, true);
            newAgent.agent.gameObject.renderer.material.color = agentColors[i];
            List <PolyNode> ppath = pathFinder.AStarSearch(startNode, endNode, graph);
            List <Vector3>  temp  = new List <Vector3> ();
            foreach (PolyNode p in ppath)
            {
                temp.Add(p.pos);
            }
            //temp.Add(endNode);
            paths[i]           = temp;
            agentAtWaypoint[i] = 0;
            agents.Add(newAgent);
            agentCounter++;
        }

        Debug.Log("Agents size:" + agents.Count);


        StartCoroutine("Move");
    }
Пример #7
0
    // Use this for initialization
    void Awake()
    {
        PolyMapLoader map = new PolyMapLoader("x", "y", "goalPos", "startPos", "button");

        polyData = map.polyData;

        /*
         * Debugging
         * map.polyData.printNodes ();
         * map.polyData.printStart ();
         * map.polyData.printEnd ();
         * map.polyData.printButtons ();
         */
    }
Пример #8
0
    // Use this for initialization
    void Start()
    {
        map = new PolyMapLoader("x", "y", "goalPos", "startPos", "button");

        Debug.Log("Lines size:" + map.polyData.lines.Count);
        Debug.Log("Vertices size:" + map.polyData.nodes.Count);



        //Debug.Log ("Created Graph size:" + createdGraph.possibleLines.Count);

        /*
         * Debugging
         * map.polyData.printNodes ();
         * map.polyData.printStart ();
         * map.polyData.printEnd ();
         * map.polyData.printButtons ();
         */
    }