private static void CalculateMaxDistance(Vector3 point) { Vector3 intersectionPoint = projectionPlaneHorizontal.ClosestPointOnPlane(point); float horizontalDistance = projectionPlaneHorizontal.GetDistanceToPoint(point); float verticalDistance = projectionPlaneVertical.GetDistanceToPoint(point); float halfFrustumHeight = Mathf.Max(verticalDistance, horizontalDistance / aspect); float distance = halfFrustumHeight / Mathf.Tan(renderCamera.fieldOfView * 0.5f * Mathf.Deg2Rad); float distanceToCenter = (intersectionPoint - m_previewDirection * distance - boundsCenter).sqrMagnitude; if (distanceToCenter > maxDistance) { maxDistance = distanceToCenter; } }
private static void CalculateMaxDistance(Vector3 point) { Vector3 intersectionPoint = projectionPlaneHorizontal.ClosestPointOnPlane(point); Single horizontalDistance = projectionPlaneHorizontal.GetDistanceToPoint(point); Single verticalDistance = projectionPlaneVertical.GetDistanceToPoint(point); // Credit: https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html Single halfFrustumHeight = Mathf.Max(verticalDistance, horizontalDistance / aspect); Single distance = halfFrustumHeight / Mathf.Tan(renderCamera.fieldOfView * 0.5f * Mathf.Deg2Rad); Single distanceToCenter = (intersectionPoint - m_previewDirection * distance - boundsCenter).sqrMagnitude; if (distanceToCenter > maxDistance) { maxDistance = distanceToCenter; } }
private static void CalculateMaxDistance(Vector3 point) { #if DEBUG_BOUNDS CreateDebugCube(point, Vector3.zero, new Vector3(0.5f, 0.5f, 0.5f)); #endif Vector3 intersectionPoint = projectionPlaneHorizontal.ClosestPointOnPlane(point); float horizontalDistance = projectionPlaneHorizontal.GetDistanceToPoint(point); float verticalDistance = projectionPlaneVertical.GetDistanceToPoint(point); // Credit: https://docs.unity3d.com/Manual/FrustumSizeAtDistance.html float halfFrustumHeight = Mathf.Max(verticalDistance, horizontalDistance / aspect); float distance = halfFrustumHeight / Mathf.Tan(renderCamera.fieldOfView * 0.5f * Mathf.Deg2Rad); float distanceToCenter = (intersectionPoint - m_previewDirection * distance - boundsCenter).sqrMagnitude; if (distanceToCenter > maxDistance) { maxDistance = distanceToCenter; } }