some joystick axes inverted?

Using GLFW
Bram Stolk
2013-08-09
2013-09-27
  • Bram Stolk

    Bram Stolk - 2013-08-09

    Hi,

    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:
    (1)
    On left and right thumbsticks, GLFW returns positive values for moving the stick up.
    The device though uses negative for up.

    (2)
    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

     
  • Bram Stolk

    Bram Stolk - 2013-08-09

    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] =
                            -_glfw.x11.joystick[i].axes[e.number];
                    }
    
     
  • Bram Stolk

    Bram Stolk - 2013-09-18

    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.

     
  • Camilla Löwy

    Camilla Löwy - 2013-09-27

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

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks