Exemplo n.º 1
0
        // Use this for initialization
        public void Start()
        {
            // create initial delaunay triangulation (three far-away points)
            m_delaunay = Delaunay.Create();

            // add auxiliary vertices as unowned
            foreach (var vertex in m_delaunay.Vertices)
            {
                m_ownership.Add(vertex, EOwnership.UNOWNED);
            }

            m_fishManager = new FishManager();

            // create polygon of rectangle window for intersection with voronoi
            float z          = Vector2.Distance(m_meshFilter.transform.position, Camera.main.transform.position);
            var   bottomLeft = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, z));
            var   topRight   = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, z));

            m_meshRect = new Polygon2D(
                new List <Vector2>()
            {
                new Vector2(bottomLeft.x, bottomLeft.z),
                new Vector2(bottomLeft.x, topRight.z),
                new Vector2(topRight.x, topRight.z),
                new Vector2(topRight.x, bottomLeft.z)
            });

            VoronoiDrawer.CreateLineMaterial();
        }
Exemplo n.º 2
0
        private void OnRenderObject()
        {
            GL.PushMatrix();

            // Set transformation matrix for drawing to
            // match our transform
            GL.MultMatrix(transform.localToWorldMatrix);

            VoronoiDrawer.Draw(m_delaunay);

            GL.PopMatrix();
        }
Exemplo n.º 3
0
        // Use this for initialization
        public void Start()
        {
            // create initial delaunay triangulation (three far-away points)
            m_delaunay = Delaunay.Create();

            // add auxiliary vertices as unowned
            foreach (var vertex in m_delaunay.Vertices)
            {
                m_ownership.Add(vertex, EOwnership.UNOWNED);
            }

            m_fishManager = new FishManager();

            // create polygon of rectangle window for intersection with voronoi
            float z          = Vector2.Distance(m_meshFilter.transform.position, Camera.main.transform.position);
            var   bottomLeft = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, z));
            var   topRight   = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, z));

            m_meshRect = new Polygon2D(
                new List <Vector2>()
            {
                new Vector2(bottomLeft.x, bottomLeft.z),
                new Vector2(bottomLeft.x, topRight.z),
                new Vector2(topRight.x, topRight.z),
                new Vector2(topRight.x, bottomLeft.z)
            });

            if (useFirstPlayerAi)
            {
                GameObject goVoronoiAI1 = new GameObject("Ai player 1");
                m_voronoiAI1 = goVoronoiAI1.AddComponent <VoronoiAI>();
                m_voronoiAI1.SetPlayer1(true);

                m_voronoiAI1.SetCorners(bottomLeft, topRight);

                m_voronoiAI1.DrawBorders = true;
                m_voronoiAI1.DrawDelauneyTriangulation = true;
                m_voronoiAI1.DrawVoronoiDiagram        = true;

                StrategyHandler sh1 = new StrategyHandler()
                                      .Add(new OutsideCHStrategy(1f, new RandomStrategy(1)));
                //.Add(new GridStrategy(6, 4))
                //.Add(new RandomStrategy(25));
                //.Add(new LargestCellStrategy());
                m_voronoiAI1.SetStrategyHandler(sh1);
                // Select a score function used by the AI
                // new AreaScore();
                // new DistanceScore();
                // new StandardDeviationScore();
                // new CircumferenceScore();
                m_voronoiAI1.SetScoreFunction(new AreaScore());
            }
            if (useSecondPlayerAi)
            {
                GameObject goVoronoiAI2 = new GameObject("Ai player 2");

                m_voronoiAI2 = goVoronoiAI2.AddComponent <VoronoiAI>();
                m_voronoiAI2.SetPlayer1(false);
                m_voronoiAI2.SetCorners(bottomLeft, topRight);

                if (!useFirstPlayerAi)
                {
                    m_voronoiAI2.DrawBorders = true;
                    m_voronoiAI2.DrawDelauneyTriangulation = true;
                    m_voronoiAI2.DrawVoronoiDiagram        = true;
                }

                StrategyHandler sh2 = new StrategyHandler()
                                      //.Add(new OutsideCHStrategy(1f, new RandomStrategy(4)))
                                      //.Add(new GridStrategy(6, 4))
                                      .Add(new RandomStrategy(25));
                //.Add(new LargestCellStrategy());
                m_voronoiAI2.SetStrategyHandler(sh2);
                // Select a score function used by the AI
                // new AreaScore();
                // new DistanceScore();
                // new StandardDeviationScore();
                // new CircumferenceScore();
                m_voronoiAI2.SetScoreFunction(new AreaScore());
            }

            VoronoiDrawer.CreateLineMaterial();
        }