Advertisement
StormWingDelta

Turret Aiming Java

Apr 19th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.71 KB | None | 0 0
  1. //This is what I have currently for aiming my turret, if anyone can help it shouldn't be hard to know how.
  2.  
  3.  
  4. import java.util.*;
  5. /**
  6.  * Write a description of class MathTesting here.
  7.  *
  8.  * @author (your name)
  9.  * @version (a version number or a date)
  10.  */
  11. public class MathTesting
  12. {
  13.     //
  14.     static Random rand2 = new Random();
  15.     public static void main(String[] args)
  16.     {
  17.         for(int RF = 0; RF < rand2.nextInt(1000); RF++)
  18.         {
  19.             System.out.println("Round: " + RF);
  20.             double TurretX = TrueRandDouble(10), TurretY = TrueRandDouble(10), FoeX = TrueRandDouble(10), FoeY = TrueRandDouble(1000);
  21.             double DistanceX = FoeX - TurretX;
  22.             double DistanceY = FoeY - TurretY;
  23.             double RadAngle = Math.atan2(DistanceY, DistanceX);
  24.             double PolarAngle = Math.toDegrees(Math.atan2(DistanceY, DistanceX));
  25.             double RealAngle = PolarAngle;
  26.             System.out.println("TX = " + TurretX + " TY = " + TurretY + " FX = " + FoeX + " FY = " + FoeY);
  27.             System.out.println("Distance X = " + DistanceX + " Distance Y = " + DistanceY);
  28.             System.out.println("Real Distance = " + Distance(TurretX,TurretY,FoeX,FoeY));
  29.             System.out.println("Math atan = " + Math.atan2(DistanceY, DistanceX));
  30.             System.out.println("PolarAngle = " + Math.toDegrees(Math.atan2(DistanceY, DistanceX)));
  31.        
  32.             if(PolarAngle < 0)
  33.             {
  34.                 RealAngle = PolarAngle + 360;
  35.             }
  36.             if(PolarAngle > 360)
  37.             {
  38.                 RealAngle = PolarAngle - 360;
  39.             }
  40.             if(PolarAngle < 360 && PolarAngle > 0)
  41.             {
  42.                 RealAngle = PolarAngle;
  43.             }
  44.        
  45.             System.out.println("RealAngle = " + RealAngle);
  46.             double FaceAngle = (double)rand2.nextInt(360);
  47.             if(FaceAngle != RealAngle)
  48.             {
  49.                 FaceAngle = RealAngle;
  50.                
  51.             }
  52.             System.out.println("FaceAngle = " + FaceAngle);
  53.             System.out.println();
  54.         }
  55.        
  56.        
  57.     }
  58.    
  59.     public static double Distance(double X1, double Y1, double X2, double Y2)
  60.     {
  61.         double D = Math.sqrt( Math.abs( (X2 - X1) * (X2 - X1) + (Y2 - Y1) * (Y2 - Y1) ) );
  62.         return D;
  63.     }
  64.    
  65.     public static int TrueRandDouble(int RandCap)
  66.     {
  67.         int RandN = rand2.nextInt(RandCap);
  68.         int TRD = 0;
  69.         int NorP = rand2.nextInt(2);
  70.         switch(NorP)
  71.         {
  72.             case 0:
  73.                 TRD = (RandN * -1);
  74.                 break;
  75.             case 1:
  76.                 TRD = (RandN * 1);
  77.                 break;
  78.         }
  79.         return TRD;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement