BEPUphysics.BroadPhaseSystems.SortAndSweep.Grid2DSortAndSweep.ComputeCell C# (CSharp) Method

ComputeCell() static private method

static private ComputeCell ( Vector3 &v, Int2 &cell ) : void
v Vector3
cell Int2
return void
        internal static void ComputeCell(ref Vector3 v, out Int2 cell)
        {
            cell.Y = (int)Math.Floor(v.Y * cellSizeInverse);
            cell.Z = (int)Math.Floor(v.Z * cellSizeInverse);
        }

Usage Example

Beispiel #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);
                            }
                        }
                    }
                }
            }
        }
All Usage Examples Of BEPUphysics.BroadPhaseSystems.SortAndSweep.Grid2DSortAndSweep::ComputeCell