COPY a near-optimal navigation grid generation algorithm and a navigation grid based routing algorithm _vector

Source: Internet
Author: User

Put forward the background:

In order to improve the speed of path finding and to provide the basic algorithm for the path-finding scheme in 3D environment, there is a frame-dropping phenomenon.

Current situation:

Because the 3D game is very high on the frame rate, and a long search in the game may take 8-10 frame time, in the complex map of the situation may even be more serious, and during this time, the rendering loop will pause rendering and wait for the results of the search. will give the player a not smooth operation experience.

In particular, 3D games in the map is more complex, large scale map, for a map of 600*600, the number of nodes in the search space is likely to reach hundreds of thousands of, which challenges the traditional A * seek algorithm, if the map is more complex, directly on these nodes directly to find the road time may be calculated in seconds.

Solution:

The method of solving the above problem can reduce the search space of the searching algorithm by generating the navigation grid. This is also the most common route finding solution in the 3D world.

There are two common ways to generate navigation grids, one of which is created by hand, which requires dedicated personnel to spend a certain amount of time creating them. The other is automatically generated by the program, but a little bit more complicated. This innovation adopts the method of automatically generating the navigation grid. The navigation grid can be automatically generated with our own Astarexplore tools without changing existing resources.

DK Online in the Maple forest area map For example, through the node 55,616, the following figure:

The picture above is a map of the 435*310, which is available through 55,616 nodes

The navigation grid automatically generated by our own tools (without manual creation) can be found in only 2,238 paths, and the Hertel-mehlhorn algorithm and 3-2merging algorithm are used to generate the algorithm.

The automatically generated navigation grid. Number of nodes is 2,238

The build results show that the nodes can be merged into 2,238 nodes from the original 55,616 nodes. Greatly reduces the search space when searching for roads, providing the possibility for faster and farther path searching.

The navigation grid in 3D space

A * Seek optimization:

1, Memory optimization:

In the search for a path, the time spent searching for paths is not the main loss, but rather the memory reset at the start of the route, or the constant allocation and release of memory. As the number of nodes is reduced, the array of nodes (which occupies only 100-200k memory) is established before the path is sought, and a one-dimensional array of bool is used to identify whether the nodes have been searched, and the bool array can only be reset after each search path is completed.

2, the use of two Fork heap optimization Open Table:

Using a two-fork heap allows the optimal node to remain at the top of the heap without consuming too much time on the order of the open table or traversing the open table to find the optimal node.

A short distance to find the road comparison:

The actual distance in the game is the distance from the figure A to B.

Results of navigation grid search result by mask search results

Mask search time-consuming navigation grid time consuming

Through the comparison: a short distance based on the original node of the search road, the search time of 1.615ms, traversing the number of nodes 284. and a navigation grid based on the search road, the traversal node is only 58, seek the road time only 0.0711 milliseconds.

One-time distance seek comparison:

The actual distance in the game is the distance from the figure A to B.

Actual seek time:

Results of navigation grid search result by mask search results

Through the comparison: a middle distance based on the original node search road, the search time is 69ms, traversing the number of nodes 8,393. and a navigation grid based on the search road, the traversal node is only 522, seek the road time only 0.38 milliseconds.

A long distance search comparison:

The actual distance in the game is the distance from the figure A to B, and a diagonal length is found.

Results of navigation grid search result by mask search results

Through the comparison: a long distance based on the original node search road, the search time is 468ms, traversing the number of nodes 46,636. Based on the navigation grid, the traversal node is only 2,198, and the path-seeking time is only 1.604 milliseconds.

Extended:

Because the algorithm of generating the navigation grid is completely based on 3D polygon, this algorithm can be applied to the scene slice, and the navigation grid based on the actual scene can be generated, thus the layered search is realized. The following figure.

Reference: Reference to "Ai Game programming Wisdom" in the "establishment of close to the best navigation grid" literature.

The Hertel-mehlhorn algorithm and the 3-2merging algorithm are used to establish the near-optimal navigation grid.

Hertel-mehlhorn algorithm

3-2merging algorithm

The algorithm still uses a * algorithm, but the search space becomes the navigation grid. The formula for the heuristic function has changed.

The G value = the distance between the midpoint of the edge and the middle of the piercing edge.

H value = The line distance between the midpoint of the polygon and the target point.

F value = g value + H value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.