Skip to content

Commit 8039952

Browse files
fix gamepad trigger range issue
1 parent 7820f4a commit 8039952

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

code/io/joy-sdl.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,10 +975,22 @@ namespace joystick
975975
void Joystick::handleAxisEvent(const SDL_GamepadAxisEvent &evt)
976976
{
977977
auto axis = evt.axis;
978+
auto value = evt.value;
978979

979980
Assertion(axis < numAxes(), "SDL event contained invalid axis index!");
980981

981-
_axisValues[axis] = evt.value;
982+
// Triggers range from 0..32767 so we need to scale the value for FSO
983+
// since it expects a full -32768..32767 range. Note that precision is
984+
// lost in the scaling so only scale if not min/max trigger value
985+
if ((axis == SDL_GAMEPAD_AXIS_LEFT_TRIGGER) || (axis == SDL_GAMEPAD_AXIS_RIGHT_TRIGGER)) {
986+
if (value == 0) {
987+
value = -32768;
988+
} else if (value < 32767) {
989+
value = static_cast<decltype(value)>((value * 2) - 32768);
990+
}
991+
}
992+
993+
_axisValues[axis] = value;
982994
}
983995

984996
void Joystick::handleButtonEvent(const SDL_JoyButtonEvent &evt)

0 commit comments

Comments
 (0)