private void GenerateHole() { //Find the last point var lastPoint = points.Last(); //Choose n random points around this point var samplePoints = new List<Vector3>(); //Find offset point var offset = MathfEx.OffsetPointByAngleXZ(Vector3.zero, Random.value * 360f, options.offsetRadius * lastPoint.radius, transform.rotation); for(int i = 0; i < options.holeSampleCount; i++) { //Choose angle and distance float randAngle = Random.Range(0f, Mathf.PI * 2); float randDistance = Random.Range(0f, options.holeScaleFactor * (lastPoint.radius / 2f)); //Add this point samplePoints.Add(MathfEx.OffsetPointByAngleXZ(offset + lastPoint.position, randAngle, randDistance, transform.rotation, true)); } //Find the convex hull of these points holeHull = new Hull(samplePoints); //Spawn the flag this.SpawnFlag(); //Generate player position playerPosition = this.GeneratePlayerPosition(); }
private void GenerateFairwayPoints() { float rad = Random.Range(options.minRadius, options.maxRadius); //First add the origin point points.Add(new FairwayPoint { position = origin, radius = rad }); //There must be at least one options.pointCount = Mathf.Max(options.pointCount, 1); float angle = 0f; //Run from 0 to n - 1 for(int i = 0; i < (options.pointCount - 1); i++) { //Find where to offset from Vector3 originPoint = points[i].position; //Compute the random angle angle += Random.Range(-options.angleRange, options.angleRange); //Calculate the new point Vector3 newPoint = MathfEx.OffsetPointByAngleXZ(originPoint, angle, options.distance, transform.rotation); rad = Random.Range(options.minRadius, options.maxRadius); if(i == (options.pointCount - 2)) rad = options.maxRadius * options.holeScaleFactor; //And add it into the list of points points.Add(new FairwayPoint { position = newPoint, radius = rad }); } }