Пример #1
0
        private bool IntersectsLineSegment
        (
            Vector3 pointA,
            Vector3 pointB,
            float segmentRadius
        )
        {
            if (SpringSphereCollider.IntersectsLineSegment(
                    transform, new Vector3(0f, 0f, 0f), radius, pointA, pointB, segmentRadius))
            {
                return(true);
            }

            if (SpringSphereCollider.IntersectsLineSegment(
                    transform, new Vector3(0f, height, 0f), radius, pointA, pointB, segmentRadius))
            {
                return(true);
            }

            var localPointA    = transform.InverseTransformPoint(pointA);
            var localPointB    = transform.InverseTransformPoint(pointB);
            var otherRadius    = transform.InverseTransformDirection(segmentRadius, 0f, 0f).magnitude;
            var combinedRadius = radius + otherRadius;

            var intersectionPoint = new Vector3(0f, 0f, 0f);

            return(ComputeCylinderIntersection(localPointA, localPointB, combinedRadius, ref intersectionPoint) &&
                   intersectionPoint.y > 0f &&
                   intersectionPoint.y < height);
        }