Changeset 730d808 in galcon-client for src


Ignore:
Timestamp:
Jun 6, 2010, 2:02:24 AM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
647a312
Parents:
4a1f590
Message:

Currently debugging fleet pathing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/com/example/helloandroid/Fleet.java

    r4a1f590 r730d808  
    2222        private boolean isClockwise;
    2323       
     24        private boolean done;   
    2425
    2526        /* Optimising: pre-calculate paths */
    2627        public Fleet(Planet source, Planet destination, int numShips, int faction) {
     28                done = false;
     29               
    2730                source.setNumShips(source.getNumShips()-numShips);
    2831               
     
    6467                this.destination = destination;
    6568                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;
    6676        }
    6777
     
    176186        public void update(ArrayList<Planet> planets) {
    177187                int speed = 3; //pixels per move
    178                 double distance, tangentDirection, angle;
     188                double distance, tangentAngle, angle;
    179189               
    180190                //is the ship going around a planet already
     
    203213                                }
    204214                               
    205                                 double radAngle = Math.atan(getSlope(nearPlanet.getX(), nearPlanet.getY(), dblX, dblY));
     215                                //double radAngle = Math.atan(getSlope(destination.getX(), destination.getY(), dblX, dblY));
    206216                                //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);
    209222                               
    210223                                if (angle <= Math.PI/2)
    211224                                        angle = Math.PI - angle;
    212225                               
    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) {
    221230                                        isClockwise = false;
    222                                 else
     231                                        direction = tangentAngle-Math.PI;
     232                                }else {
    223233                                        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);
    229238                               
    230239                                xIntercept = dblY - (dblX*Math.tan(direction));
     
    241250                        //can you reach the center of the planet by following this direction
    242251                        //if so set isNextToAPlanet to false and move
    243                         //otherwise continue moving along the circumferenceds4
     252                        //otherwise continue moving along the circumference
    244253                       
    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){
    248257                                dblY += (Math.sin(direction)*speed);
    249258                                dblX += (Math.cos(direction)*speed);
     
    257266                                }
    258267                        } 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                               
    261275                                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;
    265279                                } 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                               
    270290                                x = (int)dblX;
    271291                                y = (int)dblY;
Note: See TracChangeset for help on using the changeset viewer.