Waypoint editing and path finding by astar

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Waypoint editing and path finding by astar

Post by smso »

Info
====

Features
--------
1. Simple editor for placing nodes/waypoints in the world and connection between nodes are done automatically by
- adjustable distance (MaxDistSQ)
- line-of-sight test

2. By marking nodes as reserved, player avoidance, co-ordinated movement of NPC (non-player character)'s, etc. can be stimulated.

3. Node path is smoothed by spline and movement of NPC can be paused, resumed and stopped.



About the classes
-----------------
Use of Model–View–Controller (MVC) pattern in c++ classes:

NaviNode => model
NaviNodeView => view
NaviNodeControl => controller

NaviNode is the data structure and it also interfaces with the astar algorithm.
NaviNodeView is responsible for drawing and uses Segment which represents the connection between nodes.

NpcPathControl makes use of results from astar search to move the NPC.



Gotchas when adding nodes
=========================
Occasionally, when you press 'A' to add a new node, it is not connected to other nodes inside the large pale blue circle.

Reason:
This is due to the slightly uneven ground which in turn causes the line-of-sight test to fail.

Remedy:
Deleted the node by pressing 'X'.
Then press 'Z' to add a new node with no line-of-sight test.




Sometimes connections which are blocked by the world mesh object are still formed on adding a new node.

Reason:
Due to the finite precision of float values (f32), line-of-sight test may yield UNEXPECTED positive result.
link:
http://irrlicht.sourceforge.net/forum/v ... 2&p=263477

Remedy:
Deleted the node by pressing 'X'.
Decrease MaxDistSQ by making the pale blue circle smaller and add the node again.


Acknowledgement
===============
Some codes are based on PathCreator by kazymjir:
http://irrlicht.sourceforge.net/forum/v ... hp?t=38645

CityDriving.irr scene file is ripped from CityDriving.zip of sio2:
http://irrlicht.sourceforge.net/forum/v ... hp?t=45781


Astar algoithm is written by Justin Heyes-Jones:
http://code.google.com/p/a-star-algorit ... mentation/
Most updated version of stlastar.h and fsa.h can be obtained from the above.

Thanks.
smso
Post Reply