View Javadoc

1   package SteeringProperties;
2   
3   import SteeringStuff.SteeringType;
4   import XMLSteeringProperties.XMLPathFollowingProperties;
5   import cz.cuni.amis.pogamut.base.agent.navigation.IPathFuture;
6   import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
7   import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
8   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
9   
10  /**
11   * The steering properties of the Path Following Steering.
12   * @author Marki
13   */
14  public class PathFollowingProperties extends SteeringProperties {
15  
16      /**Steering properties: the magnitude of the repulsive force, to repulse agent from the side of the corridor.
17       * Reasonable values are 0 - 1000, the default value is 200.*/
18      private int repulsiveForce;
19  
20      /**The maximal distance from the axe of the path. Reasonable values are 200 - 2000.*/
21      private int distance;
22  
23      /**The list of ilocated elements - vertices of the path.*/
24      transient IPathFuture<ILocated> path;
25      
26      /** TargetLocation - if we want to compute path later, we can store here the targetLocation of the path.*/
27      private Location targetLocation;
28  
29      /** Regulating Force - helps the bot to keep the direction of the path. Recommended value is 50.*/
30      private double regulatingForce;
31  
32      /** The length of the projection - how much ahead we project our motion. Recommended values are 5-15.*/
33      private int projection;
34  
35      public PathFollowingProperties() {
36          super(SteeringType.PATH_FOLLOWING);
37          this.repulsiveForce = 200;
38          this.distance = 400;
39          this.targetLocation = new Location(9440,-9500,-3446.65);
40          this.path = null;
41          this.regulatingForce = 50;
42          this.projection = 5;
43      }
44  
45      public PathFollowingProperties(BehaviorType behaviorType) {
46          super(SteeringType.PATH_FOLLOWING, behaviorType);
47          this.repulsiveForce = 200;
48          this.distance = 400;
49          this.targetLocation = new Location(9440,-9500,-3446.65);
50          this.path = null;
51          this.regulatingForce = 50;
52          this.projection = 5;
53          setNewBehaviorType(behaviorType);
54      }
55      
56      public PathFollowingProperties(XMLPathFollowingProperties xml) {
57          super(SteeringType.PATH_FOLLOWING, xml.active, xml.weight, xml.behavior);
58          this.repulsiveForce = xml.repulsiveForce;
59          this.distance = xml.distance;
60          this.targetLocation = new Location(xml.xTargetLocation,xml.yTargetLocation,xml.zTargetLocation);
61          this.path = null;
62          this.regulatingForce = xml.regulatingForce;
63          this.projection = xml.projection;
64      }
65  
66  //    public PathFollowingProperties(IPathFuture<NavPoint> path) {
67  //        super(SteeringType.PATH_FOLLOWING);
68  //        this.repulsiveForce = 200;
69  //        this.distance = 400;
70  //        this.targetLocation = path.getPathTo().getLocation();
71  //        this.path = (IPathFuture) path;
72  //        this.regulatingForce = 50;
73  //        this.projection = 5;
74  //    }
75  
76      public PathFollowingProperties(IPathFuture<? extends ILocated> path) {
77          super(SteeringType.PATH_FOLLOWING);
78          this.repulsiveForce = 200;
79          this.distance = 400;
80          this.targetLocation = path.getPathTo().getLocation();
81          this.path = (IPathFuture) path;
82          this.regulatingForce = 50;
83          this.projection = 5;
84      }
85      
86      /**
87       * 
88       * @param repulsiveForce The magnitude of the repulsive force, to repulse agent from the side of the corridor. Reasonable values are 0 - 1000, the default value is 200.
89       * @param distanceFromThePath The maximal distance from the axe of the path. Reasonable values are 200 - 2000.
90       * @param path The list of ilocated elements - vertices of the path.
91       * @param targetLocation If we want to compute path later, we can store here the targetLocation of the path. This parameter isn't necessary.
92       * @param regulatingForce Helps the bot to keep the direction of the path. Recommended value is 50.
93       * @param projection The length of the projection - how much ahead we project our motion. Recommended values are 5-15.
94       */
95      public PathFollowingProperties(int repulsiveForce, int distanceFromThePath, IPathFuture<ILocated> path, Location targetLocation, double regulatingForce, int projection) {
96          super(SteeringType.PATH_FOLLOWING);
97          this.repulsiveForce = repulsiveForce;
98          this.distance = distanceFromThePath;
99          this.path = path;
100         this.targetLocation = targetLocation;
101         this.regulatingForce = regulatingForce;
102         this.projection = projection;
103     }
104 
105     protected void setNewBehaviorType(BehaviorType behaviorType) {
106         if (behaviorType.equals(BehaviorType.BASIC)) {
107             regulatingForce = 0;
108             projection = 5;
109         } else if (behaviorType.equals(BehaviorType.ADVANCED)) {
110             regulatingForce = 50;
111             projection = 5;
112         } 
113     }
114 
115 
116     public int getRepulsiveForce() {
117         return repulsiveForce;
118     }
119 
120     public void setRepulsiveForce(int orderOfTheForce) {
121         this.repulsiveForce = orderOfTheForce;
122     }
123 
124 
125     public int getDistanceFromThePath() {
126         return distance;
127     }
128 
129     public void setDistanceFromThePath(int distanceFromThePath) {
130         this.distance = distanceFromThePath;
131     }
132 
133     public IPathFuture<ILocated> getPath() {
134         return path;
135     }
136 
137     public void setPath(IPathFuture<ILocated> path) {
138         this.path = path;
139     }
140 
141     public Location getTargetLocation() {
142         return targetLocation;
143     }
144 
145     public void setTargetLocation(Location targetLocation) {
146         this.targetLocation = targetLocation;
147     }
148 
149     public double getRegulatingForce() {
150         return regulatingForce;
151     }
152 
153     public void setRegulatingForce(double regulatingForce) {
154         this.regulatingForce = regulatingForce;
155     }
156 
157     public int getProjection() {
158         return projection;
159     }
160 
161     public void setProjection(int projection) {
162         this.projection = projection;
163     }
164 
165     @Override
166     public String getSpecialText() {
167         String text = "";
168         text += "  * Repulsive Force: " + repulsiveForce + "\n";
169         text += "  * Target Location: " + targetLocation.toString() + "\n";
170         text += "  * Distance: " + distance + "\n";
171         text += "  * Regulation: " + regulatingForce + "\n";
172         text += "  * Projection: " + projection + "\n";
173         return text;
174     }
175 
176     @Override
177     public void setProperties(SteeringProperties newProperties) {
178         this.repulsiveForce = ((PathFollowingProperties)newProperties).getRepulsiveForce();
179         this.distance = ((PathFollowingProperties)newProperties).getDistanceFromThePath();
180         this.targetLocation = ((PathFollowingProperties)newProperties).getTargetLocation();
181         this.path = ((PathFollowingProperties)newProperties).getPath();
182         this.regulatingForce = ((PathFollowingProperties)newProperties).getRegulatingForce();
183         this.projection = ((PathFollowingProperties)newProperties).getProjection();
184     }
185 
186     public XMLPathFollowingProperties getXMLProperties() {
187         XMLPathFollowingProperties xmlProp = new XMLPathFollowingProperties();
188         xmlProp.repulsiveForce = repulsiveForce;
189         xmlProp.distance = distance;
190         xmlProp.xTargetLocation = (int) targetLocation.x;
191         xmlProp.yTargetLocation = (int) targetLocation.y;
192         xmlProp.zTargetLocation = (int) targetLocation.z;
193         xmlProp.regulatingForce = regulatingForce;
194         xmlProp.projection = projection;
195         xmlProp.active = active;
196         xmlProp.weight = weight;
197         xmlProp.behavior = behaviorType;
198         return xmlProp;
199     }
200 }