我正在进行一个SFML/C++项目,需要生成一个图形来连接障碍物以便于路径规划,因此我对生成导航网格非常感兴趣,我将应用boost A*算法。就像这样:
但是我在使用Boost Graph Library时遇到了很多问题(如果您有更合适的库,请告诉我)。首先,我创建了一个具有适当结构的adjacency_list:
感谢您提前的支持。
struct WayPoint{
sf::Vector2f pos;
};
struct WayPointConnection{
float dist;
};
typedef boost::adjacency_list<
boost::listS,
boost::vecS,
boost::undirectedS,
WayPoint,
WayPointConnection
> WayPointGraph;
typedef WayPointGraph::vertex_descriptor WayPointID;
typedef WayPointGraph::edge_descriptor WayPointConnectionID;
然后我创建了一个图形,并将我的障碍物的顶点添加到其中(目前仅为简单矩形):
while (i != rectangle.getPointCount()) {
sf::Vector2f pt1 (sf::Vector2f(rectangle.getPoint(i).x + mouseEvent.x, rectangle.getPoint(i).y + mouseEvent.y));
WayPointID wpID = boost::add_vertex(graph);
graph[wpID].pos = pt1;
i++;
}
现在变得更加复杂了,我需要浏览所有的顶点,并创建与这些顶点相邻的弧,同时不应穿过障碍物…… 我不知道如何使用Boost来编写此代码,我开始编写以下内容:
boost::graph_traits<WayPointGraph>::vertex_iterator vi, vi_end, next;
boost::tie(vi, vi_end) = vertices(graph);
for (next = vi; vi != vi_end; vi = next) {
//I need to create the good arcs ...
++next;
}
感谢您提前的支持。