Esempio n. 1
0
    public void GenerateSandtraps()
    {
        //How many do we need to spawn?
        var amountToSpawn = Random.Range(sandtrapOptions.minSandtrapCount, sandtrapOptions.maxSandtrapCount);

        //Choose the smallest -- either the number of fairways or the number of
        //possible points which they can be spawned at.. this prevents infinite while loops
        amountToSpawn = Mathf.Min(amountToSpawn, fairway.points.Count - 1);

        //The chosen points
        var chosenIdxs = new int[amountToSpawn];

        //Number of tries, number of successful tries
        int tries = 0, spawned = 0;

        while (spawned < amountToSpawn)
        {
            //Choose a random node in the fairway which isnt:
            // a) the green
            // b) the tee
            // c) chosen from an existing fairway point

            //This is taking a long time.. so stop it
            if (++tries > (amountToSpawn * 10))
            {
                break;
            }

            //Compute random index
            int idx = Random.Range(1, fairway.points.Count);

            //Already contains it? try again..
            if (chosenIdxs.Contains(idx))
            {
                continue;
            }

            //Add the index
            chosenIdxs[spawned] = idx;

            //Choose a random node
            var randomNode = fairway.points[idx];

            //Calculate dist
            var dist = (randomNode.radius * Random.Range(sandtrapOptions.minRadiusDist, 1f));

            //Find offset
            var offset = randomNode.position + MathfEx.Polar2CartXZ(Random.value * 360f, dist, Quaternion.identity);

            //Calculate position
            var pos = offset;

            //Make a sandtrap here
            sandtraps.Add(new Sandtrap(pos, transform, sandtrapOptions));

            //Increment the count
            spawned++;
        }
    }
Esempio n. 2
0
    // Start is called before the first frame update
    void Start()
    {
        for (int i = 0; i < 25; i++)
        {
            points.Add(centre.position + MathfEx.Polar2CartXZ(Random.value * 360, Random.value * 2f, Quaternion.identity));
        }

        hull = new Hull(points);
        // smoothHull = MathfEx.smoothPolygon(hull.points);
    }
Esempio n. 3
0
    public void GenerateHull()
    {
        var points = new List <Vector3>();

        for (int i = 0; i < options.hullPoints; i++)
        {
            //p is initially the centre point
            var p = this.centroid;

            //Offset a random xz
            p += MathfEx.Polar2CartXZ(Random.value * 360f, Random.Range(options.minRadius, options.maxRadius), Quaternion.identity);

            //Add to the list of points
            points.Add(p);
        }

        //Make a new hull with these points
        this.hull = new Hull(points);
    }