public int[] getPossibleCollidableObjects(cAABB bounds) { List <int> all = new List <int>(); int topLeftIndex = GetCellIndexAtWorldPos(bounds.topLeft); int topRightIndex = GetCellIndexAtWorldPos(bounds.getTopRight()); int bottomRightIndex = GetCellIndexAtWorldPos(bounds.rightBottom); int bottomLeftIndex = GetCellIndexAtWorldPos(bounds.getLeftBottom()); if (topLeftIndex == bottomRightIndex) { all.AddRange(grid[topLeftIndex].getAll()); } else { if (topLeftIndex == bottomLeftIndex || bottomLeftIndex == bottomRightIndex) { all.AddRange(grid[topLeftIndex].getAll()); all.AddRange(grid[bottomRightIndex].getAll()); } else { all.AddRange(grid[topLeftIndex].getAll()); all.AddRange(grid[topRightIndex].getAll()); all.AddRange(grid[bottomRightIndex].getAll()); all.AddRange(grid[bottomLeftIndex].getAll()); } } return(all.ToArray()); }
public void HandleObject(int id, cAABB bounds) { int topLeftIndex = GetCellIndexAtWorldPos(bounds.topLeft); int topRightIndex = GetCellIndexAtWorldPos(bounds.getTopRight()); int bottomRightIndex = GetCellIndexAtWorldPos(bounds.rightBottom); int bottomLeftIndex = GetCellIndexAtWorldPos(bounds.getLeftBottom()); if (topLeftIndex == bottomRightIndex) { grid[topLeftIndex].add(id); } else { if (topLeftIndex == bottomLeftIndex || bottomLeftIndex == bottomRightIndex) { grid[topLeftIndex].add(id); grid[bottomRightIndex].add(id); } else { grid[topLeftIndex].add(id); grid[topRightIndex].add(id); grid[bottomRightIndex].add(id); grid[bottomLeftIndex].add(id); } } }