protected override Vector3 CalculateStartPosition(ref Vector3 anchorPosition, Camera visibleInCamera, bool intense) { Vector3 start = anchorPosition; Vector3 randomDir; if (visibleInCamera == null) { randomDir = UnityEngine.Random.onUnitSphere; } else { Vector3 randomScreenPoint = new Vector3 ( UnityEngine.Random.Range((float)visibleInCamera.pixelWidth * 0.3f, (float)visibleInCamera.pixelWidth * 0.7f), UnityEngine.Random.Range((float)visibleInCamera.pixelHeight * 0.3f, (float)visibleInCamera.pixelHeight * 0.7f), Random.Range(visibleInCamera.nearClipPlane, visibleInCamera.farClipPlane) ); randomDir = (visibleInCamera.ScreenToWorldPoint(randomScreenPoint) - visibleInCamera.transform.position).normalized; } start += (randomDir * (intense ? IntenseDistance.Random() : NormalDistance.Random())); start.x += StartXVariance.Random(); start.y = StartYVariance.Random() + StartYBase.Random(); start.z += StartZVariance.Random(); // if the start is too close to the anchor point, push it back float minDistance = (intense ? IntenseDistance.Minimum : NormalDistance.Minimum); if (Vector3.Distance(start, anchorPosition) < minDistance) { Vector3 startDir = (start - anchorPosition).normalized; start = anchorPosition + (startDir * minDistance); } return(start); }
protected override Vector3 CalculateStartPosition(ref Vector3 anchorPosition, Camera visibleInCamera, bool intense) { Vector3 start = anchorPosition; Vector3 randomDir; if (visibleInCamera == null) { randomDir = UnityEngine.Random.onUnitSphere; } else { Vector3 randomScreenPoint = new Vector3 ( UnityEngine.Random.Range((float)Screen.width * 0.2f, (float)Screen.width * 0.8f), UnityEngine.Random.Range((float)Screen.height * 0.2f, (float)Screen.height * 0.8f), visibleInCamera.farClipPlane * 0.5f ); randomDir = visibleInCamera.ScreenToWorldPoint(randomScreenPoint).normalized; } randomDir.y = Mathf.Abs(randomDir.y); randomDir *= (intense ? IntenseDistance.Random() : NormalDistance.Random()); randomDir.y = StartYBase.Random(); start += randomDir; start.x += StartXVariance.Random(); start.y += StartYVariance.Random(); start.z += StartZVariance.Random(); // if the start is too close to the anchor point, push it back float minDistance = (intense ? IntenseDistance.Minimum : NormalDistance.Minimum); if (Vector3.Distance(start, anchorPosition) < minDistance) { Vector3 startDir = (start - anchorPosition).normalized; start = anchorPosition + (startDir * minDistance); } return(start); }
/// <summary> /// Compute start position /// </summary> /// <param name="anchorPosition">Anchor position</param> /// <param name="visibleInCamera">Visible in camera?</param> /// <param name="intense">Intense (close) or normal (far)</param> /// <param name="cloudOnly">Cloud only with no bolt?</param> /// <returns>Start position</returns> protected override Vector3 CalculateStartPosition(ref Vector3 anchorPosition, Camera visibleInCamera, bool intense, bool cloudOnly) { // TODO: Implement cloudOnly Vector3 visibleMin, visibleMax; float width, height; CalculateVisibleBounds(out visibleMin, out visibleMax, out width, out height); Vector3 start = new Vector3(visibleMin.x + (width * UnityEngine.Random.Range(0.2f, 0.8f)), visibleMin.y + (height * StartYBase.Random()), 0.0f); start.x += (width * StartXVariance.Random()); start.y += (height * StartYVariance.Random()); return(start); }