Tyler Chatow | d28951f | 2019-02-16 20:12:28 -0800 | [diff] [blame^] | 1 | #include "y2019/joystick_angle.h" |
| 2 | |
| 3 | namespace y2019 { |
| 4 | namespace input { |
| 5 | namespace joysticks { |
| 6 | |
| 7 | JoystickAngle GetJoystickPosition(const JoystickAxis &x_axis, |
| 8 | const JoystickAxis &y_axis, |
| 9 | const Data &data) { |
| 10 | return GetJoystickPosition(data.GetAxis(x_axis), data.GetAxis(y_axis)); |
| 11 | } |
| 12 | |
| 13 | JoystickAngle GetJoystickPosition(float x_axis, float y_axis) { |
| 14 | if (x_axis > kJoystickRight) { |
| 15 | if (y_axis < kJoystickDown) { |
| 16 | return JoystickAngle::kUpperRight; |
| 17 | } else if (y_axis > kJoystickUp) { |
| 18 | return JoystickAngle::kLowerRight; |
| 19 | } else { |
| 20 | return JoystickAngle::kMiddleRight; |
| 21 | } |
| 22 | } else if (x_axis < kJoystickLeft) { |
| 23 | if (y_axis < kJoystickDown) { |
| 24 | return JoystickAngle::kUpperLeft; |
| 25 | } else if (y_axis > kJoystickUp) { |
| 26 | return JoystickAngle::kLowerLeft; |
| 27 | } else { |
| 28 | return JoystickAngle::kMiddleLeft; |
| 29 | } |
| 30 | } |
| 31 | return JoystickAngle::kDefault; |
| 32 | } |
| 33 | |
| 34 | } // namespace joysticks |
| 35 | } // namespace input |
| 36 | } // namespace y2019 |