Changeset 647a312 in galcon-client


Ignore:
Timestamp:
Jun 6, 2010, 2:50:25 AM (14 years ago)
Author:
dportnoy <devnull@…>
Branches:
master
Children:
012e702, 04a9a00, 69f6f01
Parents:
730d808
Message:

Fleet pathing seems to be working correctly, even if the fleet needs to go through two intermediate planets. Fleet speed around planets probably still needs some tweaking.

File:
1 edited

Legend:

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

    r730d808 r647a312  
    2121        private boolean isNextToAPlanet;
    2222        private boolean isClockwise;
    23        
    24         private boolean done;   
    2523
    2624        /* Optimising: pre-calculate paths */
    2725        public Fleet(Planet source, Planet destination, int numShips, int faction) {
    28                 done = false;
    29                
    3026                source.setNumShips(source.getNumShips()-numShips);
    3127               
     
    213209                                }
    214210                               
    215                                 //double radAngle = Math.atan(getSlope(destination.getX(), destination.getY(), dblX, dblY));
    216                                 //figure out which way to go clockwise or counter clockwise
    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);
    222                                
    223                                 if (angle <= Math.PI/2)
    224                                         angle = Math.PI - angle;
    225                                
    226                                 //double diff = direction-angle;
    227                                
    228                                 //if(diff > 0)
     211                                tangentAngle = Math.atan(getSlope(nearPlanet.getX(),nearPlanet.getY(),dblX,dblY));
     212                               
     213                                if(dblX < nearPlanet.getX())
     214                                        tangentAngle += Math.PI;
     215                               
     216                                tangentAngle += Math.PI/2;
     217                               
    229218                                if(Math.abs(tangentAngle-direction) > Math.PI/2) {
    230219                                        isClockwise = false;
     
    240229                               
    241230                                isNextToAPlanet = true;
    242                                 //figure out which way to go clockwise or counter clockwise
    243                                 /*tangentDirection = (Math.atan(getSlope(temp.getX(),temp.getY(),dblX,dblY))) + (Math.PI/2);
    244                                 angle = Math.atan((Math.tan(tangentDirection) - Math.tan(direction))/(1 + Math.tan(tangentDirection)*Math.tan(direction)));
    245                                 if (angle <= Math.PI/2)
    246                                         angle = Math.PI - angle;*/
    247                                 //get next point and the direction and set it
    248231                        }
    249232                } else {
     
    253236                       
    254237                        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){
     238                        if(dist < 2){
    257239                                dblY += (Math.sin(direction)*speed);
    258240                                dblX += (Math.cos(direction)*speed);
     
    267249                        } else {
    268250                                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                                 }
    274251                               
    275252                                if(isClockwise){
     
    282259                                        direction = direction - angle;
    283260                                }
    284                                
    285                                 if(!done)
    286                                         Log.d("Galcon", "new: ("+dblX+", "+dblY+")");
    287                                
    288                                 done = true;
    289261                               
    290262                                x = (int)dblX;
Note: See TracChangeset for help on using the changeset viewer.