| Summary: | Joystick Axis Issue Answer | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Lísias de Castro <saisilcastro> |
| Component: | joystick | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED INVALID | QA Contact: | Sam Lantinga <slouken> |
| Severity: | critical | ||
| Priority: | P2 | ||
| Version: | HG 2.1 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 10 | ||
I confirmed this is a bug in fact. I made an abstract machine that can change between allegro and sdl. The same code works and everything but in the joystick axis. The joystick button works, but when I try to use the arrows it does not responds up and down. The left, right responds, but it responds as up, down together. Can I do something else to help solving this? That lib is almost working perfectly. Only this little ditail to work fine. I figured out a way to make the joystick work. But I don't think it is the normal way;
The x axis is answering as 1,2,3, and the y axis is answering as 4;
so when I want to get the x status, I can check for one of the 3 numbers, and when I want to check the y axis I have to check the number 4. So I can get the joystick status.
case SDL_JOYAXISMOTION:
{
if (machine->sdl->event.jaxis.which == 0) {
switch (machine->sdl->event.jaxis.axis) {
case 0:
{
if (machine->sdl->event.jaxis.value < -8000) {
bit_on(&machine->joystick.arrow, JOY_LEFT);
} else if (machine->sdl->event.jaxis.value > 8000) {
bit_on(&machine->joystick.arrow, JOY_RIGHT);
} else {
bit_off(&machine->joystick.arrow, JOY_LEFT);
bit_off(&machine->joystick.arrow, JOY_RIGHT);
}
}
break;
case 4:
{
if (machine->sdl->event.jaxis.value < -8000) {
bit_on(&machine->joystick.arrow, JOY_UP);
} else if (machine->sdl->event.jaxis.value > 8000) {
bit_on(&machine->joystick.arrow, JOY_DOWN);
} else {
bit_off(&machine->joystick.arrow, JOY_UP);
bit_off(&machine->joystick.arrow, JOY_DOWN);
}
}
break;
}
}
}
break;
if you all don't fix it. At least can advert the people, in order for them to be able using their joysticks. I did what I could to aid. Now it is with you guys.
The joystick axis order isn't defined for any platform, and in fact, different APIs and different joysticks definitely return different ordering for different axes. You can see this by looking at the variety of mappings to the same controls that are in src/joystick/SDL_gamecontrollerdb.h. If you want a pre-defined control layout, I recommend using the API in SDL_gamecontroller.h, otherwise you'll be making non-portable hacks for each platform and joystick. |
I am trying to pass the axis value to my joystick variable. But instead of answer 0 to horizontal and 1 to vertical, the event.jaxis.axis returns 0,1,2 in a row, or 4 individually. From the event.jaxis.value I can get -255, 255, -32767, 32767. But as soon as the event.jaxis.axis does not respond correctly, I can't update my joystick value. Here is my code. case SDL_JOYAXISMOTION: { B32 i; for (i = 0; i < SDL_NumJoysticks(); i++) { if (to->machine->sdl2->event.jaxis.which == i) { if(to->machine->sdl2->event.jaxis.axis == 0){ if(to->machine->sdl2->event.jaxis.value == -1){ to->machine->joystick.left = On; } if(to->machine->sdl2->event.jaxis.value == 1){ to->machine->joystick.right = On; } if(to->machine->sdl2->event.jaxis.value == 0){ to->machine->joystick.left = Off; to->machine->joystick.right = Off; } printf("%hhu\n",to->machine->sdl2->event.jaxis.axis); } if(to->machine->sdl2->event.jaxis.axis == 1){ if(to->machine->sdl2->event.jaxis.value == -1){ to->machine->joystick.up = On; } if(to->machine->sdl2->event.jaxis.value == 1){ to->machine->joystick.down = On; } if(to->machine->sdl2->event.jaxis.value == 0){ to->machine->joystick.up = Off; to->machine->joystick.down = Off; } printf("%hhu\n",to->machine->sdl2->event.jaxis.axis); } //printf("X %hi Y %hi\n",SDL_JoystickGetAxis(to->machine->sdl2->joystick,0),SDL_JoystickGetAxis(to->machine->sdl2->joystick,1)); } } system("cls"); }