Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFA::FindPath(const Dali::Vector3& positionFrom, const Dali::Vector3& positionTo)
{
Dali::Vector3 outPosFrom;
- uint32_t polyIndexFrom;
+ FaceIndex polyIndexFrom;
auto result = mNavigationMesh->FindFloor(positionFrom, outPosFrom, polyIndexFrom);
Scene3D::Algorithm::WayPointList waypoints;
if(result)
{
Dali::Vector3 outPosTo;
- uint32_t polyIndexTo;
+ FaceIndex polyIndexTo;
result = mNavigationMesh->FindFloor(positionTo, outPosTo, polyIndexTo);
if(result)
// Get waypoints
waypoints = FindPath(polyIndexFrom, polyIndexTo);
- // replace first and last waypoint
- auto& wpFrom = static_cast<WayPointData&>(waypoints[0]);
- auto& wpTo = static_cast<WayPointData&>(waypoints.back());
+ if(!waypoints.empty())
+ {
+ // replace first and last waypoint
+ auto& wpFrom = static_cast<WayPointData&>(waypoints[0]);
+ auto& wpTo = static_cast<WayPointData&>(waypoints.back());
- Vector2 fromCenter(wpFrom.point3d.x, wpFrom.point3d.y);
- wpFrom.point3d = outPosFrom;
- wpFrom.point2d = fromCenter - Vector2(outPosFrom.x, outPosFrom.y);
+ Vector2 fromCenter(wpFrom.point3d.x, wpFrom.point3d.y);
+ wpFrom.point3d = outPosFrom;
+ wpFrom.point2d = fromCenter - Vector2(outPosFrom.x, outPosFrom.y);
- Vector2 toCenter(wpTo.point3d.x, wpTo.point3d.y);
- wpTo.point3d = outPosTo;
- wpTo.point2d = toCenter - Vector2(outPosTo.x, outPosTo.y);
- wpTo.point3d = outPosTo;
+ Vector2 toCenter(wpTo.point3d.x, wpTo.point3d.y);
+ wpTo.point3d = outPosTo;
+ wpTo.point2d = toCenter - Vector2(outPosTo.x, outPosTo.y);
+ }
}
}
return waypoints;
}
-Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFA::FindPath(uint32_t sourcePolyIndex, uint32_t targetPolyIndex)
+Scene3D::Algorithm::WayPointList PathFinderAlgorithmSPFA::FindPath(FaceIndex sourcePolyIndex, FaceIndex targetPolyIndex)
{
- auto nodeCount = uint32_t(mNodes.size());
- std::vector<float> dist;
- std::vector<uint32_t> prev;
- std::vector<bool> queued;
+ auto nodeCount = uint32_t(mNodes.size());
+ std::vector<float> dist;
+ std::vector<FaceIndex> prev;
+ std::vector<bool> queued;
dist.resize(mNodes.size());
prev.resize(mNodes.size());
queued.resize(mNodes.size());
- std::list<uint32_t> nodeQueue;
+ std::list<FaceIndex> nodeQueue;
[[maybe_unused]] auto sourcePos = Dali::Vector3(Face(sourcePolyIndex)->center);
}
// Compute distances for each node back to the source
- auto u = targetPolyIndex;
- std::list<uint32_t> q;
+ auto u = targetPolyIndex;
+ std::list<FaceIndex> q;
if(prev[u] != Scene3D::Algorithm::NavigationMesh::NULL_FACE || u == sourcePolyIndex)
{
while(u != Scene3D::Algorithm::NavigationMesh::NULL_FACE)
mNodes.resize(faceCount);
// for each face build the list
- for(auto i = 0u; i < faceCount; ++i)
+ // TODO : Currently, we are assume that FaceNodeIndex is matched with FaceIndex 1:1. This might be changed in future.
+ for(FaceNodeIndex i = 0u; i < faceCount; ++i)
{
auto& node = mNodes[i];
const auto* face = mNavigationMesh->GetFace(i);