void GridSectorizer::GetEntries(DataStructures::List<void*>& intersectionList, const float minX, const float minY, const float maxX, const float maxY) { #ifdef _USE_ORDERED_LIST DataStructures::OrderedList<void*, void*>* cell; #else DataStructures::List<void*>* cell; #endif int xStart, yStart, xEnd, yEnd, xCur, yCur; unsigned index; xStart=WorldToCellXOffsetAndClamped(minX); yStart=WorldToCellYOffsetAndClamped(minY); xEnd=WorldToCellXOffsetAndClamped(maxX); yEnd=WorldToCellYOffsetAndClamped(maxY); intersectionList.Clear(true, _FILE_AND_LINE_); for (xCur=xStart; xCur <= xEnd; ++xCur) { for (yCur=yStart; yCur <= yEnd; ++yCur) { cell = grid+yCur*gridCellWidthCount+xCur; for (index=0; index < cell->Size(); ++index) intersectionList.Insert(cell->operator [](index), _FILE_AND_LINE_); } } }
void GridSectorizer::MoveEntry(void* entry, const float sourceMinX, const float sourceMinY, const float sourceMaxX, const float sourceMaxY, const float destMinX, const float destMinY, const float destMaxX, const float destMaxY) { RakAssert(cellWidth>0.0f); RakAssert(sourceMinX < sourceMaxX && sourceMinY < sourceMaxY); RakAssert(destMinX < destMaxX && destMinY < destMaxY); if (PositionCrossesCells(sourceMinX, sourceMinY, destMinX, destMinY)==false && PositionCrossesCells(destMinX, destMinY, destMinX, destMinY)==false) { return; } int xStartSource, yStartSource, xEndSource, yEndSource; int xStartDest, yStartDest, xEndDest, yEndDest; int xCur, yCur; xStartSource=WorldToCellXOffsetAndClamped(sourceMinX); yStartSource=WorldToCellYOffsetAndClamped(sourceMinY); xEndSource=WorldToCellXOffsetAndClamped(sourceMaxX); yEndSource=WorldToCellYOffsetAndClamped(sourceMaxY); xStartDest=WorldToCellXOffsetAndClamped(destMinX); yStartDest=WorldToCellYOffsetAndClamped(destMinY); xEndDest=WorldToCellXOffsetAndClamped(destMaxX); yEndDest=WorldToCellYOffsetAndClamped(destMaxY); // Remove source that is not in dest for (xCur=xStartSource; xCur <= xEndSource; ++xCur) { for (yCur=yStartSource; yCur <= yEndSource; ++yCur) { if (xCur < xStartDest || xCur > xEndDest || yCur < yStartDest || yCur > yEndDest) { grid[yCur*gridCellWidthCount+xCur].RemoveIfExists(entry); } } } // Add dest that is not in source for (xCur=xStartDest; xCur <= xEndDest; ++xCur) { for (yCur=yStartDest; yCur <= yEndDest; ++yCur) { if (xCur < xStartSource || xCur > xEndSource || yCur < yStartSource || yCur > yEndSource) { grid[yCur*gridCellWidthCount+xCur].Insert(entry,entry, true); } } } }
void GridSectorizer::RemoveEntry(void *entry, const float minX, const float minY, const float maxX, const float maxY) { RakAssert(cellWidth > 0.0f); RakAssert(minX <= maxX && minY <= maxY); int xStart, yStart, xEnd, yEnd, xCur, yCur; xStart = WorldToCellXOffsetAndClamped(minX); yStart = WorldToCellYOffsetAndClamped(minY); xEnd = WorldToCellXOffsetAndClamped(maxX); yEnd = WorldToCellYOffsetAndClamped(maxY); for (xCur = xStart; xCur <= xEnd; ++xCur) { for (yCur = yStart; yCur <= yEnd; ++yCur) grid[yCur * gridCellWidthCount + xCur].RemoveIfExists(entry); } }
void GridSectorizer::AddEntry(void *entry, const float minX, const float minY, const float maxX, const float maxY) { RakAssert(cellWidth > 0.0f); RakAssert(minX < maxX && minY < maxY); int xStart, yStart, xEnd, yEnd, xCur, yCur; xStart = WorldToCellXOffsetAndClamped(minX); yStart = WorldToCellYOffsetAndClamped(minY); xEnd = WorldToCellXOffsetAndClamped(maxX); yEnd = WorldToCellYOffsetAndClamped(maxY); for (xCur = xStart; xCur <= xEnd; ++xCur) { for (yCur = yStart; yCur <= yEnd; ++yCur) { #ifdef _USE_ORDERED_LIST grid[yCur * gridCellWidthCount + xCur].Insert(entry, entry, true); #else grid[yCur * gridCellWidthCount + xCur].Insert(entry, __FILE__, __LINE__); #endif } } }