public List <T> GetEntitiesAtPos(Vector2f pos) { if (level == MAX_LEVEL) { return(entities); } List <T> returnEntities = new List <T>(); List <T> childReturnEntities = new List <T>(); FloatRect boundsRect = bounds.AsSfmlFloatRect(); if (entities.Count > 0) { returnEntities = entities; } if (pos.X > boundsRect.Left + boundsRect.Width / 2.0f && pos.X < boundsRect.Left + boundsRect.Width) { if (pos.Y > boundsRect.Top + boundsRect.Height / 2.0f && pos.Y < boundsRect.Top + boundsRect.Height) { childReturnEntities = pSE.GetEntitiesAtPos(pos); returnEntities.AddRange(childReturnEntities); return(returnEntities); } else if (pos.Y > boundsRect.Top && pos.Y <= boundsRect.Top + boundsRect.Height / 2.0f) { childReturnEntities = pNE.GetEntitiesAtPos(pos); returnEntities.AddRange(childReturnEntities); return(returnEntities); } } else if (pos.X > boundsRect.Left && pos.X <= boundsRect.Left + boundsRect.Width / 2.0f) { if (pos.Y > boundsRect.Top + boundsRect.Height / 2.0f && pos.Y < boundsRect.Top + boundsRect.Height) { childReturnEntities = pSW.GetEntitiesAtPos(pos); returnEntities.AddRange(childReturnEntities); return(returnEntities); } else if (pos.Y > boundsRect.Top && pos.Y <= boundsRect.Top + boundsRect.Height / 2.0f) { childReturnEntities = pNW.GetEntitiesAtPos(pos); returnEntities.AddRange(childReturnEntities); return(returnEntities); } } return(returnEntities); }
public List <T> getEntitiesInArea(AABB area) { FloatRect areaRect = area.AsSfmlFloatRect(); var overscan = ENTITY_OVERSCAN; var gridSize = ENTITY_GRID_SIZE; FloatRect rect = new FloatRect(areaRect.Left - overscan, areaRect.Top - overscan, areaRect.Width + (overscan * 2), areaRect.Height + (overscan * 2)); var startX = (int)rect.Left / gridSize; var startY = (int)rect.Top / gridSize; var width = (int)rect.Width / gridSize + 1; var height = (int)rect.Height / gridSize + 1; return(this.getInGridRect(startX, startY, startX + width, startY + height)); }