Skip to content

Commit

Permalink
Merge pull request #660 from tophyr/pr/check-x-and-y-axes
Browse files Browse the repository at this point in the history
fill in x and y only if axes are valid
  • Loading branch information
Lgt2x authored Jan 1, 2025
2 parents d143d08 + 62ac1f4 commit 11f9322
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 5 additions & 5 deletions ddio/sdlcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,11 +901,11 @@ bool sdlgameController::enum_controllers() {
m_ControlList[num_devs].buttons = jc.num_btns;
m_ControlList[num_devs].btnmask = 0;
m_ControlList[num_devs].flags =
CTF_X_AXIS | CTF_Y_AXIS | ((jc.axes_mask & JOYFLAG_ZVALID) ? CTF_Z_AXIS : 0) |
((jc.axes_mask & JOYFLAG_RVALID) ? CTF_R_AXIS : 0) | ((jc.axes_mask & JOYFLAG_UVALID) ? CTF_U_AXIS : 0) |
((jc.axes_mask & JOYFLAG_VVALID) ? CTF_V_AXIS : 0) | ((jc.axes_mask & JOYFLAG_POVVALID) ? CTF_POV : 0) |
((jc.axes_mask & JOYFLAG_POV2VALID) ? CTF_POV2 : 0) | ((jc.axes_mask & JOYFLAG_POV3VALID) ? CTF_POV3 : 0) |
((jc.axes_mask & JOYFLAG_POV4VALID) ? CTF_POV4 : 0);
((jc.axes_mask & JOYFLAG_XVALID) ? CTF_X_AXIS : 0) | ((jc.axes_mask & JOYFLAG_YVALID) ? CTF_Y_AXIS : 0) |
((jc.axes_mask & JOYFLAG_ZVALID) ? CTF_Z_AXIS : 0) | ((jc.axes_mask & JOYFLAG_RVALID) ? CTF_R_AXIS : 0) |
((jc.axes_mask & JOYFLAG_UVALID) ? CTF_U_AXIS : 0) | ((jc.axes_mask & JOYFLAG_VVALID) ? CTF_V_AXIS : 0) |
((jc.axes_mask & JOYFLAG_POVVALID) ? CTF_POV : 0) | ((jc.axes_mask & JOYFLAG_POV2VALID) ? CTF_POV2 : 0) |
((jc.axes_mask & JOYFLAG_POV3VALID) ? CTF_POV3 : 0) | ((jc.axes_mask & JOYFLAG_POV4VALID) ? CTF_POV4 : 0);
m_ControlList[num_devs].normalizer[0] = (jc.maxx - jc.minx) / 2.0f;
m_ControlList[num_devs].normalizer[1] = (jc.maxy - jc.miny) / 2.0f;
m_ControlList[num_devs].normalizer[2] = (jc.maxz - jc.minz) / 2.0f;
Expand Down
8 changes: 6 additions & 2 deletions ddio/sdljoy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,12 @@ void joy_GetPos(tJoystick joy, tJoyPos *pos) {
uint32_t mask;

mask = Joysticks[joy].caps.axes_mask;
pos->x = SDL_JoystickGetAxis(stick, 0);
pos->y = SDL_JoystickGetAxis(stick, 1);
if (mask & JOYFLAG_XVALID) {
pos->x = SDL_JoystickGetAxis(stick, 0);
}
if (mask & JOYFLAG_YVALID) {
pos->y = SDL_JoystickGetAxis(stick, 1);
}
if (mask & JOYFLAG_ZVALID) {
pos->z = SDL_JoystickGetAxis(stick, 2);
}
Expand Down

0 comments on commit 11f9322

Please sign in to comment.