public Bound3 Merge(Bound3 boundingBox)
        {
            var result = this;

            if (result.min.x < boundingBox.min.x)
            {
                result.min.x = boundingBox.min.x;
            }
            if (result.max.x > boundingBox.max.x)
            {
                result.max.x = boundingBox.max.x;
            }

            if (result.min.y < boundingBox.min.y)
            {
                result.min.y = boundingBox.min.y;
            }
            if (result.max.y > boundingBox.max.y)
            {
                result.max.y = boundingBox.max.y;
            }

            if (result.min.z < boundingBox.min.z)
            {
                result.min.z = boundingBox.min.z;
            }
            if (result.max.z > boundingBox.max.z)
            {
                result.max.z = boundingBox.max.z;
            }

            return(result);
        }
        public bool Intersects(Bound3 boundingBox)
        {
            Vec3 clampedLocation;

            if (center.x > boundingBox.max.x)
            {
                clampedLocation.x = boundingBox.max.x;
            }
            else if (center.x < boundingBox.min.x)
            {
                clampedLocation.x = boundingBox.min.x;
            }
            else
            {
                clampedLocation.x = center.x;
            }

            if (center.y > boundingBox.max.y)
            {
                clampedLocation.y = boundingBox.max.y;
            }
            else if (center.y < boundingBox.min.y)
            {
                clampedLocation.y = boundingBox.min.y;
            }
            else
            {
                clampedLocation.y = center.y;
            }

            if (center.z > boundingBox.max.z)
            {
                clampedLocation.z = boundingBox.max.z;
            }
            else if (center.z < boundingBox.min.z)
            {
                clampedLocation.z = boundingBox.min.z;
            }
            else
            {
                clampedLocation.z = center.z;
            }

            return(clampedLocation.DistanceSquared(center) <= (radius * radius));
        }
 public bool Intersects(Bound3 boundingBox)
 {
     return
         (!(boundingBox.min.x > max.x || boundingBox.min.y > max.y || boundingBox.min.z > max.z ||
            min.x > boundingBox.max.x || min.y > boundingBox.max.y || min.z > boundingBox.max.z));
 }
Beispiel #4
0
 public bool Intersects(Bound3 boundingBox)
 {
     return(x >= boundingBox.left && x <= boundingBox.right && y >= boundingBox.bottom && y <= boundingBox.top && z >= boundingBox.back && z <= boundingBox.front);
 }
Beispiel #5
0
 public void Intersects(Bound3 boundingBox, out bool result)
 {
     result = x >= boundingBox.left && x <= boundingBox.right && y >= boundingBox.bottom && y <= boundingBox.top && z >= boundingBox.back && z <= boundingBox.front;
 }
Beispiel #6
0
        public bool IntersectsBounds(Bound3 boundingBox, out float result)
        {
            // X
            if (Math.Abs(direction.x) < MathTools.epsilon && (origin.x < boundingBox.min.x || origin.x > boundingBox.max.x))
            {
                //If the ray isn't pointing along the axis at all, and is outside of the box's interval, then it can't be intersecting.
                result = 0;
                return(false);
            }

            float tmin = 0, tmax = float.MaxValue;
            float inverseDirection = 1 / direction.x;
            float t1 = (boundingBox.min.x - origin.x) * inverseDirection;
            float t2 = (boundingBox.max.x - origin.x) * inverseDirection;

            if (t1 > t2)
            {
                float temp = t1;
                t1 = t2;
                t2 = temp;
            }

            tmin = Math.Max(tmin, t1);
            tmax = Math.Min(tmax, t2);
            if (tmin > tmax)
            {
                result = 0;
                return(false);
            }

            // Y
            if (Math.Abs(direction.y) < MathTools.epsilon && (origin.y < boundingBox.min.y || origin.y > boundingBox.max.y))
            {
                //If the ray isn't pointing along the axis at all, and is outside of the box's interval, then it can't be intersecting.
                result = 0;
                return(false);
            }

            inverseDirection = 1 / direction.y;
            t1 = (boundingBox.min.y - origin.y) * inverseDirection;
            t2 = (boundingBox.max.y - origin.y) * inverseDirection;
            if (t1 > t2)
            {
                float temp = t1;
                t1 = t2;
                t2 = temp;
            }

            tmin = Math.Max(tmin, t1);
            tmax = Math.Min(tmax, t2);
            if (tmin > tmax)
            {
                result = 0;
                return(false);
            }

            // Z
            if (Math.Abs(direction.z) < MathTools.epsilon && (origin.z < boundingBox.min.z || origin.z > boundingBox.max.z))
            {
                //If the ray isn't pointing along the axis at all, and is outside of the box's interval, then it can't be intersecting.
                result = 0;
                return(false);
            }

            inverseDirection = 1 / direction.z;
            t1 = (boundingBox.min.z - origin.z) * inverseDirection;
            t2 = (boundingBox.max.z - origin.z) * inverseDirection;
            if (t1 > t2)
            {
                float temp = t1;
                t1 = t2;
                t2 = temp;
            }

            tmin = Math.Max(tmin, t1);
            tmax = Math.Min(tmax, t2);
            if (tmin > tmax)
            {
                result = 0;
                return(false);
            }
            result = tmin;

            return(true);
        }
 public static void Intersects(ref Frustum3 boundingFrustum, ref Bound3 boundingBox, out bool result)
 {
     throw new NotImplementedException();
 }
 public bool Intersects(Bound3 boundingBox)
 {
     throw new NotImplementedException();
 }
 public static void Contains(ref Frustum3 boundingFrustum, ref Bound3 boundingBox, out ContainmentTypes result)
 {
     throw new NotImplementedException();
 }
 public ContainmentTypes Contains(Bound3 boundingBox)
 {
     throw new NotImplementedException();
 }