Hello, is it possible to get the mouse direction (Left, Right, Up, Down) based on mouse last position and current position? I have written the code to calculate the angle between two vectors but I am not sure if it is right.
Can someone please point me to the right direction?
public enum Direction
{
Left = 0,
Right = 1,
Down = 2,
Up = 3
}
private int lastX;
private int lastY;
private Direction direction;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
lastX = e.X;
lastY = e.Y;
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
double angle = GetAngleBetweenVectors(lastX, lastY, e.X, e.Y);
System.Diagnostics.Debug.WriteLine(angle.ToString());
//The angle returns a range of values from -value 0 +value
//How to get the direction from the angle?
//if (angle > ??)
// direction = Direction.Left;
}
private double GetAngleBetweenVectors(double Ax, double Ay, double Bx, double By)
{
double theta = Math.Atan2(Ay, Ax) - Math.Atan2(By, Bx);
return Math.Round(theta * 180 / Math.PI);
}