Exemplo n.º 1
0
        /// <summary>
        /// Merges this bounding volume with a second one. The resulting
        /// bounding volume is returned as a new object and will contain the
        /// original volumes completely. The returned value will be of the
        /// same bounding type as the caller.
        /// </summary>
        /// <param name="volume">Volume to merge with</param>
        /// <returns>New volume that contains the original two</returns>
        public override BoundingVolume Merge(BoundingVolume volume)
        {
            if (volume == null)
            {
                return(this.Clone());
            }

            Vector3     center  = Vector3.Zero;
            Vector3     extents = Vector3.Zero;
            BoundingBox result  = new BoundingBox();

            switch (volume.BoundingType)
            {
            case BoundingType.AABB:
                BoundingBox bb = volume as BoundingBox;
                center  = bb.Center;
                extents = bb.Extents;
                MergeAABB(ref center, ref extents, result);
                break;

            case BoundingType.OBB:
                OrientedBoundingBox obb = volume as OrientedBoundingBox;
                MergeOBB(obb, result);
                break;

            case BoundingType.Sphere:
                BoundingSphere sphere = volume as BoundingSphere;
                center = sphere.Center;
                float r = sphere.Radius;
                extents = new Vector3(r, r, r);
                MergeAABB(ref center, ref extents, result);
                break;
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Merges this bounding volume with a second one. The resulting bounding
        /// volume is stored locally and will contain the original volumes completely.
        /// </summary>
        /// <param name="volume">Volume to merge with</param>
        public override void MergeLocal(BoundingVolume volume)
        {
            if (volume == null)
            {
                return;
            }

            float   radius;
            Vector3 center;

            switch (volume.BoundingType)
            {
            case BoundingType.AABB:
                BoundingBox box = volume as BoundingBox;
                radius = box.Extents.Length();
                center = box.Center;
                MergeSphere(ref radius, ref center, this);
                return;

            case BoundingType.Sphere:
                BoundingSphere sphere = volume as BoundingSphere;
                radius = sphere.Radius;
                center = sphere.Center;
                MergeSphere(ref radius, ref center, this);
                return;

            case Bounding.BoundingType.OBB:
                OrientedBoundingBox obb = volume as OrientedBoundingBox;
                MergeOBB(obb, this);
                return;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Merges this bounding volume with a second one. The resulting bounding
        /// volume is stored locally and will contain the original volumes completely.
        /// </summary>
        /// <param name="volume">Volume to merge with</param>
        public override void MergeLocal(BoundingVolume volume)
        {
            if (volume == null)
            {
                return;
            }

            Vector3 center  = Vector3.Zero;
            Vector3 extents = Vector3.Zero;

            switch (volume.BoundingType)
            {
            case BoundingType.AABB:
                BoundingBox bb = volume as BoundingBox;
                center  = bb.Center;
                extents = bb.Extents;
                MergeAABB(ref center, ref extents, this);
                return;

            case BoundingType.OBB:
                OrientedBoundingBox obb = volume as OrientedBoundingBox;
                MergeOBB(obb, this);
                return;

            case BoundingType.Sphere:
                BoundingSphere sphere = volume as BoundingSphere;
                center = sphere.Center;
                float r = sphere.Radius;
                extents = new Vector3(r, r, r);
                MergeAABB(ref center, ref extents, this);
                return;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets this bounding volume to contain the specified volume or to copy from.
        /// </summary>
        /// <param name="volume">Volume to copy from</param>
        public override void Set(BoundingVolume volume)
        {
            switch (volume.BoundingType)
            {
            case BoundingType.AABB:
                BoundingBox bb = volume as BoundingBox;
                m_center  = bb.Center;
                m_extents = bb.Extents;
                return;

            case BoundingType.Sphere:
                BoundingSphere sphere = volume as BoundingSphere;
                m_center = sphere.Center;
                float r = sphere.Radius;
                m_extents = new Vector3(r, r, r);
                return;

            case BoundingType.OBB:
                OrientedBoundingBox obb = volume as OrientedBoundingBox;
                if (!obb.CorrectCorners)
                {
                    obb.ComputeCorners();
                }
                ComputeFromPoints(obb.Corners);
                return;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Determines if the oriented bounding box is contained within this bounding volume.
        /// </summary>
        /// <param name="obb">Oriented bounding box to test</param>
        /// <returns>Containment type</returns>
        public override ContainmentType Contains(OrientedBoundingBox obb)
        {
            if (obb == null)
            {
                return(ContainmentType.Outside);
            }

            return(obb.Contains(this));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Tests if the oriented bounding box intersects with this bounding sphere.
        /// </summary>
        /// <param name="obb">Oriented bounding box to test</param>
        /// <returns>True if they intersect</returns>
        public override bool Intersects(OrientedBoundingBox obb)
        {
            if (obb == null)
            {
                return(false);
            }

            return(obb.Intersects(this));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Merge takes care of OBB case. Input is the OBB to merge with this
        /// AABB to create a merged volume that is stored in the result.
        /// </summary>
        /// <param name="obb">OrientedBoundingBox to merge with</param>
        /// <param name="result">Resulting AABB</param>
        private void MergeOBB(OrientedBoundingBox obb, BoundingBox result)
        {
            if (!obb.CorrectCorners)
            {
                obb.ComputeCorners();
            }

            Vector3 min = this.Min;
            Vector3 max = this.Max;

            for (int i = 0; i < obb.Corners.Length; i++)
            {
                Vector3 temp = obb.Corners[i];
                if (temp.X < min.X)
                {
                    min.X = temp.X;
                }
                else if (temp.X > max.X)
                {
                    max.X = temp.X;
                }
                if (temp.Y < min.Y)
                {
                    min.Y = temp.Y;
                }
                else if (temp.Y > max.Y)
                {
                    max.Y = temp.Y;
                }
                if (temp.Z < min.Z)
                {
                    min.Z = temp.Z;
                }
                else if (temp.Z > max.Z)
                {
                    max.Z = temp.Z;
                }
            }

            Vector3 resCenter;

            Vector3.Add(ref min, ref max, out resCenter);
            Vector3.Multiply(ref resCenter, 0.5f, out resCenter);

            Vector3 resExtents;

            Vector3.Subtract(ref max, ref m_center, out resExtents);

            result.Center  = resCenter;
            result.Extents = resExtents;
        }
Exemplo n.º 8
0
 public OrientedBoundingBox(OrientedBoundingBox source)
 {
     m_center         = source.Center;
     m_xAxis          = source.XAxis;
     m_yAxis          = source.YAxis;
     m_zAxis          = source.ZAxis;
     m_extents        = source.Extents;
     m_correctCorners = source.CorrectCorners;
     m_corners        = new Vector3[8];
     Vector3[] srcCorners = source.Corners;
     for (int i = 0; i < 8; i++)
     {
         m_corners[i] = srcCorners[i];
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Handles the merge case for OBB. Input is the oriented bounding box,
        /// which is used with the properties of this Sphere to create a
        /// merged volume that is stored in the result.
        /// </summary>
        /// <param name="obb">Oriented bounding box to merge with</param>
        /// <param name="result">Sphere to store the result</param>
        private void MergeOBB(OrientedBoundingBox obb, BoundingSphere result)
        {
            if (!obb.CorrectCorners)
            {
                obb.ComputeCorners();
            }

            //Save this sphere's radius/center (result sphere may be this sphere)
            float   sRad    = m_radius;
            Vector3 sCenter = m_center;

            //Use the input sphere and compute it to contain the OBB's corners
            result.ComputeFromPoints(obb.Corners);

            //Use our saved radius/center and merge the result sphere with this
            result.MergeSphere(ref sRad, ref sCenter, result);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Merges this bounding volume with a second one. The resulting
        /// bounding volume is returned as a new object and will contain the
        /// original volumes completely. The returned value will be of the
        /// same bounding type as the caller.
        /// </summary>
        /// <param name="volume">Volume to merge with</param>
        /// <returns>New volume that contains the original two</returns>
        public override BoundingVolume Merge(BoundingVolume volume)
        {
            if (volume == null)
            {
                return(this.Clone());
            }

            float   radius;
            Vector3 center;

            BoundingSphere result = new BoundingSphere();

            switch (volume.BoundingType)
            {
            case BoundingType.AABB:
                BoundingBox box = volume as BoundingBox;
                radius = box.Extents.Length();
                center = box.Center;
                MergeSphere(ref radius, ref center, result);
                break;

            case BoundingType.Sphere:
                BoundingSphere sphere = volume as BoundingSphere;
                radius = sphere.Radius;
                center = sphere.Center;
                MergeSphere(ref radius, ref center, result);
                break;

            case Bounding.BoundingType.OBB:
                OrientedBoundingBox obb = volume as OrientedBoundingBox;
                MergeOBB(obb, result);
                break;
            }

            return(result);
        }
Exemplo n.º 11
0
 public override ContainmentType Contains(OrientedBoundingBox obb)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 12
0
 public override bool Intersects(OrientedBoundingBox obb)
 {
     throw new System.NotImplementedException();
 }
Exemplo n.º 13
0
 /// <summary>
 /// Determines if the oriented bounding box is contained within this bounding volume.
 /// </summary>
 /// <param name="obb">Oriented bounding box to test</param>
 /// <returns>Containment type</returns>
 public abstract ContainmentType Contains(OrientedBoundingBox obb);
Exemplo n.º 14
0
 /// <summary>
 /// Tests if the volume intersects with this bounding volume.
 /// </summary>
 /// <param name="obb">Oriented bounding box to test</param>
 /// <returns>True if they intersect</returns>
 public abstract bool Intersects(OrientedBoundingBox obb);