Some joystick axes inverted?

bram wrote on Friday, August 09, 2013:


I love GLFW so far, keep up the good work!

I do have a problem with reading the joystick though.
I am testing with a PS3 controller.

I have found that the values returned by GLFW do not correspond to the actual values from the device. (I compared them with jstest values.)

Issues I found:
On left and right thumbsticks, GLFW returns positive values for moving the stick up.
The device though uses negative for up.

The right trigger value is inverted.
When released, the left trigger returns -1.
When released, the right trigger returns +1.
When pressed, the left trigger returns +1.
When pressed, the right trigger returns -1.
The raw device values do not exhibit this behavior:
both left and right triggers will return positive values when pressed.

Is this on purpose? If so with what rationale?


bram wrote on Friday, August 09, 2013:

Ugh… I found the offending code in x11_joystick.c
Uneven numbered axes are inverted.
That’s pretty ugly, if you ask me.
It also explains why the LEFT and RIGHT triggers behave differently.

It says it is according to GLFW spec, but you may want to change the spec.
It is impossible to implement the spec, since you have no knowledge about the axes.

It could be a thumbstick, but what if it is a brake pedal?
An accelerator?
A trigger?
There is no complete joystick database that will tell you how each axis functions on a device.

                // We need to change the sign for the Y axes, so that
                // positive = up/forward, according to the GLFW spec.
                if (e.number & 1)
                    _glfw.x11.joystick[i].axes[e.number] =

bram wrote on Wednesday, September 18, 2013:

BTW, the win32_joystick.c is even worse off:
This code assumes that the nr of axes are even, and will probably crash upon uneven axis count.

axes[(*count)++] = calcJoystickPos(ji.dwXpos, jc.wXmin, jc.wXmax);
axes[(*count)++] = -calcJoystickPos(ji.dwYpos, jc.wYmin, jc.wYmax);

And it also does the uneven axis inversion like x11 does.

elmindreda wrote on Friday, September 27, 2013:

I will address this in 3.0.4 or 3.1. Thank you for detailing it!