예제 #1
0
    public void findLines(PolyData data)
    {
        //For every figure, iterate through the vertices and check if it's possible
        //to draw a line to a vertice in any other figure
        for (int i = 0; i < data.figures.Count; i++)
        {
            PolyNode curFig = data.figures[i];
            foreach (Vector3 curVertice in curFig.vertices)
            {
                for (int j = 0; j < data.figures.Count; i++)
                {
                    //If it's the same figure continue;
                    if (i == j)
                    {
                        continue;
                    }

                    PolyNode curTestFigure = data.figures[j];

                    foreach (Vector3 endVertice in curTestFigure.vertices)
                    {
                        Line testLine = new Line(curVertice, endVertice);
                        if (!this.doIntersect(data, testLine))
                        {
                            possibleLines.Add(testLine);
                        }
                    }
                }
            }
        }
    }
예제 #2
0
    // Use this for initialization
    void Start()
    {
        map = new PolyMapLoaderT3("polygMap1/x", "polygMap1/y", "polygMap1/goalPos", "polygMap1/startPos",
                                  "polygMap1/button", "polygMap1/customerPos");
        mapData = map.polyData;
        R       = 5;

        agents = new List <PolyAgent> ();
        for (int i = 0; i < mapData.start.Count; i++)
        {
            Vector3 start = mapData.start[i];
            Vector3 end   = mapData.end[i];
            agents.Add(new PolyAgent("Agent " + i, start, end, R, "point"));
            agents [i].agent.renderer.material.color = Color.blue;
            agents[i].model = gameObject.AddComponent <DynamicPointModel> ();
        }

        vrp = new VRPPL(mapData.customers, agents.Count);

        foreach (PolyAgent agent in agents)
        {
            List <Vector3> path = new List <Vector3> ();
            path.Add(agent.end);
            agent.model.SetPath(path, agent, mapData.lines);
            agent.model.StartCoroutineMove();
        }
    }
예제 #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
    // 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");
    }
예제 #5
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 ();
         */
    }
예제 #6
0
    public PolyMapLoader(string x, string y, string goal, string start, string buttons)
    {
        polyData = new PolyData();
        string xFile       = prefix + x + postfix;
        string yFile       = prefix + y + postfix;
        string goalFile    = prefix + goal + postfix;
        string startFile   = prefix + start + postfix;
        string buttonsFile = prefix + buttons + postfix;

        System.IO.StreamReader xReader = new System.IO.StreamReader(xFile);
        System.IO.StreamReader yReader = new System.IO.StreamReader(yFile);

        string xpos, ypos;

        while ((xpos = xReader.ReadLine()) != null)
        {
            ypos = yReader.ReadLine();              // xFile and yFile matches each other

            xpos = xpos.Replace(",", ".");
            ypos = ypos.Replace(",", ".");

            polyData.nodes.Add(new Vector3(float.Parse(xpos), 1f, float.Parse(ypos)));
        }

        xReader.Close();
        yReader.Close();

        System.IO.StreamReader startReader = new System.IO.StreamReader(startFile);
        string line;

        line = startReader.ReadLine();
        string[] startPos = line.Split(' ');
        polyData.start = new Vector3(Mathf.Round(float.Parse(startPos [0])), 1f, float.Parse(startPos [1]));
        startReader.Close();

        System.IO.StreamReader endReader = new System.IO.StreamReader(goalFile);
        line = endReader.ReadLine();
        string[] endPos = line.Split(' ');
        polyData.end = new Vector3(Mathf.Round(float.Parse(endPos [0])), 1f, float.Parse(endPos [1]));
        endReader.Close();

        System.IO.StreamReader buttonReader = new System.IO.StreamReader(buttonsFile);
        string button;

        while ((button = buttonReader.ReadLine()) != null)
        {
            polyData.buttons.Add(Convert.ToInt32(button));
        }
        buttonReader.Close();
    }
예제 #7
0
    //Checks if a line intersect any obstacle line
    private bool doIntersect(PolyData data, Line testLine)
    {
        foreach (Line curLine in data.lines)
        {
            if (testLine.intersect(curLine))
            {
                //Debug.Log("TestLine:"+testLine.point1+" "+testLine.point2);
                //Debug.Log("Obs line:"+curLine.point1+" "+curLine.point2);

                return(true);
            }
        }
        return(false);
    }
예제 #8
0
    void Start()
    {
        map = new PolyMapLoaderT3("polygMap1/x", "polygMap1/y", "polygMap1/goalPos", "polygMap1/startPos",
                                  "polygMap1/button", "polygMap1/customerPos");
        polyData = map.polyData;

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

        // START VRP
        R      = 3;
        agents = new List <PolyAgent> ();
        for (int i = 0; i < polyData.start.Count; i++)
        {
            Vector3 start = polyData.start[i];
            Vector3 end   = polyData.end[i];
            agents.Add(new PolyAgent("Agent " + i, start, end, R, "car"));
            agents [i].agent.renderer.material.color = Color.black;
            agents[i].model = gameObject.AddComponent <DynamicCarModel> ();
            //agents[i].model = gameObject.AddComponent<DynamicPointModel> ();
        }

        List <Vector3> customers = new List <Vector3> ();       // for plotting

        foreach (Vector3 v in polyData.customers)
        {
            customers.Add(v);
        }
        vrp = new VRPPL(customers, agents.Count);


        // END VRP

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

        stopwatch.Start();
        ready = new List <PolyAgent> ();
    }
예제 #9
0
파일: T5Simple.cs 프로젝트: Draggys/Agents2
    void Start()
    {
        map = new PolyMapLoaderT3("polygMap1/x", "polygMap1/y", "polygMap1/goalPos", "polygMap1/startPos",
                                  "polygMap1/button", "polygMap1/customerPos");
        polyData = map.polyData;

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

        // START VRP
        R = 3;
        CreateObstacles();
        ConstructWalkableLines();
        CreateInterObstacleWalk();

        agents = new List <T5PolyAgent> ();
        for (int i = 0; i < polyData.start.Count; i++)
        {
            Vector3 start = polyData.start[i];
            Vector3 end   = polyData.end[i];
            agents.Add(new T5PolyAgent("Agent " + i, start, end, R, "car"));
            agents [i].agent.renderer.material.color = Color.black;

            agents[i].model = gameObject.AddComponent <T5DynCar> ();

            List <PolyNode> ppath = pathFinder.AStarSearch(start, end, graph);
            List <Vector3>  path  = new List <Vector3> ();
            foreach (PolyNode node in ppath)
            {
                path.Add(node.pos);
            }
            agents[i].model.SetPath(path, agents[i], new List <Line> ());
        }
        foreach (T5PolyAgent agent in agents)
        {
            agent.model.SetAgents(ref agents);
            agent.model.StartCoroutineMove();
        }
        stopwatch.Start();
        ready = new List <T5PolyAgent> ();
    }
예제 #10
0
        public void Read(string filename)
        {
            FileData fileData = new FileData(filename);

            Data       = fileData;
            SourceFile = filename;

            fileData.Endian = Endianness.Big;
            fileData.seek(0);

            // read header
            string magic = fileData.readString(0, 4);

            if (magic.Equals("NDWD"))
            {
                fileData.Endian = Endianness.Little;
            }

            Endian = fileData.Endian;

            fileData.seek(0xA);
            int polysets = fileData.readUShort();

            boneCount = fileData.readUShort();
            fileData.skip(2);  // somethingsets
            int polyClumpStart    = fileData.readInt() + 0x30;
            int polyClumpSize     = fileData.readInt();
            int vertClumpStart    = polyClumpStart + polyClumpSize;
            int vertClumpSize     = fileData.readInt();
            int vertaddClumpStart = vertClumpStart + vertClumpSize;
            int vertaddClumpSize  = fileData.readInt();
            int nameStart         = vertaddClumpStart + vertaddClumpSize;

            boundingSphere[0] = fileData.readFloat();
            boundingSphere[1] = fileData.readFloat();
            boundingSphere[2] = fileData.readFloat();
            boundingSphere[3] = fileData.readFloat();

            // object descriptors

            ObjectData[]   obj             = new ObjectData[polysets];
            List <float[]> boundingSpheres = new List <float[]>();

            int[] boneflags = new int[polysets];
            for (int i = 0; i < polysets; i++)
            {
                float[] boundingSphere = new float[8];
                boundingSphere[0] = fileData.readFloat();
                boundingSphere[1] = fileData.readFloat();
                boundingSphere[2] = fileData.readFloat();
                boundingSphere[3] = fileData.readFloat();
                boundingSphere[4] = fileData.readFloat();
                boundingSphere[5] = fileData.readFloat();
                boundingSphere[6] = fileData.readFloat();
                boundingSphere[7] = fileData.readFloat();
                boundingSpheres.Add(boundingSphere);
                int temp = fileData.pos() + 4;
                fileData.seek(nameStart + fileData.readInt());
                obj[i].name = (fileData.readString());
                // read name string
                fileData.seek(temp);
                boneflags[i]      = fileData.readInt();
                obj[i].singlebind = fileData.readShort();
                obj[i].polyCount  = fileData.readUShort();
                obj[i].positionb  = fileData.readInt();
            }

            // reading polygon data
            foreach (var o in obj)
            {
                Mesh m = new Mesh();
                meshes.Add(m);
                m.Nodes = new List <Polygon>();
                //m.Text = o.name;
                //m.boneflag = boneflags[meshIndex];
                //m.singlebind = (short)o.singlebind;
                //m.boundingSphere = boundingSpheres[meshIndex++];

                for (int i = 0; i < o.polyCount; i++)
                {
                    PolyData polyData = new PolyData();

                    polyData.polyStart   = fileData.readInt() + polyClumpStart;
                    polyData.vertStart   = fileData.readInt() + vertClumpStart;
                    polyData.verAddStart = fileData.readInt() + vertaddClumpStart;
                    polyData.vertCount   = fileData.readUShort();
                    polyData.vertSize    = fileData.readByte();
                    polyData.UVSize      = fileData.readByte();
                    polyData.texprop1    = fileData.readInt();
                    polyData.texprop2    = fileData.readInt();
                    polyData.texprop3    = fileData.readInt();
                    polyData.texprop4    = fileData.readInt();
                    polyData.polyCount   = fileData.readUShort();
                    polyData.polySize    = fileData.readByte();
                    polyData.polyFlag    = fileData.readByte();
                    fileData.skip(0xC);

                    int temp = fileData.pos();

                    // read vertex
                    //Polygon poly = ReadVertex(fileData, polyData, o);
                    Polygon poly = new Polygon();
                    m.Nodes.Add(poly);

                    poly.materials = ReadMaterials(fileData, polyData, nameStart);

                    fileData.seek(temp);
                }
            }
            foreach (Mesh m in meshes)
            {
                if (m.Nodes == null)
                {
                    continue;
                }
                foreach (Polygon p in m.Nodes)
                {
                    foreach (Material mat in p.materials)
                    {
                        foreach (MatTexture t in mat.textures)
                        {
                            bool found = false;
                            for (ushort j = 0; j < allTextures.Count; ++j)
                            {
                                if (t.hashPos == allTextures[j].hashPos)
                                {
                                    found = true;
                                    break;
                                }
                            }
                            if (found)
                            {
                                continue;
                            }
                            allTextures.Add(t);
                        }
                    }
                }
            }
        }
예제 #11
0
        public static List <Material> ReadMaterials(FileData d, PolyData p, int nameOffset)
        {
            int             propoff = p.texprop1;
            List <Material> mats    = new List <Material>();

            while (propoff != 0)
            {
                d.seek(propoff);

                Material m = new Material();
                mats.Add(m);
                m.textures = new List <MatTexture>();

                d.skip(4); //m.Flags = (uint)d.readInt();
                d.skip(4);
                d.skip(2); //m.srcFactor = d.readUShort();
                ushort texCount = d.readUShort();
                d.skip(2); //m.dstFactor = d.readUShort();
                d.skip(1); //m.alphaTest = d.readByte();
                d.skip(1); //m.alphaFunction = d.readByte();

                d.skip(1); // unknown
                d.skip(1); //m.RefAlpha = d.readByte();
                d.skip(2); //m.cullMode = d.readUShort();
                d.skip(4); // padding
                d.skip(4); //m.unkownWater = d.readInt();
                d.skip(4); //m.zBufferOffset = d.readInt();

                for (ushort i = 0; i < texCount; i++)
                {
                    MatTexture tex = new MatTexture();
                    tex.hashPos = d.pos();
                    tex.hash    = d.readInt();
                    d.skip(6); // padding?
                    d.skip(2); //tex.mapMode = d.readUShort();
                    d.skip(1); //tex.wrapModeS = d.readByte();
                    d.skip(1); //tex.wrapModeT = d.readByte();
                    d.skip(1); //tex.minFilter = d.readByte();
                    d.skip(1); //tex.magFilter = d.readByte();
                    d.skip(1); //tex.mipDetail = d.readByte();
                    d.skip(1); //tex.unknown = d.readByte();
                    d.skip(4); // padding?
                    d.skip(2); //tex.unknown2 = d.readShort();
                    m.textures.Add(tex);
                }

                int head = 0x20;

                if (d.Endian != Endianness.Little)
                {
                    while (head != 0)
                    {
                        head = d.readInt();
                        int nameStart = d.readInt();

                        string name = d.readString(nameOffset + nameStart, -1);

                        int pos        = d.pos();
                        int valueCount = d.readInt();
                        d.skip(4);

                        // Material properties should always have 4 values. Use 0 for remaining values.
                        float[] values = new float[4];
                        for (int i = 0; i < values.Length; i++)
                        {
                            if (i < valueCount)
                            {
                                values[i] = d.readFloat();
                            }
                            else
                            {
                                values[i] = 0;
                            }
                        }
                        //m.entries.Add(name, values);

                        d.seek(pos);

                        if (head == 0)
                        {
                            d.skip(0x20 - 8);
                        }
                        else
                        {
                            d.skip(head - 8);
                        }
                    }
                }

                if (propoff == p.texprop1)
                {
                    propoff = p.texprop2;
                }
                else if (propoff == p.texprop2)
                {
                    propoff = p.texprop3;
                }
                else if (propoff == p.texprop3)
                {
                    propoff = p.texprop4;
                }
            }

            return(mats);
        }
예제 #12
0
    public PolyMapLoaderT3(string x, string y, string goal, string start, string buttons, string customers)
    {
        polyData = new PolyData();
        string xFile        = prefix + x + postfix;
        string yFile        = prefix + y + postfix;
        string goalFile     = prefix + goal + postfix;
        string startFile    = prefix + start + postfix;
        string buttonsFile  = prefix + buttons + postfix;
        string customerFile = prefix + customers + postfix;

        System.IO.StreamReader xReader      = new System.IO.StreamReader(xFile);
        System.IO.StreamReader yReader      = new System.IO.StreamReader(yFile);
        System.IO.StreamReader buttonReader = new System.IO.StreamReader(buttonsFile);

        string   xpos, ypos;
        PolyNode curFigure     = new PolyNode();
        int      curFirstPoint = 0;
        int      index         = 0;
        bool     newOne        = true;

        while ((xpos = xReader.ReadLine()) != null)
        {
            ypos = yReader.ReadLine();              // xFile and yFile matches each other

            int curButton = int.Parse(buttonReader.ReadLine());

            // Här funkar det inte
            float xfloat;
            float yfloat;

            xpos = xpos.Replace(",", ".");
            ypos = ypos.Replace(",", ".");

            Vector3 curVec = new Vector3(float.Parse(xpos), 1f, float.Parse(ypos));


            curFigure.vertices.Add(curVec);

            polyData.buttons.Add(curButton);

            //New Figure
            if (curButton == 3)
            {
                polyData.figures.Add(curFigure);
                curFigure = new PolyNode();

                Line newLine1 = new Line(curVec, polyData.nodes[curFirstPoint]);
                Line newLine2 = new Line(polyData.nodes[index - 1], curVec);

                polyData.lines.Add(newLine1);
                polyData.lines.Add(newLine2);
                curFirstPoint = index + 1;
                newOne        = true;
            }
            else
            {
                if (polyData.nodes.Count != 0 && !newOne)
                {
                    Line newLine = new Line(polyData.nodes[index - 1], curVec);
                    polyData.lines.Add(newLine);
                }
                newOne = false;
            }
            polyData.nodes.Add(curVec);
            index++;
        }

        xReader.Close();
        yReader.Close();
        buttonReader.Close();

        string line;

        // read start
        System.IO.StreamReader file;
        file = new System.IO.StreamReader(startFile);
        while ((line = file.ReadLine()) != null)
        {
            string[] pos = line.Split(' ');
            polyData.start.Add(new Vector3(float.Parse(pos[0]) - 1, 1, float.Parse(pos[1]) - 1));
        }
        file.Close();

        // read end
        file = new System.IO.StreamReader(goalFile);
        while ((line = file.ReadLine()) != null)
        {
            string[] pos = line.Split(' ');
            polyData.end.Add(new Vector3(float.Parse(pos[0]) - 1, 1, float.Parse(pos[1]) - 1));
        }
        file.Close();

        // read customers
        file = new System.IO.StreamReader(customerFile);
        while ((line = file.ReadLine()) != null)
        {
            string[] pos = line.Split(' ');
            polyData.customers.Add(new Vector3(float.Parse(pos[0]) - 1, 1, float.Parse(pos[1]) - 1));
        }

        /*System.IO.StreamReader buttonReader = new System.IO.StreamReader (buttonsFile);
         * string button;
         * while ((button = buttonReader.ReadLine ()) != null) {
         *      polyData.buttons.Add (Convert.ToInt32(button));
         * }
         * buttonReader.Close ();*/
    }
        /// <summary>
        /// 统计数据初始化
        /// </summary>
        private void initData()
        {
            list               = new List <PolyData>();
            polydata           = new PolyData();
            polydata.PlaceName = "温哥华";
            polydata.X         = -122.9856932188265;
            polydata.Y         = 49.31473826915955;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "维多利亚";
            polydata.X         = -123.5725403242023;
            polydata.Y         = 48.68274907875484;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "华盛顿";
            polydata.X         = -76.94979490634647;
            polydata.Y         = 38.91738753487638;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "墨西哥城";
            polydata.X         = -99.14502956293464;
            polydata.Y         = 19.46453454379436;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "危地马拉";
            polydata.X         = -90.53756250004767;
            polydata.Y         = 14.638845654204122;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "哈瓦那";
            polydata.X         = -82.42665837247868;
            polydata.Y         = 23.081544106735578;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "金斯敦";
            polydata.X         = -76.80646878637968;
            polydata.Y         = 18.02563058349792;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "太子港";
            polydata.X         = -72.35997341103229;
            polydata.Y         = 18.589906646359267;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "加拉加斯";
            polydata.X         = -66.91245230016885;
            polydata.Y         = 10.516244738939125;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "乔治敦";
            polydata.X         = -58.20002988958967;
            polydata.Y         = 6.792022724054252;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "基多";
            polydata.X         = -78.55911023762702;
            polydata.Y         = -0.18242941291198278;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "卡亚俄";
            polydata.X         = -76.86063928841438;
            polydata.Y         = -11.990470304348502;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "拉巴斯";
            polydata.X         = -68.17078792034965;
            polydata.Y         = -16.482107764724816;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "亚松森";
            polydata.X         = -57.68766722451156;
            polydata.Y         = -25.169702028538108;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "圣地亚哥";
            polydata.X         = -70.68068784795692;
            polydata.Y         = -33.460045944097;
            list.Add(polydata);

            polydata           = new PolyData();
            polydata.PlaceName = "布宜诺斯艾利斯";
            polydata.X         = -58.424611762608485;
            polydata.Y         = -34.6788822398775;
            list.Add(polydata);
        }
예제 #14
0
    public PolyGraphCreator(PolyData data)
    {
        possibleLines = new List <Line> ();

        this.findLines(data);
    }