Exemplo n.º 1
0
        private static bool Overlaps(Box box, Cylinder cylinder)
        {
            bool isOrientable1    = box.IsOrientable;
            bool isFixedVertical1 = box.IsFixedVertical;
            bool isOrientable2    = cylinder.IsOrientable;

            var p1 = box.Position;
            var p2 = cylinder.Position;

            // The cylinder is non-orientable (while the box is either non-orientable or fixed-vertical).
            if (!isOrientable2 && (isFixedVertical1 || !isOrientable1))
            {
                // Check Y delta.
                var dY = Math.Abs(p1.y - p2.y);

                if (dY > (box.Height + cylinder.Height) / 2)
                {
                    return(false);
                }

                // The calculations below are the same for fixed-vertical boxes, except that the boxes flat vertices
                // need to be rotated relative to the cylinder.
                if (isFixedVertical1)
                {
                    p1 = p2 + box.Orientation.Inverse * (p1 - p2);
                }

                // Check cylinder zone (compared to the box).
                var dX         = Math.Abs(p1.x - p2.x);
                var dZ         = Math.Abs(p1.z - p2.z);
                var halfBounds = box.Bounds / 2;
                var withinX    = dX <= halfBounds.x;
                var withinZ    = dZ <= halfBounds.z;

                // This means that the cylinder's central axis is within the box (along the flat XZ plane).
                if (withinX && withinZ)
                {
                    return(true);
                }

                var radius = cylinder.Radius;

                // Check X delta.
                if (withinX)
                {
                    return(dZ <= halfBounds.z + radius);
                }

                // Check Z delta.
                if (withinZ)
                {
                    return(dX <= halfBounds.x + radius);
                }

                var flatP1      = p1.swizzle.xz;
                var flatP2      = p2.swizzle.xz;
                var flatCorners = new []
                {
                    new vec2(halfBounds.x, halfBounds.z),
                    new vec2(halfBounds.x, -halfBounds.z),
                    new vec2(-halfBounds.x, halfBounds.z),
                    new vec2(-halfBounds.x, -halfBounds.z)
                };

                return(flatCorners.Any(p => Utilities.DistanceSquared(flatP1 + p, flatP2) <= radius * radius));
            }

            // TODO: Finish this (for orientable boxes/cylinders).
            return(false);
        }
Exemplo n.º 2
0
 private static bool Overlaps(Cylinder cylinder, Sphere sphere)
 {
     return(false);
 }
Exemplo n.º 3
0
 private static bool Overlaps(Cylinder cylinder, Line3D line)
 {
     return(false);
 }
Exemplo n.º 4
0
 private static bool Overlaps(Box box, Cylinder cylinder)
 {
     // TODO: Finish this implementation.
     return(false);
 }
Exemplo n.º 5
0
 private static bool Overlaps(Cylinder cylinder, Sphere sphere)
 {
     // TODO: Finish this implementation.
     return(false);
 }
Exemplo n.º 6
0
 private static bool Overlaps(Capsule3D capsule, Cylinder cylinder)
 {
     // TODO: Finish this implementation.
     return(false);
 }