I have a program that is supposed to allow the use of my computer with a xbox 360 remote. The direction of the joystick is in degrees, where directly up is 0 degrees, right is 90 degrees, down is 180 degrees, and left is 270 degrees. And of course there is everything between those values also. I'm a bit confused with the math of how to turn these angle measures into usable x and y coordinates for the mouse. I already know how to calculate the mouse speed using the joystick magnitude which is a double value of 0 to 1.
My question is how would I use the degree value of the joystick to move the cursor?
public void main()
{
//Wait for a controller to connect before program continues
xc = new XboxController();
while (!xc.isConnected())
{
System.out.println("Waiting for controller...");
xc = new XboxController();
}
System.out.println("Connected!");
try
{
//This robot will be used to change the mouse coordinates and perform clicks
robot = new Robot();
}
catch (Exception e)
{
e.printStackTrace();
}
//Get the screen dimensions
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
screenWidth = (int)screenSize.getWidth();
screenHeight = (int)screenSize.getHeight();
xc.addXboxControllerListener(new XboxControllerAdapter()
{
//Is called every time the leftThumbStick's direction is changed
//The direction value is in degrees
public void leftThumbDirection(double direction)
{
System.out.println("Left degree direction: "+(int)direction);
//Need to calculate the new coordinates of the mouse based on the joystick
}
});
}