Пример #1
0
        private static bool CheckSphereCapsuleIntersection(Shape s0, Shape s1)
        {
            Shape sphere;
            Shape capsule;

            if (s0._shapeTypeValue == ShapeType.Sphere && s1._shapeTypeValue == ShapeType.Capsule)
            {
                sphere  = s0;
                capsule = s1;
            }
            else if (s0._shapeTypeValue == ShapeType.Capsule && s1._shapeTypeValue == ShapeType.Sphere)
            {
                sphere  = s1;
                capsule = s0;
            }
            else
            {
                throw new ArgumentException(
                          string.Format(
                              "CheckSphereCapsuleIntersection must take exactly one Sphere and one Capsule. s0 is {0} and s1 is {1}.",
                              s0._shapeTypeValue.ToString(),
                              s1._shapeTypeValue.ToString()));
            }

            // the sphere's coordinates must be in the first two parameters because the algorithm defaults to one of them if the lines are parallel
            // (or one is a point)
            return(Math_d.ClosestSegmentToSegmentSqrDistance(sphere._position0, sphere._position0, capsule._position0, capsule._position1)
                   < (capsule._extends0 + sphere._extends0) * (capsule._extends0 + sphere._extends0));
        }
Пример #2
0
        private static bool CheckCapsuleIntersection(Shape s0, Shape s1)
        {
            if (s0._shapeTypeValue != ShapeType.Capsule || s1._shapeTypeValue != ShapeType.Capsule)
            {
                throw new ArgumentException(
                          string.Format(
                              "CheckCapsuleIntersection must take exactly two Capsules. s0 is {0} and s1 is {1}.",
                              s0._shapeTypeValue.ToString(),
                              s1._shapeTypeValue.ToString()));
            }

            return(Math_d.ClosestSegmentToSegmentSqrDistance(s0._position0, s0._position1, s1._position0, s1._position1)
                   < (s0._extends0 + s1._extends0) * (s0._extends0 + s1._extends0));
        }