Maps Pathfinding Nodes - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Maps Pathfinding Nodes (/thread-2574.html)
Maps Pathfinding Nodes - jigzat - Jun 15, 2008 03:08 PM
Hello, this is not necessarily for a game but I thought I could easily find an answer here. I want to develop a virtual map for my city, the choice is to use nodes in intersections with paths to north south east and west to represent single and double directions roads. But I have a big doubt, if the city didn't have tunnels and bridges and elevated roads it would be easier as it would be just a 2D grid but it has. How do I represent those elements?
Maps Pathfinding Nodes - AndyKorth - Jun 15, 2008 07:17 PM
You're on a good track for making nodes for intersections, but don't constrain yourself to 2D. When you create a graph (edges and nodes), you don't need to constrain yourself to a single dimension. Bridges and tunnels are just more edges in your graph.
I'm assuming you're planning to use the graph of your city for pathfinding, but on a second read, maybe that's not the case?
Maps Pathfinding Nodes - jigzat - Jun 15, 2008 08:52 PM
Yeah, I'm going to do that but actually is just an exercise. I'm not doing it for any commercial purpose but it could turn into something like that, who knows. Thanks for the answer, it clear my doubts.
Maps Pathfinding Nodes - _ibd_ - Jun 16, 2008 08:39 AM
When you want to do pathfinding, you'd probably go for an A-star algorithm (which is a dijkstra algorithm, basically). You can then represent bridges, tunnels, mountains or any other obstacles with weighted edges, which means your edges have a number, its weight, associated with them.
A star handles weighted edges (as long as this weight is > 0) well, so it makes no real difference or complication if you want to have bridges, etc., except that you need to store the weight in your edge struct/class.
Maps Pathfinding Nodes - jigzat - Jun 16, 2008 11:40 AM
What do you mean with weighted edges? Like the cost of using the edge?
Maps Pathfinding Nodes - Skorche - Jun 16, 2008 03:21 PM
In the case of a pathfinding map, the weight would be the distance you traveled.
Maps Pathfinding Nodes - jigzat - Jun 16, 2008 07:35 PM
I was thinking exactly that, but I thought it was called "cost" or something similar.
I was thinking about using some sort of array to store a pointer to each node/object so I can access them for special purposes without using the edges (like changing the cost/weight on the fly), is that a good idea or should I just leave them self-linked and access them through the edges?.
Maps Pathfinding Nodes - Duane - Jun 16, 2008 07:51 PM
Hmm, I created a nifty ray-casting technique that looked for edges of objects and then determined the best routeâ€”for 3d games, I found that this was the best approach; you're not constrained to grids.
Maps Pathfinding Nodes - _ibd_ - Jun 17, 2008 02:40 AM
jigzat: Not sure what you mean. Generally, you have a simple array of nodes. Every node then has a list of edges. These edges can have a cost/weight associated with them which you can change "on the fly" if you want so. You can access the edges via the nodes.
The cost would be higher for bridges, for example, because they can't be traversed as easy as an open field, for example.
Maps Pathfinding Nodes - AndyKorth - Jun 17, 2008 06:58 AM
I got the impression from the first post that each node you created had 4 links (one for each cardinal direction) connecting to adjacent nodes. That would explain why you'd have trouble with bridges. Like _ibd_ said, just maintain a list of edges for every node. You don't need to tie them to specific directions (like this node is connected to the north).
I think most people in this thread are assuming you're just creating a standard graph:
Maps Pathfinding Nodes - jigzat - Jun 17, 2008 02:58 PM
Yeah you are right, every node has 4 pointers that may or may not lead to a different node (depending of the street or avenue that represents, it doesn't necessarily means it is linked to a cardinal direction is just to represent double way roads) so I think I am basically doing a Graph. I talked about an array because in my university classes we worked with linked lists and we basically had a main pointer that pointed to a node which leads to NULL to the back and to other node to the front (if is not circular). We never stored the objects/nodes in any array, but I think it could be better if I store them on it and keep a directory of nodes.