mirror of https://github.com/mgba-emu/mgba.git
SDL: Support exposing an axis directly as the gyro value (closes #2531)
This commit is contained in:
parent
85737f1103
commit
a0613e27ab
|
@ -341,6 +341,11 @@ void InputController::registerGyroAxisX(int axis) {
|
||||||
#ifdef BUILD_SDL
|
#ifdef BUILD_SDL
|
||||||
if (m_playerAttached) {
|
if (m_playerAttached) {
|
||||||
m_sdlPlayer.rotation.gyroX = axis;
|
m_sdlPlayer.rotation.gyroX = axis;
|
||||||
|
if (m_sdlPlayer.rotation.gyroY == axis) {
|
||||||
|
m_sdlPlayer.rotation.gyroZ = axis;
|
||||||
|
} else {
|
||||||
|
m_sdlPlayer.rotation.gyroZ = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -349,6 +354,11 @@ void InputController::registerGyroAxisY(int axis) {
|
||||||
#ifdef BUILD_SDL
|
#ifdef BUILD_SDL
|
||||||
if (m_playerAttached) {
|
if (m_playerAttached) {
|
||||||
m_sdlPlayer.rotation.gyroY = axis;
|
m_sdlPlayer.rotation.gyroY = axis;
|
||||||
|
if (m_sdlPlayer.rotation.gyroX == axis) {
|
||||||
|
m_sdlPlayer.rotation.gyroZ = axis;
|
||||||
|
} else {
|
||||||
|
m_sdlPlayer.rotation.gyroZ = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -284,10 +284,10 @@
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="minimum">
|
<property name="minimum">
|
||||||
<number>-2147483647</number>
|
<number>-1073741823</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="maximum">
|
<property name="maximum">
|
||||||
<number>2147483647</number>
|
<number>1073741823</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="value">
|
<property name="value">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
|
|
|
@ -199,6 +199,7 @@ bool mSDLAttachPlayer(struct mSDLEvents* events, struct mSDLPlayer* player) {
|
||||||
player->rotation.gyroSensitivity = 2.2e9f;
|
player->rotation.gyroSensitivity = 2.2e9f;
|
||||||
player->rotation.gyroX = 0;
|
player->rotation.gyroX = 0;
|
||||||
player->rotation.gyroY = 1;
|
player->rotation.gyroY = 1;
|
||||||
|
player->rotation.gyroZ = -1;
|
||||||
player->rotation.zDelta = 0;
|
player->rotation.zDelta = 0;
|
||||||
CircleBufferInit(&player->rotation.zHistory, sizeof(float) * GYRO_STEPS);
|
CircleBufferInit(&player->rotation.zHistory, sizeof(float) * GYRO_STEPS);
|
||||||
player->rotation.p = player;
|
player->rotation.p = player;
|
||||||
|
@ -327,6 +328,13 @@ void mSDLPlayerLoadConfig(struct mSDLPlayer* context, const struct Configuration
|
||||||
context->rotation.gyroY = axis;
|
context->rotation.gyroY = axis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
value = mInputGetCustomValue(config, "gba", SDL_BINDING_BUTTON, "gyroAxisZ", name);
|
||||||
|
if (value) {
|
||||||
|
axis = strtol(value, &end, 0);
|
||||||
|
if (axis >= 0 && axis < numAxes && end && !*end) {
|
||||||
|
context->rotation.gyroZ = axis;
|
||||||
|
}
|
||||||
|
}
|
||||||
value = mInputGetCustomValue(config, "gba", SDL_BINDING_BUTTON, "gyroSensitivity", name);
|
value = mInputGetCustomValue(config, "gba", SDL_BINDING_BUTTON, "gyroSensitivity", name);
|
||||||
if (value) {
|
if (value) {
|
||||||
float sensitivity = strtof_u(value, &end);
|
float sensitivity = strtof_u(value, &end);
|
||||||
|
@ -357,6 +365,8 @@ void mSDLPlayerSaveConfig(const struct mSDLPlayer* context, struct Configuration
|
||||||
mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "gyroAxisX", value, name);
|
mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "gyroAxisX", value, name);
|
||||||
snprintf(value, sizeof(value), "%i", context->rotation.gyroY);
|
snprintf(value, sizeof(value), "%i", context->rotation.gyroY);
|
||||||
mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "gyroAxisY", value, name);
|
mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "gyroAxisY", value, name);
|
||||||
|
snprintf(value, sizeof(value), "%i", context->rotation.gyroZ);
|
||||||
|
mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "gyroAxisZ", value, name);
|
||||||
snprintf(value, sizeof(value), "%g", context->rotation.gyroSensitivity);
|
snprintf(value, sizeof(value), "%g", context->rotation.gyroSensitivity);
|
||||||
mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "gyroSensitivity", value, name);
|
mInputSetCustomValue(config, "gba", SDL_BINDING_BUTTON, "gyroSensitivity", value, name);
|
||||||
}
|
}
|
||||||
|
@ -750,6 +760,10 @@ static void _mSDLRotationSample(struct mRotationSource* source) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if (rotation->gyroZ >= 0) {
|
||||||
|
rotation->zDelta = SDL_JoystickGetAxis(rotation->p->joystick->joystick, rotation->gyroZ) / 1.e5f;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int x = SDL_JoystickGetAxis(rotation->p->joystick->joystick, rotation->gyroX);
|
int x = SDL_JoystickGetAxis(rotation->p->joystick->joystick, rotation->gyroX);
|
||||||
int y = SDL_JoystickGetAxis(rotation->p->joystick->joystick, rotation->gyroY);
|
int y = SDL_JoystickGetAxis(rotation->p->joystick->joystick, rotation->gyroY);
|
||||||
|
|
|
@ -95,6 +95,7 @@ struct mSDLPlayer {
|
||||||
// Gyro
|
// Gyro
|
||||||
int gyroX;
|
int gyroX;
|
||||||
int gyroY;
|
int gyroY;
|
||||||
|
int gyroZ;
|
||||||
float gyroSensitivity;
|
float gyroSensitivity;
|
||||||
struct CircleBuffer zHistory;
|
struct CircleBuffer zHistory;
|
||||||
int oldX;
|
int oldX;
|
||||||
|
|
Loading…
Reference in New Issue