Panda3D
Loading...
Searching...
No Matches
aiPathFinder.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file aiPathFinder.h
10 * @author Deepak, John, Navin
11 * @date 2009-11-10
12 */
13
14#ifndef _PATHFINDER_H
15#define _PATHFINDER_H
16
17#include "meshNode.h"
18#include "cmath.h"
19#include "lineSegs.h"
20
21typedef std::vector<Node *> NodeArray;
22typedef std::vector<NodeArray> NavMesh;
23
24Node* find_in_mesh(NavMesh nav_mesh, LVecBase3 pos, int grid_size);
25
26/**
27 * This class implements pathfinding using A* algorithm. It also uses a
28 * Binary Heap search to search the open list. The heuristics are calculated
29 * using the manhattan method.
30 */
31class EXPCL_PANDAAI PathFinder {
32public:
33 Node *_src_node;
34 Node *_dest_node;
35 std::vector<Node*> _open_list;
36 std::vector<Node*> _closed_list;
37
38 NavMesh _grid;
39
40 void identify_neighbors(Node *nd);
41 int calc_cost_frm_src(Node *nd);
42 int calc_heuristic(Node *nd);
43 void calc_node_score(Node *nd);
44 bool is_diagonal_node(Node *nd);
45
46 void add_to_olist(Node *nd);
47 void remove_from_olist();
48
49 void add_to_clist(Node *nd);
50 void remove_from_clist(int r, int c);
51
52 void generate_path();
53 void find_path(Node *src_node, Node *dest_node);
54 PathFinder(NavMesh nav_mesh);
55 ~PathFinder();
56};
57
58#endif
Node * find_in_mesh(NavMesh nav_mesh, LVecBase3 pos, int grid_size)
This function allows the user to pass a position and it returns the corresponding node on the navigat...
This class is used to assign the nodes on the mesh.
Definition meshNode.h:16
void remove_from_clist(int r, int c)
This function removes a node from the closed list.
bool is_diagonal_node(Node *nd)
This function checks if the traversal from a node is diagonal.
void add_to_clist(Node *nd)
This function adds a node to the closed list.
int calc_cost_frm_src(Node *nd)
This function calculates the cost of each node by finding out the number of node traversals required ...
void add_to_olist(Node *nd)
This function adds a node to the open list heap.
void generate_path()
This function performs the pathfinding process using the A* algorithm.
int calc_heuristic(Node *nd)
This function calculates the heuristic of the nodes using Manhattan method.
void identify_neighbors(Node *nd)
This function traverses through the 8 neigbors of the parent node and then adds the neighbors to the ...
void calc_node_score(Node *nd)
This function calculates the score of each node.
void remove_from_olist()
This function removes a node from the open list.
void find_path(Node *src_node, Node *dest_node)
This function initializes the pathfinding process by accepting the source and destination nodes.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.