Пример #1
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;
            }
        }
Пример #2
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;
        }
Пример #3
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);
        }