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 cz.cuni.amis.pogamut.base3d.worldview.object.Location;
21  import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
22  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
23  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPointNeighbourLink;
24  import java.util.ArrayList;
25  import java.util.List;
26  import java.util.Map;
27  import math.geom3d.Point3D;
28  
29  /**
30   * CLass representing a navpoint which is a part of an off mesh connection in navMesh
31   * Contains mainly the real navpoint and then some more information , like polygon and connections to others
32   * @author Jakub Tomek
33   */
34  public class OffMeshPoint implements ILocated, INavMeshAtom, java.io.Serializable {
35      
36      private UnrealId navpointId = null;
37      private int pId = -1;
38      private ArrayList<OffMeshEdge> outgoingEdges = new ArrayList<OffMeshEdge>();
39      private ArrayList<OffMeshEdge> incomingEdges = new ArrayList<OffMeshEdge>();
40      private Location location;
41     
42      public OffMeshPoint(NavPoint navpoint, int pId) {
43          this.navpointId = navpoint.getId();
44          this.pId = pId;
45          this.location = navpoint.getLocation();
46      }
47  
48      public UnrealId getNavPointId() {
49          return navpointId;
50      }
51  
52      public int getPId() {
53          return pId;
54      } 
55  
56      public ArrayList<OffMeshEdge> getOutgoingEdges() {
57          return outgoingEdges;
58      } 
59  
60      public ArrayList<OffMeshEdge> getIncomingEdges() {
61          return incomingEdges;
62      }
63  
64      @Override
65      public Location getLocation() {
66          return location;
67      }
68  
69       /**
70       * Gets a list of all neighbors of this atom in navmesh. That includes both polygons and offmesh points.
71       * @param mesh
72       * @return 
73       */
74      @Override
75      public List<INavMeshAtom> getNeighbours(NavMesh mesh) {      
76          List<INavMeshAtom> neighbours = new ArrayList<INavMeshAtom>();
77          
78          //CHANGE: pId = 0 is valid polygon!!!
79          if(pId >= 0) neighbours.add(new NavMeshPolygon(pId));
80          
81          for(OffMeshEdge oe : outgoingEdges) {
82              neighbours.add(oe.getTo());
83          }
84          
85          return neighbours;
86      }
87      
88      /**
89       * Compares atoms if they are the same (same class, same polygon/point)
90       * @param atom
91       * @return 
92       */
93      @Override
94      public boolean equals(INavMeshAtom atom) {
95          if(atom.getClass() == OffMeshPoint.class) {
96              OffMeshPoint op = (OffMeshPoint) atom;
97              return (op.navpointId.getStringId().equals(this.navpointId.getStringId()));
98          }
99          else return false;
100     }
101     
102 }