示例#1
0
        public void GetEntries(Microsoft.Xna.Framework.BoundingSphere boundingShape, IList <BroadPhaseEntry> overlaps)
        {
            //Create a bounding box based on the bounding sphere.
            //Compute the min and max of the bounding box.
            //Loop through the cells and select bounding boxes which overlap the x axis.
#if !WINDOWS
            Vector3 offset = new Vector3();
#else
            Vector3 offset;
#endif
            offset.X = boundingShape.Radius;
            offset.Y = offset.X;
            offset.Z = offset.Y;
            BoundingBox box;
            Vector3.Add(ref boundingShape.Center, ref offset, out box.Max);
            Vector3.Subtract(ref boundingShape.Center, ref offset, out box.Min);

            Int2 min, max;
            Grid2DSortAndSweep.ComputeCell(ref box.Min, out min);
            Grid2DSortAndSweep.ComputeCell(ref box.Max, out max);
            for (int i = min.Y; i <= max.Y; i++)
            {
                for (int j = min.Z; j <= max.Z; j++)
                {
                    //Grab the cell that we are currently in.
                    Int2 cellIndex;
                    cellIndex.Y = i;
                    cellIndex.Z = j;
                    GridCell2D cell;
                    if (owner.cellSet.TryGetCell(ref cellIndex, out cell))
                    {
                        //To fully accelerate this, the entries list would need to contain both min and max interval markers.
                        //Since it only contains the sorted min intervals, we can't just start at a point in the middle of the list.
                        //Consider some giant bounding box that spans the entire list.
                        for (int k = 0; k < cell.entries.count &&
                             cell.entries.Elements[k].item.boundingBox.Min.X <= box.Max.X; k++)   //TODO: Try additional x axis pruning? A bit of optimization potential due to overlap with AABB test.
                        {
                            bool intersects;
                            var  item = cell.entries.Elements[k].item;
                            boundingShape.Intersects(ref item.boundingBox, out intersects);
                            if (intersects && !overlaps.Contains(item))
                            {
                                overlaps.Add(item);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        public void Contains(ref BoundingSphere sphere, out ContainmentType result)
        {
            bool flag = false;

            for (int index = 0; index < 6; ++index)
            {
                PlaneIntersectionType result1 = PlaneIntersectionType.Front;
                sphere.Intersects(ref this.planes[index], out result1);
                switch (result1)
                {
                case PlaneIntersectionType.Front:
                    result = ContainmentType.Disjoint;
                    return;

                case PlaneIntersectionType.Intersecting:
                    flag = true;
                    break;
                }
            }
            result = flag ? ContainmentType.Intersects : ContainmentType.Contains;
        }
示例#3
0
        /// <summary>
        /// Containment test between this <see cref="BoundingFrustum"/> and specified <see cref="BoundingSphere"/>.
        /// </summary>
        /// <param name="sphere">A <see cref="BoundingSphere"/> for testing.</param>
        /// <param name="result">Result of testing for containment between this <see cref="BoundingFrustum"/> and specified <see cref="BoundingSphere"/> as an output parameter.</param>
        public void Contains(ref BoundingSphere sphere, out ContainmentType result)
        {
            bool intersects = false;

            for (int i = 0; i < PlaneCount; i += 1)
            {
                PlaneIntersectionType planeIntersectionType = default(PlaneIntersectionType);

                // TODO: We might want to inline this for performance reasons.
                sphere.Intersects(ref this.planes[i], out planeIntersectionType);
                switch (planeIntersectionType)
                {
                case PlaneIntersectionType.Front:
                    result = ContainmentType.Disjoint;
                    return;

                case PlaneIntersectionType.Intersecting:
                    intersects = true;
                    break;
                }
            }
            result = intersects ? ContainmentType.Intersects : ContainmentType.Contains;
        }
示例#4
0
 public void Intersects(ref BoundingSphere sphere, out PlaneIntersectionType result)
 {
     sphere.Intersects(ref this, out result);
 }
示例#5
0
 public PlaneIntersectionType Intersects(BoundingSphere sphere)
 {
     return(sphere.Intersects(this));
 }