Example #1
0
        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);
        }
Example #2
0
        public Bound3 Merge(Bound3 boundingBox2)
        {
            Bound3 result;

            if (min.x < boundingBox2.min.x)
            {
                result.min.x = min.x;
            }
            else
            {
                result.min.x = boundingBox2.min.x;
            }

            if (min.y < boundingBox2.min.y)
            {
                result.min.y = min.y;
            }
            else
            {
                result.min.y = boundingBox2.min.y;
            }

            if (min.z < boundingBox2.min.z)
            {
                result.min.z = min.z;
            }
            else
            {
                result.min.z = boundingBox2.min.z;
            }

            if (max.x > boundingBox2.max.x)
            {
                result.max.x = max.x;
            }
            else
            {
                result.max.x = boundingBox2.max.x;
            }

            if (max.y > boundingBox2.max.y)
            {
                result.max.y = max.y;
            }
            else
            {
                result.max.y = boundingBox2.max.y;
            }

            if (max.z > boundingBox2.max.z)
            {
                result.max.z = max.z;
            }
            else
            {
                result.max.z = boundingBox2.max.z;
            }

            return(result);
        }
Example #3
0
        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 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;
 }
 public bool Intersects(Bound3 boundingBox)
 {
     return(x >= boundingBox.left && x <= boundingBox.right && y >= boundingBox.bottom && y <= boundingBox.top && z >= boundingBox.back && z <= boundingBox.front);
 }
Example #6
0
        public bool Intersects(Bound3 boundingBox, out float result)
        {
            // X
            if (Math.Abs(direction.x) < MathUtilities.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) < MathUtilities.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) < MathUtilities.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);
        }
Example #7
0
 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));
 }
Example #8
0
 public static void Intersects(ref Frustum3 boundingFrustum, ref Bound3 boundingBox, out bool result)
 {
     throw new NotImplementedException();
 }
Example #9
0
 public bool Intersects(Bound3 boundingBox)
 {
     throw new NotImplementedException();
 }
Example #10
0
 public static void Contains(ref Frustum3 boundingFrustum, ref Bound3 boundingBox, out ContainmentTypes result)
 {
     throw new NotImplementedException();
 }
Example #11
0
 public ContainmentTypes Contains(Bound3 boundingBox)
 {
     throw new NotImplementedException();
 }