Exemplo n.º 1
0
        /// <summary>
        /// Calculate the area of intersection of this box and another.
        /// </summary>
        public AxisAlignedBox Intersection(AxisAlignedBox other)
        {
            if (IsNull || other.IsNull)
            {
                return(new AxisAlignedBox());
            }
            if (IsInfinite)
            {
                return(new AxisAlignedBox(other));
            }

            if (other.IsInfinite)
            {
                return(new AxisAlignedBox(this));
            }

            Vector3 min     = _minimum;
            Vector3 max     = _maximum;
            Vector3 minimum = other.Minimum;

            min.MakeCeil(minimum);
            Vector3 maximum = other.Maximum;

            max.MakeFloor(maximum);
            if (min.x < max.x &&
                min.y < max.y &&
                min.z < max.z)
            {
                return(new AxisAlignedBox(min, max));
            }

            return(new AxisAlignedBox());
        }
Exemplo n.º 2
0
        public void Merge(Aabb rhs)
        {
            Vector3 max = Center + HalfSize;

            max.MakeCeil(rhs.Center + rhs.HalfSize);

            Vector3 min = Center - HalfSize;

            min.MakeFloor(rhs.Center - rhs.HalfSize);

            if (float.IsInfinity(max.x) == false &&
                float.IsInfinity(max.y) == false &&
                float.IsInfinity(max.z) == false)
            {
                Center = (max + min) * 0.5f;
            }
            HalfSize = (max - min) * 0.5f;
        }
Exemplo n.º 3
0
        public void Merge(Vector3 points)
        {
            Vector3 max = Center + HalfSize;

            max.MakeCeil(points);

            Vector3 min = Center - HalfSize;

            min.MakeFloor(points);

            if (float.IsInfinity(max.x) == false &&
                float.IsInfinity(max.y) == false &&
                float.IsInfinity(max.z) == false)
            {
                Center = (max + min) * 0.5f;
            }

            HalfSize = (max - min) * 0.5f;
        }
Exemplo n.º 4
0
 /// <summary>Extends the box to encompass the specified point (if needed). </summary>
 public void Merge(Vector3 point)
 {
     if (_extent != Extent.Null)
     {
         if (_extent != Extent.Finite)
         {
             if (_extent != Extent.Infinite)
             {
                 throw new Exception(" Should never reach here");
             }
         }
         else
         {
             _maximum.MakeCeil(point);
             _minimum.MakeFloor(point);
         }
     }
     else
     {
         SetExtents(point, point);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Merges the passed in box into the current box. The result is the box which encompasses both.
 /// </summary>
 public void Merge(AxisAlignedBox rhs)
 {
     if (rhs._extent != Extent.Null &&
         _extent != Extent.Infinite)
     {
         if (rhs._extent == Extent.Infinite)
         {
             _extent = Extent.Infinite;
         }
         else if (_extent == Extent.Null)
         {
             SetExtents(rhs._minimum, rhs._maximum);
         }
         else
         {
             Vector3 min = _minimum;
             Vector3 max = _maximum;
             max.MakeCeil(rhs._maximum);
             min.MakeFloor(rhs._minimum);
             SetExtents(min, max);
         }
     }
 }