//find list of objects near/adjacent to current object public List <GridObjectInterface> checkNeighbouringBlocks(GridObjectInterface obj) { List <GridObjectInterface> neighbours = new List <GridObjectInterface>(); Vector3 gridBlock; int gridX, gridY, gridZ; //loop though adjacent blocks containing objects to test for potential collisions for (int i = 0; i < obj.getCapacity(); i++) { gridBlock = obj.getLocation(i); gridX = (int)(gridBlock.X); gridY = (int)(gridBlock.Y); gridZ = (int)(gridBlock.Z); //check all 8 blocks surrounding object (as well as block object is in) for nearby objects for (int x = -1; x < 2; x++) { for (int y = -1; y < 2; y++) { for (int z = -1; z < 2; z++) { checkForDuplicates(neighbours, obj, gridX + x, gridY + y, gridZ + z); } } } } return(neighbours); }
//clear pointers to grid and remove object from grid public void deregisterObject(GridObjectInterface obj) { for (int i = 0; i < obj.getCapacity(); i++) { Vector3 gridBlock = obj.getLocation(i); grid[(int)Math.Round(gridBlock.X), (int)Math.Round(gridBlock.Y), (int)Math.Round(gridBlock.Z)].Remove(obj); } obj.removeAllLocations(); }
//find list of objects near/adjacent to current object public List<GridObjectInterface> checkNeighbouringBlocks(GridObjectInterface obj) { List<GridObjectInterface> neighbours = new List<GridObjectInterface>(); Vector3 gridBlock; int gridX, gridY, gridZ; //loop though adjacent blocks containing objects to test for potential collisions for (int i = 0; i < obj.getCapacity(); i++) { gridBlock = obj.getLocation(i); gridX = (int)(gridBlock.X); gridY = (int)(gridBlock.Y); gridZ = (int)(gridBlock.Z); //check all 8 blocks surrounding object (as well as block object is in) for nearby objects for (int x = -1; x < 2; x++) for (int y = -1; y < 2; y++) for (int z = -1; z < 2; z++) checkForDuplicates(neighbours, obj, gridX + x, gridY + y, gridZ + z); } return neighbours; }