View Javadoc

1   /*
2    * Copyright (C) 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package cz.cuni.amis.pogamut.ut2004.agent.navigation.navmesh;
18  
19  import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  /**
24   * class used in algorithm A* in pathfinding in NavMesh
25   * @author Jakub
26   */
27  public class AStarNode {
28      private INavMeshAtom atom;
29      private AStarNode from;
30      private List<AStarNode> followers;
31      private double distanceFromStart;
32      private double estimatedDistanceToTarget;
33      private double estimatedTotalDistance;
34      
35      public AStarNode(AStarNode from, INavMeshAtom atom, NavMesh mesh, INavMeshAtom start, INavMeshAtom target) {
36          
37          this.from = from;
38          this.atom = atom;
39          followers = new ArrayList<AStarNode>();
40          
41          // count distance from start
42          if(from == null) {
43              distanceFromStart = 0;
44          }
45          else {
46              distanceFromStart = from.getDistanceFromStart() + mesh.getDistance(from.atom, atom);
47          }
48          
49          // count distance to end
50          estimatedDistanceToTarget = mesh.getDistance(atom, target);
51          
52          // count total distance
53          estimatedTotalDistance = distanceFromStart + estimatedDistanceToTarget;   
54      }
55      
56      public double getDistanceFromStart() {
57          return distanceFromStart;
58      }
59      public double getEstimatedDistanceToTarget() {
60          return estimatedDistanceToTarget;
61      }
62      public double getEstimatedTotalDistance() {
63          return estimatedTotalDistance;
64      }
65      public INavMeshAtom getAtom() {
66          return atom;
67      }
68      public AStarNode getFrom() {
69          return from;
70      } 
71      public List<AStarNode> getFollowers() {
72          return followers;
73      }
74  }