Skip to content

Commit

Permalink
PFBA: fix analog stick angular zone sizes (22.5 degrees now)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsn8887 committed Aug 4, 2017
1 parent 7851a65 commit 54c072f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pfba/deps/libcross2d/src/sdl2/sdl2_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void SDL2Input::process_axis(Input::Player &player, int rotate) {
bool up = false, down = false, left = false, right = false;
Axis *currentStickXAxis = NULL;
Axis *currentStickYAxis = NULL;
float slope = 0.414214f; // tangent of 22.5 degrees for size of angular zones

for (int i = 0; i<=1; i++) {

Expand Down Expand Up @@ -163,27 +164,27 @@ void SDL2Input::process_axis(Input::Player &player, int rotate) {
analogY = -analogY;
if (analogY > 0 && analogX > 0) {
// upper right quadrant
if (2*analogY > analogX)
if (analogY > slope * analogX)
up = true;
if (2*analogX > analogY)
if (analogX > slope * analogY)
right = true;
} else if (analogY > 0 && analogX <= 0) {
// upper left quadrant
if (2*analogY > (-analogX))
if (analogY > slope * (-analogX))
up = true;
if (2*(-analogX) > analogY)
if ((-analogX) > slope * analogY)
left = true;
} else if (analogY <= 0 && analogX > 0) {
// lower right quadrant
if (2*(-analogY) > analogX)
if ((-analogY) > slope * analogX)
down = true;
if (2*analogX > (-analogY))
if (analogX > slope * (-analogY))
right = true;
} else if (analogY <= 0 && analogX <= 0) {
// lower left quadrant
if (2*(-analogY) > (-analogX))
if ((-analogY) > slope * (-analogX))
down = true;
if (2*(-analogX) > (-analogY))
if ((-analogX) > slope * (-analogY))
left = true;
}

Expand Down

0 comments on commit 54c072f

Please sign in to comment.