@@ -56,6 +56,7 @@ PathFinder::~PathFinder() {
56
56
void PathFinder::Clear () {
57
57
m_NodeGrid.clear ();
58
58
m_NodeDimension = SCENEGRIDSIZE;
59
+ m_Offset = Vector ();
59
60
}
60
61
61
62
int PathFinder::Create (int nodeDimension) {
@@ -72,8 +73,10 @@ int PathFinder::Create(int nodeDimension) {
72
73
m_WrapsX = g_SceneMan.SceneWrapsX ();
73
74
m_WrapsY = g_SceneMan.SceneWrapsY ();
74
75
76
+ m_Offset = Vector (nodeDimension * 0 .5f , nodeDimension * 0 .5f );
77
+
75
78
// Create and assign scene coordinate positions for all nodes.
76
- Vector nodePos = Vector (static_cast <float >(nodeDimension) / 2 .0F , static_cast <float >(nodeDimension) / 2 .0F );
79
+ Vector nodePos = Vector (static_cast <float >(nodeDimension) / 2 .0F , static_cast <float >(nodeDimension) / 2 .0F ) + m_Offset ;
77
80
m_NodeGrid.reserve (m_GridWidth * m_GridHeight);
78
81
for (int y = 0 ; y < m_GridHeight; ++y) {
79
82
// Make sure no cell centers are off the scene (since they can overlap the far edge of the scene).
@@ -454,10 +457,10 @@ std::vector<int> PathFinder::GetNodeIdsInBox(Box box) {
454
457
box.Unflip ();
455
458
456
459
// Get the extents of the box's potential influence on PathNodes and their connecting edges.
457
- int firstX = static_cast <int >(std::floor ((box.m_Corner .m_X / static_cast <float >(m_NodeDimension)) + 0 .5F ) - 1 );
458
- int lastX = static_cast <int >(std::floor (((box.m_Corner .m_X + box.m_Width ) / static_cast <float >(m_NodeDimension)) + 0 .5F ) + 1 );
459
- int firstY = static_cast <int >(std::floor ((box.m_Corner .m_Y / static_cast <float >(m_NodeDimension)) + 0 .5F ) - 1 );
460
- int lastY = static_cast <int >(std::floor (((box.m_Corner .m_Y + box.m_Height ) / static_cast <float >(m_NodeDimension)) + 0 .5F ) + 1 );
460
+ int firstX = static_cast <int >(std::floor ( (box.m_Corner .m_X / static_cast <float >(m_NodeDimension)) + 0 .5F ) - 1 );
461
+ int lastX = static_cast <int >(std::floor (((box.m_Corner .m_X + box.m_Width ) / static_cast <float >(m_NodeDimension)) + 0 .5F ) + 1 );
462
+ int firstY = static_cast <int >(std::floor ( (box.m_Corner .m_Y / static_cast <float >(m_NodeDimension)) + 0 .5F ) - 1 );
463
+ int lastY = static_cast <int >(std::floor (((box.m_Corner .m_Y + box.m_Height ) / static_cast <float >(m_NodeDimension)) + 0 .5F ) + 1 );
461
464
462
465
// Only iterate through the grid where the box overlaps any edges.
463
466
for (int nodeX = firstX; nodeX <= lastX; ++nodeX) {
0 commit comments