Skip to content

Commit 97b7d3a

Browse files
authored
Merge pull request #477 from GeneralsOnlineDevelopmentTeam/seer/fix/partition-cell-coords
bugfix(partitioning): Correct cell world coordinate calculation for overlap checks
2 parents 1193ebb + 7286f77 commit 97b7d3a

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

Generals/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,13 +1887,19 @@ void PartitionData::doCircleFillPrecise(Real centerX, Real centerY, Real radius)
18871887
ThePartitionManager->worldToCell(centerX + radius, centerY + radius, &maxCellX, &maxCellY);
18881888

18891889
Real cellSize = ThePartitionManager->getCellSize();
1890+
Real halfCellSize = cellSize * 0.5f;
18901891

18911892
for (Int x = minCellX; x <= maxCellX; ++x)
18921893
{
18931894
for (Int y = minCellY; y <= maxCellY; ++y)
18941895
{
1895-
Real cellWorldX = x * cellSize;
1896-
Real cellWorldY = y * cellSize;
1896+
// getCellCenterPos returns the world-space center of the cell, accounting for
1897+
// m_worldExtents.lo offset. Subtracting halfCellSize gives the lower-left corner,
1898+
// which is what doesCircleOverlapCell expects.
1899+
Real cellWorldX, cellWorldY;
1900+
ThePartitionManager->getCellCenterPos(x, y, cellWorldX, cellWorldY);
1901+
cellWorldX -= halfCellSize;
1902+
cellWorldY -= halfCellSize;
18971903

18981904
if (doesCircleOverlapCell(centerX, centerY, radius, cellWorldX, cellWorldY, cellSize))
18991905
{

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,13 +1891,19 @@ void PartitionData::doCircleFillPrecise(Real centerX, Real centerY, Real radius)
18911891
ThePartitionManager->worldToCell(centerX + radius, centerY + radius, &maxCellX, &maxCellY);
18921892

18931893
Real cellSize = ThePartitionManager->getCellSize();
1894+
Real halfCellSize = cellSize * 0.5f;
18941895

18951896
for (Int x = minCellX; x <= maxCellX; ++x)
18961897
{
18971898
for (Int y = minCellY; y <= maxCellY; ++y)
18981899
{
1899-
Real cellWorldX = x * cellSize;
1900-
Real cellWorldY = y * cellSize;
1900+
// getCellCenterPos returns the world-space center of the cell, accounting for
1901+
// m_worldExtents.lo offset. Subtracting halfCellSize gives the lower-left corner,
1902+
// which is what doesCircleOverlapCell expects.
1903+
Real cellWorldX, cellWorldY;
1904+
ThePartitionManager->getCellCenterPos(x, y, cellWorldX, cellWorldY);
1905+
cellWorldX -= halfCellSize;
1906+
cellWorldY -= halfCellSize;
19011907

19021908
if (doesCircleOverlapCell(centerX, centerY, radius, cellWorldX, cellWorldY, cellSize))
19031909
{

0 commit comments

Comments
 (0)