Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1.         public double GetDist(Point p1,Point p2)
  2.         {
  3.             return Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2));
  4.         }
  5.  
  6.         private void Form1_MouseMove(object sender, MouseEventArgs e)
  7.         {
  8.             double boatrot = 0; // just a test
  9.  
  10.             Point a = e.Location; // this is the 'player' in this case, the mouse pointer
  11.             Point b = textboxcenter; // the center of the object eg boat, in this case a textbox
  12.             Point c =
  13.                 new Point(
  14.                     (int)
  15.                     ((Math.Cos(boatrot)*(0)) - (Math.Sin(boatrot)*(20)) +
  16.                      textboxcenter.X),
  17.                     (int)
  18.                     ((Math.Sin(boatrot) * (0)) + (Math.Cos(boatrot) * (20)) +  // all of this basically makes a third point that is 20 away from the boat, and oppasite the direction of said boat
  19.                      textboxcenter.Y));
  20.             double A = GetDist(b, c);  // just for ease of use
  21.             double B = GetDist(c, a);
  22.             double C = GetDist(a, b);
  23.  
  24.             double angle = Math.Acos((Math.Pow(A, 2) + Math.Pow(B, 2) - Math.Pow(C, 2))/(2*A*B));
  25.  
  26.             label1.Text = string.Format("Mouse ({0},{1}) Boat ({2},{3}) Angle ({4}) Dist ({5})", e.X, e.Y, textboxcenter.X, textboxcenter.Y, angle, C);
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement