Panda3D

aiPathFinder.h

00001 ////////////////////////////////////////////////////////////////////////
00002 // Filename    : aiPathFinder.h
00003 // Created by  : Deepak, John, Navin
00004 // Date        :  10 Nov 09
00005 ////////////////////////////////////////////////////////////////////
00006 //
00007 // PANDA 3D SOFTWARE
00008 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00009 //
00010 // All use of this software is subject to the terms of the revised BSD
00011 // license.  You should have received a copy of this license along
00012 // with this source code in a file named "LICENSE."
00013 //
00014 ////////////////////////////////////////////////////////////////////
00015 
00016 #ifndef _PATHFINDER_H
00017 #define _PATHFINDER_H
00018 
00019 #include "meshNode.h"
00020 #include "cmath.h"
00021 #include "lineSegs.h"
00022 
00023 typedef vector<Node *> NodeArray;
00024 typedef vector<NodeArray> NavMesh;
00025 
00026 Node* find_in_mesh(NavMesh nav_mesh, LVecBase3f pos, int grid_size);
00027 
00028 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00029 //
00030 // Class : PathFinder
00031 //  Description : This class implements pathfinding using A* algorithm. It also uses a Binary Heap search to
00032 //               search the open list. The heuristics are calculated using the manhattan method.
00033 
00034 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
00035 
00036 class EXPCL_PANDAAI PathFinder {
00037 public:
00038   Node *_src_node;
00039   Node *_dest_node;
00040   vector<Node*> _open_list;
00041   vector<Node*> _closed_list;
00042 
00043   NavMesh _grid;
00044 
00045   void identify_neighbors(Node *nd);
00046   int calc_cost_frm_src(Node *nd);
00047   int calc_heuristic(Node *nd);
00048   void calc_node_score(Node *nd);
00049   bool is_diagonal_node(Node *nd);
00050 
00051   void add_to_olist(Node *nd);
00052   void remove_from_olist();
00053 
00054   void add_to_clist(Node *nd);
00055   void remove_from_clist(int r, int c);
00056 
00057   void generate_path();
00058   void find_path(Node *src_node, Node *dest_node);
00059   PathFinder(NavMesh nav_mesh);
00060   ~PathFinder();
00061 };
00062 
00063 #endif
00064 
 All Classes Functions Variables Enumerations