Example #1
0
        private static bool Overlaps(Capsule3D capsule, Line3D line)
        {
            var center     = capsule.Position;
            var halfHeight = capsule.Height / 2;
            var halfVector = new vec3(0, halfHeight, 0);
            var p1         = line.P1 - center;
            var p2         = line.P2 - center;
            var r          = capsule.Radius;

            if (capsule.IsOrientable)
            {
                var inverse = capsule.InverseOrientation;
                p1 = inverse * p1;
                p2 = inverse * p2;
            }

            // One (or both) of the line endpoints are contained within the spherical caps.
            if (Sphere.Contains(p1, halfVector, r) || Sphere.Contains(p2, halfVector, r) ||
                Sphere.Contains(p1, -halfVector, r) || Sphere.Contains(p2, -halfVector, r))
            {
                return(true);
            }

            var d1       = Utilities.LengthSquared(p1.swizzle.xz);
            var d2       = Utilities.LengthSquared(p2.swizzle.xz);
            var rSquared = r * r;

            // One (or both) of the line endpoints are contained within the cylinder.
            if ((d1 <= rSquared && Math.Abs(p1.y) <= halfHeight) ||
                (d2 <= rSquared && Math.Abs(p2.y) <= halfHeight))
            {
                return(true);
            }

            d1 = Utilities.DistanceSquaredToLine(vec2.Zero, p1.swizzle.xz, p2.swizzle.xz, out var t);

            // The flat line is outside the flat circle.
            if (d1 > rSquared)
            {
                return(false);
            }

            var result = p1 + (p2 - p1) * t;

            if (Math.Abs(result.y) <= halfHeight)
            {
                return(true);
            }

            d1 = Utilities.DistanceSquaredToLine(halfVector, p1, p2, out _);
            d2 = Utilities.DistanceSquaredToLine(-halfVector, p1, p2, out _);

            // The line passes through one of the spherical caps.
            return(d1 <= rSquared || d2 <= rSquared);
        }
Example #2
0
        private static bool Overlaps(Capsule3D capsule, Shape3D other)
        {
            switch (other.Type)
            {
            case ShapeTypes3D.Capsule: return(Overlaps(capsule, (Capsule3D)other));

            case ShapeTypes3D.Cylinder: return(Overlaps(capsule, (Cylinder)other));

            case ShapeTypes3D.Line: return(Overlaps(capsule, (Line3D)other));

            case ShapeTypes3D.Sphere: return(Overlaps(capsule, (Sphere)other));
            }

            return(false);
        }
Example #3
0
 private static bool Overlaps(Box box, Capsule3D capsule)
 {
     // TODO: Finish this implementation.
     return(false);
 }
Example #4
0
 private static bool Overlaps(Capsule3D capsule, Sphere sphere)
 {
     // TODO: Finish this implementation.
     return(false);
 }
Example #5
0
 private static bool Overlaps(Capsule3D capsule, Cylinder cylinder)
 {
     // TODO: Finish this implementation.
     return(false);
 }