我正在開發一個項目SFML/C++,我需要生成一個圖形來連接它們之間的障礙物以方便尋路,所以我有興趣生成一個導航網格,我將應用boost A *算法。 有點像這樣: boost圖形庫astar和導航網格
但我有Boost圖庫實現此的許多問題(如果你心裏有一個庫,會更適合我的興趣)。首先,我創建具有相應結構的的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::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;
}
預先感謝您。
謝謝你的回答,我會嘗試poly2tri解決方案 – thegrandwaazoo