Hi,
I am not sure if this has been discussed before but I implemented the Dijkstra's algorithm trying to solve the Single-pair shortest-path problem in a 3D graph. I think that many people are looking for this because many issues in Game programming are related to this. So here we go:
First the link for the Blitz3D code:
http://www.moraldigames.com/Temp/Spa.zip
The interface is quite simple:
First you must create a graph using the following command:
mygraph = Graph_Create(0)
0 is the graph id (you can create many graphs using different id's)
Then you have to build the graph by adding vertices:
v1.Vertex = Graph_CreateVertex(mygraph, x1, y1, z1)
v2.Vertex = Graph_CreateVertex(mygraph, x2, y2, z2)
...
In order to create connections between vertices use:
Vertex_Connection(v1, v2)
...
After the construction of the graph simply call:
Graph_FindShortestPath(mygraph, src, dest)
where src and dest are existing vertices within mygraph
Each graph has the bestsearch vertex and after the previous call you can trace the shortest path following the predecessor member of the bestsearch vertex
The most interesting is that you can define your own 'cost' between two vertices by modifying the Vertex_GetCost() function in the way you like. Currently in the program the 'cost' between two vertices is their distance
If you are confused check the source.
If you build a graph and you find that the program does not calculate the shortest path please let me now in order to debug it.
Enjoy!
I am not sure if this has been discussed before but I implemented the Dijkstra's algorithm trying to solve the Single-pair shortest-path problem in a 3D graph. I think that many people are looking for this because many issues in Game programming are related to this. So here we go:
First the link for the Blitz3D code:
http://www.moraldigames.com/Temp/Spa.zip
The interface is quite simple:
First you must create a graph using the following command:
mygraph = Graph_Create(0)
0 is the graph id (you can create many graphs using different id's)
Then you have to build the graph by adding vertices:
v1.Vertex = Graph_CreateVertex(mygraph, x1, y1, z1)
v2.Vertex = Graph_CreateVertex(mygraph, x2, y2, z2)
...
In order to create connections between vertices use:
Vertex_Connection(v1, v2)
...
After the construction of the graph simply call:
Graph_FindShortestPath(mygraph, src, dest)
where src and dest are existing vertices within mygraph
Each graph has the bestsearch vertex and after the previous call you can trace the shortest path following the predecessor member of the bestsearch vertex
The most interesting is that you can define your own 'cost' between two vertices by modifying the Vertex_GetCost() function in the way you like. Currently in the program the 'cost' between two vertices is their distance
If you are confused check the source.
If you build a graph and you find that the program does not calculate the shortest path please let me now in order to debug it.
Enjoy!