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.Location;
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  /**
24   * Implementation of INavMeshAtom for polygons
25   * @author Jakub
26   */
27  public class NavMeshPolygon implements INavMeshAtom {
28     private int pId;
29     
30     NavMeshPolygon(int pId) {
31         this.pId = pId;
32     }
33     
34     public int getPolygonId() {
35         return pId;
36     }
37  
38      @Override
39      public List<INavMeshAtom> getNeighbours(NavMesh mesh) {
40         List<INavMeshAtom> neighbours = new ArrayList<INavMeshAtom>(); 
41         
42         // add all nearby polygons
43         List<Integer> pn = mesh.getNeighbourIdsToPolygon(pId);
44         for(Integer i : pn) {
45             neighbours.add(new NavMeshPolygon(i));
46         }
47         
48         // add all offmesh points on this polgon
49         List<OffMeshPoint> ops = mesh.getOffMeshPointsOnPolygon(pId);
50         for(OffMeshPoint op : ops) {
51             neighbours.add(op);
52         }
53         
54         return neighbours; 
55      }
56  
57      /**
58       * Compares ids of polygons and returns true if they are the same
59       * returns false if p is point
60       * @param p
61       * @return 
62       */
63      public boolean equals(INavMeshAtom atom) {
64          if(atom.getClass() == NavMeshPolygon.class) {
65              NavMeshPolygon p = (NavMeshPolygon) atom;
66              return (p.getPolygonId()==pId);
67          }
68          else return false;
69      }
70  }