Nez.Portable/Physics/SpatialHash.cs
/// <summary>
/// returns all objects in cells that the bounding box intersects
/// </summary>
/// <returns>The neighbors.</returns>
/// <param name="bounds">Bounds.</param>
/// <param name="layerMask">Layer mask.</param>
returns all objects in cells that the bounding box intersects
returns all objects in cells that the bounding box intersects
public HashSet<Collider> aabbBroadphase(ref RectangleF bounds, Collider excludeCollider, int layerMask)
        {
            _tempHashset.Clear();
            var p1 = cellCoords(bounds.x, bounds.y);
            var p2 = cellCoords(bounds.right, bounds.bottom);
            for (var x = p1.X; x <= p2.X; x++)
            {
                for (var y = p1.Y; y <= p2.Y; y++)
                {
                    var cell = cellAtPosition(x, y);
                    if (cell == null)
                        continue;
                    for (var i = 0; i < cell.Count; i++)
                    {
                        var collider = cell[i];
                        if (collider == excludeCollider || !Flags.isFlagSet(layerMask, collider.physicsLayer))
                            continue;
                        if (bounds.intersects(collider.bounds))
                            _tempHashset.Add(collider);
                    }
                }
            }
            return _tempHashset;
        }
public HashSet < Collider > aabbBroadphase ( ref RectangleF bounds , Collider excludeCollider , int layerMask ) { _tempHashset . Clear ( ) ; var p1 = cellCoords ( bounds . x , bounds . y ) ; var p2 = cellCoords ( bounds . right , bounds . bottom ) ; for ( var x = p1 . X ; x <= p2 . X ; x ++ ) { for ( var y = p1 . Y ; y <= p2 . Y ; y ++ ) { var cell = cellAtPosition ( x , y ) ; if ( cell == null ) continue ; for ( var i = 0 ; i < cell . Count ; i ++ ) { var collider = cell [ i ] ; if ( collider == excludeCollider || ! Flags . isFlagSet ( layerMask , collider . physicsLayer ) ) continue ; if ( bounds . intersects ( collider . bounds ) ) _tempHashset . Add ( collider ) ; } } } return _tempHashset ; }
returns all objects in cells that the bounding box intersects
returns all objects in cells that the bounding box intersects
// we have a cell. loop through and fetch all the Colliders // skip this collider if it is our excludeCollider or if it doesnt match our layerMask
None
RectangleF
ref
excludeCollider
Collider
layerMask
int
None
bounds
None