Need suggestions on navigation map implementation

Started by
1 comment, last by Northernlight 13 years, 5 months ago
Hi
Not sure if this should go in the AI programming section but the question is not really an AI programming issue.

I'm implementing a map of graphnodes for A* navigation. The nodes and their edges are created by "flood filling" on a terrain. The nodes are then stored in a std::vector. The nodemap is dynamic which means that nodes can be removed and added during runtime.

The problem is this: When the user is clicking on the terrain I have to find out which node is the closest one to the point which was clicked.

I'm thinking that iterating through the entire vector, and then testing each node's distance to the clicked point, would be a very expensive operation. (Calculating distance between two 3D vectors and the comparing two floating point numbers). My first thought was to first check the X value of the nodes in the vector and then check the Y value of the nodes with the closest X value I find first. I'm still thinking that this is too expensive, and there must be a more elegant solution than that.

Have anyone else had this problem? Or do anyone have a suggestion?
Advertisement
Spatial partitioning.
Thanks for the tip :)
I'm currently working on implementing a KD-tree search as described in the link you posted.

This topic is closed to new replies.

Advertisement