Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public double GetDist(Point p1,Point p2)
- {
- return Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2));
- }
- private void Form1_MouseMove(object sender, MouseEventArgs e)
- {
- double boatrot = 0; // just a test
- Point a = e.Location; // this is the 'player' in this case, the mouse pointer
- Point b = textboxcenter; // the center of the object eg boat, in this case a textbox
- Point c =
- new Point(
- (int)
- ((Math.Cos(boatrot)*(0)) - (Math.Sin(boatrot)*(20)) +
- textboxcenter.X),
- (int)
- ((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
- textboxcenter.Y));
- double A = GetDist(b, c); // just for ease of use
- double B = GetDist(c, a);
- double C = GetDist(a, b);
- double angle = Math.Acos((Math.Pow(A, 2) + Math.Pow(B, 2) - Math.Pow(C, 2))/(2*A*B));
- label1.Text = string.Format("Mouse ({0},{1}) Boat ({2},{3}) Angle ({4}) Dist ({5})", e.X, e.Y, textboxcenter.X, textboxcenter.Y, angle, C);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement