I've been reading the SDL tutorials and I was wondering how I would be able to handle multiple axis events, like if a controller had a left analog stick and a right analog stick, would the right analog stick's left/right (X/Y)
axis, be "event.jaxis.axis == 5"?.
Thanks:happy: .
SDL joystick handling with multiple sticks
Started by 3DModelerMan, Oct 19 2008 08:47 PM
7 replies to this topic
#1
Posted 19 October 2008 - 08:47 PM
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!
#2
Posted 19 October 2008 - 11:32 PM
You use SDL_JoystickNumAxes to get the number of axes available on the device, and then call SDL_JoystickGetAxis to get the position of the axis you want.
EDIT: It sounds like you are using SDL_JoyAxisEvent. In that case, the axis field does indeed contain the index of the axis in which motion was detected.
EDIT: It sounds like you are using SDL_JoyAxisEvent. In that case, the axis field does indeed contain the index of the axis in which motion was detected.
#3
Posted 20 October 2008 - 02:05 PM
Thanks, do you know how I would be able to detect if the button was pressed at the same time as the stick?, just do
" case SDL_JOYAXISMOTION && SDL_JOYBUTTONDOWN: "
right?.
" case SDL_JOYAXISMOTION && SDL_JOYBUTTONDOWN: "
right?.
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!
#4
Posted 20 October 2008 - 04:06 PM
I think you want a single & there, not a double &&.
reedbeta.com - developer blog, OpenGL demos, and other projects
#5
Posted 20 October 2008 - 05:41 PM
Oh, what's the difference?, is a single & C where a double and is C++?.
I use C++ so it should work fine. But if does'nt I'll try a single one.
Thanks:happy: .
I use C++ so it should work fine. But if does'nt I'll try a single one.
Thanks:happy: .
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!
#6
Posted 20 October 2008 - 05:55 PM
Actually, never mind what I said. The SDL_Event structure is a discriminated union, so you'll never get more than one event type at the same time. If you want to test that the user pushes the button and moves the stick in a certain time frame, you'll have to do it yourself.
(By the way, it has nothing to do with C vs C++. Single & is a bitwise op, double && is a logical op. In this case, I thought you were looking at a bitfield, so the bitwise op would be the appropriate one to use.)
(By the way, it has nothing to do with C vs C++. Single & is a bitwise op, double && is a logical op. In this case, I thought you were looking at a bitfield, so the bitwise op would be the appropriate one to use.)
reedbeta.com - developer blog, OpenGL demos, and other projects
#7
Posted 21 October 2008 - 12:06 AM
Oh, thanks for the help, I'll have a bool variable, that is set to true when a button is pressed and then reset, I'll also try something similar for the analog.
Lightspeed compilers are to slow...we need LUDICROUS SPEED!!!
#8
Posted 21 October 2008 - 02:19 PM
Right, you will have to track the state of the buttons as you receive button up/down events and then check the stored button state when you receive axis events. Alternatively, you can turn-off joystick events and poll the state of the joystick as needed.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












