コード例 #1
0
    public static Vector2 SquareDeletedPosition(float width, float height, float xOffset = 0, float yOffset = 0)
    {
        float x = Mathf.Abs(width) / 2, y = Mathf.Abs(height) / 2;          //Obliczanie środka ekranu
        int   screenPart = Random.Range(1, 5);                              //Wybieranie części ekranu w której ma zostać

        //wylosowany punkt

        /* W zależności od miejsca wylosowanego punktu
         * gra oblicza pozycję punktu losując losowy punkt w
         * jednej z czterech części ekranu.
         */

        switch (screenPart)
        {
        case 1:
            return(RandomPoints.GetVector2(xOffset, Screen.width - xOffset, yOffset, Screen.height / 2 - height / 2));

        case 2:
            return(RandomPoints.GetVector2(xOffset, Screen.width - xOffset, Screen.height / 2 + height / 2, Screen.height - yOffset));

        case 3:
            return(RandomPoints.GetVector2(xOffset, Screen.width / 2 - width / 2, yOffset, Screen.height - yOffset));

        case 4:
            return(RandomPoints.GetVector2(Screen.width / 2 + width / 2, Screen.width - xOffset, yOffset, Screen.height - yOffset));
        }
        throw new Exception("Coś się posypało");        //Ten wyjątek tak wiele mówi...
    }
コード例 #2
0
 public static Vector2 Position(float xOffset = 0, float yOffset = 0)
 {
     return(RandomPoints.GetVector2(xOffset, Screen.width - xOffset, yOffset, Screen.height - yOffset));
 }
コード例 #3
0
 public static Vector2 XPosition(float y, float xOffset = 0)
 {
     return(new Vector2(RandomPoints.GetPoint(xOffset, Screen.width - xOffset), y));
 }
コード例 #4
0
 public static Vector2 YPosition(float x, float yOffset = 0)
 {
     return(new Vector2(x, RandomPoints.GetPoint(yOffset, Screen.height - yOffset)));
 }
コード例 #5
0
 // Start is called before the first frame update
 void Start()
 {
     randomPoints = new RandomPoints(max_x, max_z, _y);
     //triangles = new List<Triangle>();
     doRelaxation = false;
 }
コード例 #6
0
    // Update is called once per frame
    void Update()
    {
        float rt = Time.realtimeSinceStartup;

        if (doTriangulation)
        {
            doTriangulation = false;
            if (!firstTriangulationDone)
            {
                Debug.Log("Get random points");
                // create random points
                randomPoints = new RandomPoints(max_x, max_z, Yplane);
                points       = randomPoints.CreateRandomPoints(pointsNum, VERBOSE);

                Debug.Log("Compute triangulation");
                triangulation = null;
                triangulation = new Triangulation(max_x, max_z, Yplane, points, VERBOSE, validateAfterEveryPoint);
                triangulation.ComputeTriangulation();
                firstTriangulationDone = true;

                if (showTimer)
                {
                    Debug.Log("(Triangulation) Timer: " + (Time.realtimeSinceStartup - rt) + " s");
                }
            }
            else
            {
                Debug.LogError("Triangulation has already been computed.");
            }
        }
        if (doVoronoi)
        {
            doVoronoi = false;
            if (!firstVoronoiDone && firstTriangulationDone)
            {
                Debug.Log("Convert triangulation to Voronoi");
                ConvertTriangulationToVoronoi();
                firstVoronoiDone = true;

                int numOfValidCells = 0;
                foreach (VoronoiCell cell in voronoi.voronoiCells)
                {
                    if (cell.isValid)
                    {
                        numOfValidCells++;
                    }
                }
                Debug.Log("Number of cells = " + numOfValidCells);
            }
            else if (!firstTriangulationDone)
            {
                Debug.LogError("Triangulation must be computed before the Voronoi.");
            }
            else
            {
                Debug.LogError("First Voronoi has already been computed.");
            }
        }

        if (doRelaxation)
        {
            doRelaxation = false;
            if (firstVoronoiDone)
            {
                if (relaxTimes < 0)
                {
                    relaxTimes = 0;
                }
                Debug.Log("The Voronoi will be relaxed " + relaxTimes + " time" + (relaxTimes != 1 ? "s." : "."));
                while (relaxTimesCounter < relaxTimes)
                {
                    totalRelaxesDone++;
                    Debug.Log("Apply Relaxation #" + totalRelaxesDone);
                    RelaxVoronoi();
                    ConvertTriangulationToVoronoi();
                    relaxTimesCounter++;

                    if (showTimer)
                    {
                        Debug.Log("(Relaxation) Timer: " + (Time.realtimeSinceStartup - rt) + " s");
                    }
                }
                relaxTimesCounter = 0;
            }
            else
            {
                Debug.LogError("The first Voronoi must be computed before the diagram is relaxed.");
            }
        }

        if (doMesh)
        {
            doMesh = false;
            if (!meshesCreated && firstVoronoiDone)
            {
                Debug.Log("Generate meshes");
                CreateMeshColumns();
                FindCellNeighbors();
                meshesCreated = true;
            }
            else if (meshesCreated)
            {
                Debug.LogError("Meshes have already been generated.");
            }
            else
            {
                Debug.LogError("The first Voronoi must be computed before the meshes are created.");
            }
        }

        if (doPerlin)
        {
            doPerlin = false;
            if (meshesCreated)
            {
                Debug.Log("Apply Perlin Noise to column heights");
                ApplyPerlinToVoronoi();
            }
            else
            {
                Debug.LogError("Meshes must be generated before noise is applied.");
            }
        }

        if (doRandomRipple)
        {
            doRandomRipple  = false;
            doRandomPathing = false;
            if (meshesCreated)
            {
                Debug.Log("Do random ripple (may need to reset first)");
                // rippleResetNeeded = true;
                ChooseRandomObjectToStartRipple();
            }
            else
            {
                Debug.LogError("Meshes must be generated before ripple is applied.");
            }
        }

        if (doRandomPathing)
        {
            doRandomPathing = false;
            if (meshesCreated)
            {
                Debug.Log("Do random pathing (may need to reset first)");
                // rippleResetNeeded = true;
                ChooseRandomObjectToStartPathing();
            }
            else
            {
                Debug.LogError("Meshes must be generated before pathing is applied.");
            }
        }

        if (resetRipples)
        {
            resetRipples = false;
            if (meshesCreated)
            {
                Debug.Log("Reset ripple");
                // reset all RippleColumn
                foreach (GameObject obj in meshObjects)
                {
                    obj.GetComponent <RippleColumn>().RESET = true;
                }
                // rippleResetNeeded = false;
            }
        }
        //showTimer = false;  // so timer only gets shown the first time Update() runs
    }