View Javadoc

1   /*
2    * Copyright (C) 2014 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.pathfollowing;
18  
19  import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
20  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPointNeighbourLink;
21  
22  /**
23   * Contains precomputed information about coming jump. If it is even jumpable, minimal and maximal take off point, landing target and navigation target of current link.
24   *
25   * @author Bogo
26   */
27  public class JumpBoundaries {
28  
29      private boolean jumpable;
30  
31      private Location takeOffMin;
32      private Location takeOffMax;
33      private Location takeoffEdgeDirection;
34  
35      private Location landingTarget;
36      
37      private Location navigTarget;
38  
39      private Location targetEdgeDirection;
40      private NavPointNeighbourLink link;
41  
42      /**
43       * Constructor for jumpable link.
44       * 
45       * @param link
46       * @param takeOffMin
47       * @param takeOffMax
48       * @param takeoffEdgeDirection
49       * @param target
50       * @param targetEdgeDirection
51       * @param navigTarget 
52       */
53      public JumpBoundaries(NavPointNeighbourLink link, Location takeOffMin, Location takeOffMax, Location takeoffEdgeDirection, Location target, Location targetEdgeDirection, Location navigTarget) {
54          this.link = link;
55          this.takeOffMin = takeOffMin;
56          this.takeOffMax = takeOffMax;
57          this.takeoffEdgeDirection = takeoffEdgeDirection;
58          this.landingTarget = target;
59          this.targetEdgeDirection = targetEdgeDirection;
60          this.navigTarget = navigTarget;
61          this.jumpable = true;
62      }
63  
64      /**
65       * Constructor for not jumpable link.
66       * 
67       * @param link 
68       */
69      public JumpBoundaries(NavPointNeighbourLink link) {
70          this.link = link;
71          this.jumpable = false;
72      }
73  
74      /**
75       * Get link this boundaries are for.
76       * @return 
77       */
78      public NavPointNeighbourLink getLink() {
79          return link;
80      }
81  
82      /**
83       * Get link this boundaries are for.
84       * @param link 
85       */
86      public void setLink(NavPointNeighbourLink link) {
87          this.link = link;
88      }
89  
90      /**
91       * If is jumpable.
92       * @return 
93       */
94      public boolean isJumpable() {
95          return jumpable;
96      }
97  
98      /**
99       * Set jumpable.
100      * @param jumpable 
101      */
102     public void setJumpable(boolean jumpable) {
103         this.jumpable = jumpable;
104     }
105 
106     /**
107      * Get earliest take off point.
108      * @return 
109      */
110     public Location getTakeOffMin() {
111         return takeOffMin;
112     }
113 
114     /**
115      * Set earliest take off point.
116      * @param takeOffMin 
117      */
118     public void setTakeOffMin(Location takeOffMin) {
119         this.takeOffMin = takeOffMin;
120     }
121 
122     /**
123      * Get latest take off point.
124      * @return 
125      */
126     public Location getTakeOffMax() {
127         return takeOffMax;
128     }
129 
130     /**
131      * Set latest take off point.
132      * @param takeOffMax 
133      */
134     public void setTakeOffMax(Location takeOffMax) {
135         this.takeOffMax = takeOffMax;
136     }
137 
138     /**
139      * Get landing target.
140      * @return 
141      */
142     public Location getLandingTarget() {
143         return landingTarget;
144     }
145 
146     /**
147      * Set landing target.
148      * @param landingTarget 
149      */
150     public void setLandingTarget(Location landingTarget) {
151         this.landingTarget = landingTarget;
152     }
153 
154     /**
155      * If the given location is between take off boundaries.
156      * 
157      * @param botLocation
158      * @return 
159      */
160     boolean isInBoundaries(Location botLocation) {
161         if (!jumpable) {
162             return false;
163         }
164 
165         if (takeOffMin.equals(takeOffMax, 1.0)) {
166             //We have only the point, we are out of NavMesh
167             return botLocation.getDistance(takeOffMin) < 20;
168         }
169 
170         //TODO: Improve || inform about passing max boundary
171         return botLocation.getDistance(takeOffMax) + botLocation.getDistance(takeOffMin) <= 2 * takeOffMin.getDistance(takeOffMax);
172     }
173 
174     /**
175      * If the given location is past take off boundaries.
176      * 
177      * @param botLocation
178      * @return 
179      */
180     boolean isPastBoundaries(Location botLocation) {
181         if (jumpable) {
182             return botLocation.getDistance(landingTarget) < takeOffMax.getDistance(landingTarget);
183         } else {
184             return false;
185         }
186     }
187 
188     /**
189      * If the jump is up and not fall.
190      * 
191      * @return 
192      */
193     public boolean isJumpUp() {
194         return jumpable && landingTarget.z - takeOffMax.z > 45;
195     }
196 
197     /**
198      * Get direction of the mesh edge the landing target lies on.
199      * 
200      * @return 
201      */
202     public Location getTargetEdgeDirection() {
203         return targetEdgeDirection;
204     }
205 
206     /**
207      * Get direction of the mesh edge the take off point lies on.
208      * 
209      * @return 
210      */
211     public Location getTakeoffEdgeDirection() {
212         return takeoffEdgeDirection;
213     }
214 
215     /**
216      * Get target of current link.
217      * 
218      * @return 
219      */
220     public Location getNavigTarget() {
221         return navigTarget;
222     }
223 
224     /**
225      * If the bot can land later than at landing target without problem detected by mesh.
226      * 
227      * @param distanceLater
228      * @return 
229      */
230     boolean canLandLater(double distanceLater) {
231         return landingTarget.getDistance2D(navigTarget) > distanceLater;
232     }
233 
234 }