Skip to content

Commit

Permalink
Use the correct orientation transformation based on whether the devic…
Browse files Browse the repository at this point in the history
…e is naturally landscape or portrait
  • Loading branch information
slouken committed Jun 17, 2023
1 parent e6d1ba2 commit 9eb5eab
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/joystick/SDL_gamepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,27 @@ static void RecenterGamepad(SDL_Gamepad *gamepad)
*/
static void AdjustSensorOrientation(float *src, float *dst)
{
/* When a phone is rotated left and laid flat, the axes change
orientation as follows:
-X to +X becomes +Z to -Z
-Y to +Y becomes +X to -X
-Z to +Z becomes -Y to +Y
*/
dst[0] = -src[1];
dst[1] = src[2];
dst[2] = -src[0];
if (SDL_GetDisplayNaturalOrientation(SDL_GetPrimaryDisplay()) == SDL_ORIENTATION_LANDSCAPE) {
/* When a device in landscape orientation is laid flat, the axes change
orientation as follows:
-X to +X becomes -X to +X
-Y to +Y becomes +Z to -Z
-Z to +Z becomes -Y to +Y
*/
dst[0] = src[0];
dst[1] = src[2];
dst[2] = -src[1];
} else {
/* When a device in portrait orientation is rotated left and laid flat,
the axes change orientation as follows:
-X to +X becomes +Z to -Z
-Y to +Y becomes +X to -X
-Z to +Z becomes -Y to +Y
*/
dst[0] = -src[1];
dst[1] = src[2];
dst[2] = -src[0];
}
}

/*
Expand Down

0 comments on commit 9eb5eab

Please sign in to comment.