Math behind moving a gamepad hat button
I am wondering if taking the crossProduct(UP, RIGHT) * .5 will get me the up and right keypad movement I need for a gamepad? I need up/right up/left down/right down/left so is my math correct or do I need to do it another way?
thanks
prolly not
you prolly just want
up * sin(45) + right * cos(45)
-up * sin(45) + right * cos(45)
up * sin(45) + -right * cos(45)
-up * sin(45) + -right * cos(45)
The crosproduct will give you a vector "-at" in a standard (at, up, left) world. wich you could then rotate around using
the standard axis-angle rotation functions of your graphics api. (in 90deg incriments starting at 45deg)
you prolly just want
up * sin(45) + right * cos(45)
-up * sin(45) + right * cos(45)
up * sin(45) + -right * cos(45)
-up * sin(45) + -right * cos(45)
The crosproduct will give you a vector "-at" in a standard (at, up, left) world. wich you could then rotate around using
the standard axis-angle rotation functions of your graphics api. (in 90deg incriments starting at 45deg)
The cross product will give you a vector that points straight up out of the dpad (as in, towards your face). You'll want to do what KulSeran told you, and make the up-right, up-left, etc movements just linear combinations of the up and right directions.
RIGHT_UP = up * sin(45) + right * cos(45)
RIGHT_DOWN = -up * sin(45) + right * cos(45)
LEFT_UP = up * sin(45) + -right * cos(45)
LEFT_DOWN = -up * sin(45) + -right * cos(45)
Are those correct? guess I need a bit more clarification on it.
Thanks for the help.
RIGHT_DOWN = -up * sin(45) + right * cos(45)
LEFT_UP = up * sin(45) + -right * cos(45)
LEFT_DOWN = -up * sin(45) + -right * cos(45)
Are those correct? guess I need a bit more clarification on it.
Thanks for the help.
That looks perfectly correct. It's helpful to just think of the directions as vectors on a unit circle. You can think of any direction as:
UP * sin(theta) + RIGHT * cos(theta);
For example, just straight up would be the vector pointing directly up at an angle of 90 degrees, therefor the direction vector would be:
UP * sin(90) + RIGHT * cos(90) = UP * 1 + RIGHT * 0 = UP
As you can see, it just simplifies to UP, which you would expect.
UP * sin(theta) + RIGHT * cos(theta);
For example, just straight up would be the vector pointing directly up at an angle of 90 degrees, therefor the direction vector would be:
UP * sin(90) + RIGHT * cos(90) = UP * 1 + RIGHT * 0 = UP
As you can see, it just simplifies to UP, which you would expect.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement