mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-27 10:57:22 +08:00
Use the correct orientation transformation based on whether the device is naturally landscape or portrait
This commit is contained in:
@@ -377,15 +377,27 @@ static void RecenterGamepad(SDL_Gamepad *gamepad)
|
|||||||
*/
|
*/
|
||||||
static void AdjustSensorOrientation(float *src, float *dst)
|
static void AdjustSensorOrientation(float *src, float *dst)
|
||||||
{
|
{
|
||||||
/* When a phone is rotated left and laid flat, the axes change
|
if (SDL_GetDisplayNaturalOrientation(SDL_GetPrimaryDisplay()) == SDL_ORIENTATION_LANDSCAPE) {
|
||||||
orientation as follows:
|
/* When a device in landscape orientation is laid flat, the axes change
|
||||||
-X to +X becomes +Z to -Z
|
orientation as follows:
|
||||||
-Y to +Y becomes +X to -X
|
-X to +X becomes -X to +X
|
||||||
-Z to +Z becomes -Y to +Y
|
-Y to +Y becomes +Z to -Z
|
||||||
*/
|
-Z to +Z becomes -Y to +Y
|
||||||
dst[0] = -src[1];
|
*/
|
||||||
dst[1] = src[2];
|
dst[0] = src[0];
|
||||||
dst[2] = -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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user