private void Query(Box2 bounds, QuadNode node, List <T> results) { lock (syncLock) { if (node == null) { return; } if (bounds.Intersects(node.Bounds)) { foreach (T quadObject in node.Objects) { if (bounds.Intersects(quadObject.Bounds)) { results.Add(quadObject); } } foreach (QuadNode childNode in node.Nodes) { Query(bounds, childNode, results); } } } }
public bool AnyEntitiesIntersecting(MapId mapId, Box2 box) { foreach (var entity in GetEntities()) { var transform = entity.Transform; if (transform.MapID != mapId) { continue; } if (entity.TryGetComponent <BoundingBoxComponent>(out var component)) { if (box.Intersects(component.WorldAABB)) { return(true); } } else { if (box.Contains(transform.WorldPosition)) { return(true); } } } return(false); }
public IEnumerable <IEntity> GetEntitiesIntersecting(MapId mapId, Box2 position) { foreach (var entity in GetEntities()) { var transform = entity.Transform; if (transform.MapID != mapId) { continue; } if (entity.TryGetComponent <BoundingBoxComponent>(out var component)) { if (position.Intersects(component.WorldAABB)) { yield return(entity); } } else { if (position.Contains(transform.WorldPosition)) { yield return(entity); } } } }
/// <summary> /// Tests a physBody against every other registered physBody. /// </summary> /// <param name="physBody">Body being tested.</param> /// <param name="colliderAABB">The AABB of the physBody being tested. This can be IPhysBody.WorldAABB, or a modified version of it.</param> /// <param name="results">An empty list that the function stores all colliding bodies inside of.</param> internal void DoCollisionTest(IPhysBody physBody, Box2 colliderAABB, List <IPhysBody> results) { foreach (var body in GetCollidablesForLocation(colliderAABB)) { // TODO: Terrible hack to fix bullets crashing the server. // Should be handled with deferred physics events instead. if (body.Owner.Deleted) { continue; } if (!body.CollisionEnabled) { continue; } if ((physBody.CollisionMask & body.CollisionLayer) == 0x0) { continue; } if (physBody.MapID != body.MapID || physBody == body || !colliderAABB.Intersects(body.WorldAABB)) { continue; } results.Add(body); } }
public IEnumerable <IEntity> GetEntitiesIntersecting(Box2 position) { foreach (var entity in GetEntities()) { if (entity.TryGetComponent <BoundingBoxComponent>(out var component)) { if (position.Intersects(component.WorldAABB)) { yield return(entity); } } else { var transform = entity.GetComponent <ITransformComponent>(); if (position.Contains(transform.Position)) { yield return(entity); } } } }
public bool AnyEntitiesIntersecting(Box2 position) { foreach (var entity in GetEntities()) { if (entity.TryGetComponent <BoundingBoxComponent>(out var component)) { if (position.Intersects(component.WorldAABB)) { return(true); } } else { var transform = entity.GetComponent <ITransformComponent>(); if (position.Contains(transform.WorldPosition)) { return(true); } } } return(false); }
/// <summary> /// Tests a physBody against every other registered physBody. /// </summary> /// <param name="physBody">Body being tested.</param> /// <param name="colliderAABB">The AABB of the physBody being tested. This can be IPhysBody.WorldAABB, or a modified version of it.</param> /// <param name="results">An empty list that the function stores all colliding bodies inside of.</param> internal void DoCollisionTest(IPhysBody physBody, Box2 colliderAABB, List <IPhysBody> results) { foreach (var body in GetCollidablesForLocation(colliderAABB)) { if (!body.CollisionEnabled) { continue; } if ((physBody.CollisionMask & body.CollisionLayer) == 0x0) { continue; } if (physBody.MapID != body.MapID || physBody == body || !colliderAABB.Intersects(body.WorldAABB)) { continue; } results.Add(body); } }
/// <summary> /// Tests a collidable against every other registered collidable. /// </summary> /// <param name="collidable">Collidable being tested.</param> /// <param name="colliderAABB">The AABB of the collidable being tested. This can be ICollidable.WorldAABB, or a modified version of it.</param> /// <param name="results">An empty list that the function stores all colliding bodies inside of.</param> public void DoCollisionTest(ICollidable collidable, Box2 colliderAABB, List <ICollidable> results) { foreach (var body in GetCollidablesForLocation(colliderAABB)) { if (!body.CollisionEnabled) { continue; } if ((collidable.CollisionMask & body.CollisionLayer) == 0x0) { continue; } if (collidable.MapID != body.MapID || collidable == body || !colliderAABB.Intersects(body.WorldAABB)) { continue; } results.Add(body); } }