Changeset 730d808 in galcon-client
- Timestamp:
- Jun 6, 2010, 2:02:24 AM (15 years ago)
- Branches:
- master
- Children:
- 647a312
- Parents:
- 4a1f590
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/com/example/helloandroid/Fleet.java
r4a1f590 r730d808 22 22 private boolean isClockwise; 23 23 24 private boolean done; 24 25 25 26 /* Optimising: pre-calculate paths */ 26 27 public Fleet(Planet source, Planet destination, int numShips, int faction) { 28 done = false; 29 27 30 source.setNumShips(source.getNumShips()-numShips); 28 31 … … 64 67 this.destination = destination; 65 68 this.isNextToAPlanet = false; 69 70 Log.d("Galcon", "Source: ("+source.getX()+", "+source.getY()+")"); 71 Log.d("Galcon", "Destination: ("+destination.getX()+", "+destination.getY()+")"); 72 Log.d("Galcon", "Initial direction: "+direction); 73 74 if(direction < 0) 75 direction += Math.PI*2; 66 76 } 67 77 … … 176 186 public void update(ArrayList<Planet> planets) { 177 187 int speed = 3; //pixels per move 178 double distance, tangent Direction, angle;188 double distance, tangentAngle, angle; 179 189 180 190 //is the ship going around a planet already … … 203 213 } 204 214 205 double radAngle = Math.atan(getSlope(nearPlanet.getX(), nearPlanet.getY(), dblX, dblY));215 //double radAngle = Math.atan(getSlope(destination.getX(), destination.getY(), dblX, dblY)); 206 216 //figure out which way to go clockwise or counter clockwise 207 tangentDirection = (Math.atan(getSlope(nearPlanet.getX(),nearPlanet.getY(),dblX,dblY))) + (Math.PI/2); 208 angle = Math.atan((Math.tan(tangentDirection) - Math.tan(direction))/(1 + Math.tan(tangentDirection)*Math.tan(direction))); 217 tangentAngle = (Math.atan(getSlope(nearPlanet.getX(),nearPlanet.getY(),dblX,dblY))) + (Math.PI/2); 218 angle = Math.atan((Math.tan(tangentAngle) - Math.tan(direction))/(1 + Math.tan(tangentAngle)*Math.tan(direction))); 219 220 Log.d("Galcon", "tangentAngle: "+tangentAngle); 221 Log.d("Galcon", "direction: "+direction+", angle: "+angle); 209 222 210 223 if (angle <= Math.PI/2) 211 224 angle = Math.PI - angle; 212 225 213 if(dblX < nearPlanet.getX()) 214 radAngle += Math.PI; 215 216 angle = radAngle + Math.PI/2; 217 218 double diff = direction-angle; 219 220 if(diff > 0) 226 //double diff = direction-angle; 227 228 //if(diff > 0) 229 if(Math.abs(tangentAngle-direction) > Math.PI/2) { 221 230 isClockwise = false; 222 else 231 direction = tangentAngle-Math.PI; 232 }else { 223 233 isClockwise = true; 224 225 if(Math.abs(diff)>Math.PI/2) 226 direction = angle-Math.PI; 227 else 228 direction = angle; 234 direction = tangentAngle; 235 } 236 237 Log.d("Galcon", "isClockwise: "+isClockwise); 229 238 230 239 xIntercept = dblY - (dblX*Math.tan(direction)); … … 241 250 //can you reach the center of the planet by following this direction 242 251 //if so set isNextToAPlanet to false and move 243 //otherwise continue moving along the circumference ds4252 //otherwise continue moving along the circumference 244 253 245 double dist = Math.abs(destination.getY() - ( direction*destination.getY()) - xIntercept)/(double)Math.sqrt(Math.pow(direction,2)+1);246 Log.i("Gencon", dist + " units");247 if(dist < 5 ){254 double dist = Math.abs(destination.getY() - (Math.tan(direction)*destination.getX()) - xIntercept)/(double)Math.sqrt(Math.pow(direction,2)+1); 255 //Log.d("Galcon", "dist: "+dist); 256 if(dist < 5 && dist == 1){ 248 257 dblY += (Math.sin(direction)*speed); 249 258 dblX += (Math.cos(direction)*speed); … … 257 266 } 258 267 } else { 259 angle = speed/(double)nearPlanet.radius; 260 Log.i("Gencon", angle + "%"); 268 angle = speed/(double)nearPlanet.radius*.1; 269 270 if(!done) { 271 Log.d("Galcon", "direction: "+direction+", angle: "+angle); 272 Log.d("Galcon", "original: ("+dblX+", "+dblY+")"); 273 } 274 261 275 if(isClockwise){ 262 dblX = ((Math.cos(direction + (Math.PI/2) - angle)*(nearPlanet.radius) + nearPlanet.getX()));263 dblY = ((Math.sin(direction + (Math.PI/2) - angle)*(nearPlanet.radius) + nearPlanet.getY()));264 direction = direction - (angle*.4);276 dblX = Math.cos(direction - (Math.PI/2) + angle)*nearPlanet.radius + nearPlanet.getX(); 277 dblY = Math.sin(direction - (Math.PI/2) + angle)*nearPlanet.radius + nearPlanet.getY(); 278 direction = direction + angle; 265 279 } else { 266 dblX = ((Math.cos(direction - (Math.PI/2) + angle)*(nearPlanet.radius) + nearPlanet.getX())); 267 dblY = ((Math.sin(direction - (Math.PI/2) + angle)*(nearPlanet.radius) + nearPlanet.getY())); 268 direction = direction + (angle*.4); 269 } 280 dblX = Math.cos(direction + (Math.PI/2) - angle)*nearPlanet.radius + nearPlanet.getX(); 281 dblY = Math.sin(direction + (Math.PI/2) - angle)*nearPlanet.radius + nearPlanet.getY(); 282 direction = direction - angle; 283 } 284 285 if(!done) 286 Log.d("Galcon", "new: ("+dblX+", "+dblY+")"); 287 288 done = true; 289 270 290 x = (int)dblX; 271 291 y = (int)dblY;
Note:
See TracChangeset
for help on using the changeset viewer.